Remove_node Gives a Strange Error on Specific Node Structure

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By uheartbeast
:warning: Old Version Published before Godot 3 was released.

Here is the structure of my scene:


If I call remove_node on the KinematicBody2D I get this error “ERROR: _body_inout: Condition ’ !body_in && !E ’ is true. At: scene/2d/area2d.cpp:165”

If I remove either of the collisions shapes I no longer get the error. Is there something wrong with having multiple collision shapes like this or is this a godot engine bug?


Where are you removing the node from?

Zylann | 2016-06-04 11:31

I have a singleton that removes the node inside of a process function when the left key is pressed.

uheartbeast | 2016-06-04 15:32

:bust_in_silhouette: Reply From: Warlaan

This is just a wild hunch, but maybe it helps:
I am assuming that the collision shape of the area2d overlaps with the collision shape of the kinematic body? If that is the case then that would mean that every frame the corresponding collision callback is called. Afaik the result of the physics calculations are synchronized in _fixed_process, so if you remove the KinematicBody2d in _process() the callback may be called on the area which then freaks out because the kinematic body is already gone.

If that is true then using any of these workarounds should help:

  • Try removing the kinematic body in _fixed_process().
  • Try moving the collisionshapes so they don’t overlap anymore.
  • Try changing the collision flags of the KinematicBody and the Area so the two don’t trigger each other’s callbacks.

As this is really just an educated guess I would like to hear some feedback whether it worked.

Thanks for the answer!

  • removing the kinematic body in the fixed process didn’t seem to change it.
  • Moving the shapes so they no longer overlap worked but I need them to overlap.
  • I really like the sound of this one. Do you mean the collision layer
    the body and area are on? I’m not sure I understand what you mean by
    “collision flags”.

Regardless, it seems you are really close. That must be a pretty well educated guess.

uheartbeast | 2016-06-04 17:31

Thanks :wink:
When you look at the inspector with a KinematicBody2D selected you see two entries called “Layers” and “Mask”. In order for two things to collide the mask of the one needs to match the layer of the other one. That system is a little counter-intuitive, but if you google for it there are quite a few results. Also at least in the latest development version there is a tooltip for the Layers-entry in the inspector that explains it quite well.

Warlaan | 2016-06-04 18:17

Just out of curiosity you might try using queue_free() instead of remove_node(). Of course that doesn’t do the same thing and probably it’s not what you need, but it might be helpful to know if the error still occurs.

Warlaan | 2016-06-04 18:21

It worked. Thanks so much!

uheartbeast | 2016-06-04 19:40

Also I tested it with queue_free() and there was no error. It is specific to remove_node(). But you are correct, I did need to use remove_node().

uheartbeast | 2016-06-04 19:43

Actually, your answer gave me the idea of using call_deferred. This fixes the issue and I don’t even have to worry about using the different collision layers and masks! Thanks again for all your help. You really helped me to understand the issue.

uheartbeast | 2016-06-04 21:22

:bust_in_silhouette: Reply From: jarlowrey

This solved it for me:

  1. Set a random position and use call_deferred as the other commenter says.
  2. Set monitoring and monitorable to false as this question says.
  3. Set monitoring/monitorable of all the nodes children as false too (if it has any CollisionObject2D children [Area2D, KinematicBody2D, etc])