Removing an Area2D from SceneTree (remove_child) emits the body_exited signal

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Hugh Bagan

Hello! I’m working on a topdown game that uses manual scene changing. The feature I’m currently trying to implement is moving a crate onto a button that opens a door. The button is in one scene (level), but the door is in a different scene. Basically, when a box is ontop of the button it triggers a body_entered signal and sets an autoload boolean to open the door. But the issue is that when I go to another level I remove the previous level from being a child of LevelManager, which triggers body_exited, and flips the boolean.

One possible avenue would be to only allow buttons to be pressed and not unpressed, but I want buttons to both be unpressed and be able to effect nodes in other scenes (via autoload variables for example).

Here is the commit. To reproduce this behaviour, move the box on the right onto the button. The door to the north will disappear, so walk into the diamond shape to go to the next room. Move the box in this room on to the button, then return to the previous room. Note how the first door is still gone, but when the second button was pressed the other door in the first room was not opened.

The concerning code is in,, and
Also if you know of a better way to do a key/door system, please let me know.
Thank you!