I have an object that needs to follow various
Path2D paths in my scene. To do this, when it needs to follow a path, I re-parent it to a
PathFollow2D that will traverse the relevant path. The code to do this looks like this:
# Remove from the current parent first, otherwise we can't set new parent character.get_parent().remove_child(character) slide_follow.add_child(character) # ...set PathFollow2D in motion, etc...
Functionally, this works, and it's perfectly fine 90% of the time. However, because I have to remove the node from it's current/prior parent in order to add it, it briefly loses it's location and then comes back. Sometimes, this happens inside an
Area2D that has collision detection on for the character, which results in
body_entered signals firing
incorrectly unnecessarily, which can have adverse side effects.
I've tried temporarily disabling collision on the character to prevent this:
character.get_node("CollisionShape2D").disable = true print("#1 removing from old parent") character.get_parent().remove_child(character) print("#2 parentless node") slide_follow.add_child(character) print("#3 on to new parent") character.get_node("CollisionShape2D").disable = false
but the signals still fire:
#1 removing from old parent exit signal fired! #2 parentless node enter signal fired! #3 on to new parent
Is there a way to either keep the node in place or temporarily disable relevant collision so that the enter/exit signals don't fire during the reparenting process?