Error : Can't change this state while flushing queries. Godot 3.1

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

I don’t understand this error

E 0:00:03:0381 Can’t change this state while flushing queries. Use call_deferred() or set_deferred() to change monitoring state instead
servers/physics_2d/physics_2d_server_sw.cpp:416 @ area_set_shape_disabled() @ make_variable_Explosion() @ explode() @ _on_Bullet_klein_Rot_body_entered()

I have a Bullet Node, if this Node hits a Enemy it make a explosion

func explode():
	get_node("/root/Main/SpecialFX").make_variable_Explosion(global_position - Vector2(960,540), .1)

In my SpecialFX Node the Code looks like this:

extends Node
const Rummms = 17
const EXPLOSION = preload("res://Main/SpecialFX/Explos.tscn")

func make_variable_Explosion(pos, Radius):
	var explosion = EXPLOSION.instance()
	explosion.position = pos
	explosion.Radius = Radius # Scale wird dafür benutzt, Default ist 1
	get_parent().get_node("SpielAblauf/Schlachtfeld").add_child(explosion) # Die SpecialFX wird dem Object hinzugefügt
	get_node("/root/Main/AudioPlayer").playSound = Rummms

this is the Explos.tscn code

extends RigidBody2D

var Lebenszeit = 60
var Radius = 1 setget set_Radius # Startwert des Explosionsradius
func set_Radius(radius):
	Radius = radius
	self.scale = Vector2(radius, radius)

func _process(delta):
	Lebenszeit -= 1
	if Lebenszeit == 0:

The RigidBody2D has 2 Nodes, a Partikel2D for the Explosion and a Collision Shape that i don’t use at the moment.

It looks like everything’s okay. I see the explosions, the size is fine.
But in the debugger are depending on the time hundreds of errors.

My English is not so good that i understand the Error, any Tips for me?

Maybe it’s an error in the Linux Version of Godot.

Find this
"ERROR: body_set_shape_disabled" only showing on debug terminal, generic error on editor · Issue #26452 · godotengine/godot · GitHub

Pinandu | 2019-04-10 09:58

Ich kann die Zeilennummern jetzt nicht direkt Deinen Scripts zuordnen aber in Zeile 21 geschieht wohl etwas, dass besser mit call_deferred() ausgeführt werden sollte.

Du könntest mal probieren, die ganze Funktion mit call_deferred aufzurufen:

func explode():
        [(global_position - Vector2(960,540)), .1])

Oder eben nur den Aufruf in der bemängelten Zeile (welche auch immer das ist).
Die Doku zu call_deferred findet sich in der Referenz zu Object:
Object — Godot Engine (3.1) documentation in English

– English –
Try to use call_deferred to execute the function call in line 21 (whatever that is). Or try to call the entire function make_variable_Explosion as call_deferred.

wombatstampede | 2019-04-10 12:40

Vielen Dank das wars.

Thanks a lot this fix the Error

get_parent().get_node(“SpielAblauf/Schlachtfeld”).call_deferred(“add_child”, explosion)

Muss man denn seit 3.1 alle add_child so machen?

Is it a must to add_child in this way?

p.s. Ich habe mir ein altes spiel angesehen, da tauchen diese Fehler auch auf,
was bedeutet dieser Fehler?

bei dieser Zeile z.B.
get_node(“Collision”).disabled = true

Pinandu | 2019-04-10 16:16

:bust_in_silhouette: Reply From: wombatstampede

No, you don’t have always to use call_deferred() to add a child. This depends a bit of the context from where the method is called (Timer, _physics_process, notifications).

But I can’t tell exactly when it is required or not. Usually it’ll be required if you want to change something which is currently busy doing something. (I.e. disable a collision shape while collision handling is still processed)

Just be aware that ‘call_deferred()’ will be executed “later” out of the context of the current code. So if you’ve got some code some lines later requiring the changes of that call then you’d better move that also into the deferred code.