Hmm, so its already parented to the node you are trying to change it to?
Thinking about it, maybe when it gets removed and added as a child of another node, it triggers the collision detection again? Either way, it’s strange that it thinks the new parent and the existing parent are the same. I would think they would be different.
As a test/thought, what happens if you do not remove the child from the scene but still add it as a child of a different node? I doubt it will change the child, but I’m curious if the node will still be in the scene or not. It should, since it wasn’t removed, but it may not hurt to double check to make sure the remove_child
is not causing the node to be removed.
As mentioned in this Q&A post, one thing you could try is to cache/save the nodes you want to reparent, and then in the next _process call, perform the reparenting. That may also you to skip using call_deferred
and may help fix the issue. The Q&A post also has code for reparenting nodes, but it looks basically like what you’ve already tried, so...
Another thing that may work, is instead of reparenting the node you duplicate it, parent it to the new parent, and destroy the original, as described briefly here. The only kicker is that duplicated nodes may not correctly carry script variables along with them, in which case you may need to use something like described in this post in addition to the duplication (I think. I haven’t tried runtime duplication in Godot).