#Prevent on_area_exited() from triggering when enemy dies.

11 messages · Page 1 of 1 (latest)

silver lily
#

I have an issue where all areas belonging to a component called detection trigger when the parent enemy is queue_free.

The problem arises because i have an Area2D which teleports the entity back to the players position if its an ally. This procs when exiting the range area.
When i free the enemy, ALL areas of detection component trigger not just the teleport one. I've tried things like:
if enemy.is_queued_for_deletion() in the signal to no avail. All signals still proc, causing errors such as the dying ally teleporting to my location as if it exited the range and many more with the other on_area_exited signals.
How can i prevent all exit signals from triggering when i queue_free the enemy?

desert fulcrum
silver lily
#

I dont think so, when the entity despawns i kill it serting its health to 0, the the state machine plays the die state, upon finishing the die animation the queue_free() is called

#

I thought of a fix i could add tomorrow when i go back to it but i dont know if thats the best way to do it. Because so far i cannot get it to work the way i wanted

#

I could add a function that disables all detection when the die anim starts but that would mean add that to every entity i thought a simpler fix is possible

desert fulcrum
#

I gotta admit I don't really understand your setup. But definitely sounds like there should be a simpler fix

silver lily
#

I didnt even knew signals triggered when removing the area until now it sounds very prone to errors. All im doing is deleting the parent and the entire component and all its on_area_exited signals trigger as if the areas exit. I tried doing set_deffered("disabled", true , waiting a physics frame wont help either as the node is in the process of getting deleted and is_queued_for_deletion() returns false on the parent.

desert fulcrum
#

So the removed node has Area children and when you queue_free the parent all of those areas emit an area_exited signal?

#

Is the parent an area itself?

silver lily
#

Yes. No the parent is a Characterbody2D the detection component is a Node2D with 3 Area2D each with their exit and enter signals, they all trigger when i delete the character

desert fulcrum
#

One idea that comes to mind is using a custom function in the characterbody script to kill it, which deletes the areas before deleting itself