- Edited
Hi!
I created 'bullet' objects and 'enemy' objects, and made the 'enemy' connect and signal to the 'bullet' on collision. The 'bullet' is freed on receiving the signal. I assumed this would shift detection duties away from the 'bullet'. It even works! About half the time... and sometimes it leads to a crash:
"invalid get index '...' (on base: 'previously freed' "
Now, since it works sometimes, I don´t know what goes wrong.
Here the offending code:
var connections = []
var collided
func _physics_process(delta):
collided = get_overlapping_areas()
for entity in collided:
if entity not in connections:
self.collision.connect(entity._on_collision)
connections.append(entity)
collision.emit()
_on_collision does nothing but dequeue. Both the 'bullets' and the 'enemies' get instanced in a main scene.
I thought I could clear the connections list from time to time. Is there a more elegant way to check for existing connections? Is my implementation just crap?
lemme know!