Operating system or device - Godot version:
Godot v2.1.2 Stable.
Issue description:
TL;DR version: Basically the following is spamming the debugger output. Although collisions are working fine.
File: area_2d.cpp , line: 165
ERR_FAIL_COND(!body_in && !E);
Detailed verison: my issue is that I am trying to implement a node that changes its children after a set of time (like toggle between two states every 5 seconds). When I do add_child to the node that contains Area2D, and at the same time, let's say the player was in the location where the object is about to toggle its state by adding child node, the error happens (using add_child). The Area2D has body_enter signal.
Have a look here in the forum's post about this issue. I was kind of happy when I thought the issue is fixed, when I changed the overlapping collision shapes of the node containing Area2D (the parent node has a KinematicBody2D too). But soon I realized the issue appears again when dealing with other nodes (like the one toggles its state) at the same location.
Things I tried,
call_deferred for adding or removing the node that contains the Area2D didn't work.remove_child) and connect again before add_childMy only option which I don't like to go there, is to make Area2D permanent and never removed or added (by putting it in a different parent), and switch or toggle states using code. That would be ugly.
Like I said, collisions are working fine, even when add_child for the Area2D (maybe the collisions are reported in the next frame, which I don't care as long as they are reported). Only the debugger output spamming. I wish to know if there is a cleaner approach.
Any suggestions!
Issues similar to this:
Issue #3589 (closed)
Link to minimal example project:
:
Try removing all the masks and layers first, as workaround, I remember that had to do that in one specific case where I was toggling the monitoring on Area2D.
@eon-s Interesting. Thanks for the tip. But that didn't work, but what worked is disabling monitoring before removing child, and enable monitoring after adding child. The issue seems to be gone, even with overlapping collision shapes of the area2d with sibling's (e.g, parent has a KinematicBody2D) collision shape.
Despite there is a workaround for this, it either must be mentioned in the documentation to do so when adding/removing child of type area2d in script, or fixed. As it is right now, it is unexpected behavior.
That is why I will leave this issue open, in a hope it gets fixed, or at least, when someone like me tries to find the same issue and doesn't look in closed issues (default is searching open issues in github, unless otherwise specified).
I had a similar problem (see #7507). I fixed it and made a pull request for the 3.0 branch (#7508), although it seems that the problem isn't there anymore in 3.0. However, I successfully use that fix in my current 2.1 build, no more debug messages like those. Feel free to try it if you want.
Edit: I actually modified that PR so the original fix isn't in there anymore. Look at https://github.com/lonesurvivor/godot/commit/86f1f91ad82f2a214d488aba69fe0fa4f8a8da80 if you want to (and ignore all the bad whitespace changes, used wrong editor settings back then...)
@lonesurvivor That is exactly what happened to me. I have experienced all these issues and error messages while trying different stuff to fix it. How did I miss your issue and your PR while searching the issue tracker, I don't know.
It seems you did what I did, just behind the scenes ;) that is, storing the state of monitoring, disable it before exiting scene tree and restore it upon re-entering the scene tree.
I hope your PR gets merged soon for the 2.1 branch. Although it is reassuring it is not needed for 3.0, but I am not sure if I will export my project to 3.0 when it gets released.
Edit: you should update your PR to reflect https://github.com/lonesurvivor/godot/commit/86f1f91ad82f2a214d488aba69fe0fa4f8a8da80 without the white noise ;) you said you updated it but it seems the changes are not yet synced or pushed somehow?
Ah, my apologies, I thought that this https://github.com/lonesurvivor/godot/commit/86f1f91ad82f2a214d488aba69fe0fa4f8a8da80 for some reason is the updated version. I take back what I said.
@lonesurvivor I didn't try your changes, but I tried to disconnect before remove_child and connect after add_child manually in script, that didn't help. So what made you remove the storing and restoring of monitoring state?
@RebelliousX
I removed that because it worked without it in 3.0. I left the rest of the PR (the disconnects) since I'm pretty sure it is wrong as it is now although it doesn't cause any error messages in 3.0 either.
I guess I should just make a new PR for the 2.1 branch tomorrow (after fixing the whitespaces). At the time I made this fix, I didn't think that 2.1 would still be a thing for such a long time, so I kept it for myself...
@lonesurvivor much obliged 馃憤 Thanks again.
No problem. Done.
@lonesurvivor Thanks again.
Most helpful comment
Try removing all the masks and layers first, as workaround, I remember that had to do that in one specific case where I was toggling the monitoring on Area2D.