+3 votes

I am working in Godot 3.1 alpha 4, downloaded from here.

I have a breakable box which spawns a coin when the player attacks it.

The breakable box is an Area2D and the coin is a KinematicBody2D. When my player attacks, he generates an attack box which is also an Area2D. This attack box calls a destroy() method on the breakable box during emission of its on_area_entered signal. The destroy() method in turn calls a function from a singleton which spawns a coin.

func create_coin(pos, vec, speed):
    var projectile = coin_scene.instance()
    get_node("Level").add_child(projectile)
    projectile.init(pos, vec, speed)
    return projectile

Everything seems to work fine in-game, but I see the following errors generated whenever a coin is spawned.

enter image description here

The traces indicate that the problem is rooted in the create_coin() method.

These errors were not present in Godot 3.0.6, before I ported over to Godot 3.1 alpha 4.

What do these errors mean and how can I avoid them?


Here are some of the C Sources and Stack Traces, in case they help.

enter image description here
enter image description here
enter image description here

asked Dec 30, 2018 in Engine by Diet Estus (1,425 points)
edited Dec 30, 2018 by Diet Estus

1 Answer

+4 votes
Best answer

You're trying to call this function in a notification generated by flush_queries. It appears that flush_queries is finding all the overlaps and pushing out notifications based on those, but it's setting a variable flushing_queries to true while it's doing that. Any other function that adds, removes, enables or disables collision data is disabled via the FLUSH_QUERY_CHECK macro at the beginning of those functions.

The short of it is it appears you can't do that from a collision notification. It's advising you to use call_deferred which will defer the physics-modifying code that's causing the problem to the idle time.

answered Dec 31, 2018 by uzimonkey (68 points)
selected Dec 31, 2018 by Diet Estus

Thanks for the answer! You seem to be correct. You cannot add new Area2Ds to a scene during a call of another Area2Ds on_area_entered(). Using call_deferred() solves the problem. It's interesting that you don't get these errors in Godot 3.0.6.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.