0 votes

I don't understand this error

E 0:00:03:0381 Can't change this state while flushing queries. Use calldeferred() or setdeferred() to change monitoring state instead
servers/physics2d/physics2dserversw.cpp:416 @ areasetshapedisabled()
SpecialFX.gd:21 @ make
variableExplosion()
Bullet
BaseScript.gd:26 @ explode()
Bullet
BaseScript.gd:32 @ _onBulletkleinRotbodyentered()

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)
    queue_free()

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)

#warning-ignore:unused_argument
func _process(delta):
    Lebenszeit -= 1
    if Lebenszeit == 0:
        queue_free()

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?

asked Apr 10, 2019 in Engine by Pinandu (26 points)

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

Find this
https://github.com/godotengine/godot/issues/26452

Ich kann die Zeilennummern jetzt nicht direkt Deinen Scripts zuordnen aber in SpecialFX.gd 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():
    get_node("/root/Main/SpecialFX").call_deferred("make_variable_Explosion",\
        [(global_position - Vector2(960,540)), .1])
    queue_free()

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:
https://docs.godotengine.org/en/3.1/classes/class_object.html?highlight=object#class-object-method-init

-- 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.

Vielen Dank das wars.

Thanks a lot this fix the Error

getparent().getnode("SpielAblauf/Schlachtfeld").calldeferred("addchild", 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

1 Answer

0 votes

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, physicsprocess, 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.

answered Apr 11, 2019 by wombatstampede (3,153 points)
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.