HOW TO SOLVE: Can't change this state while flushing queries. Use call_deferred()...?

Godot Version

Question

Hello people! I hope you are doping great! I have this error and i don’t know how to fix it. This doen’t break my game for now, but i think is better to fix it. I’m new in GDScript :frowning:

Can’t change this state while flushing queries. Use call_deferred() or set_deferred() to change monitoring state instead.
<Error C++> Condition “body->get_space() && flushing_queries” is true.
<C++ Fuente> servers/physics_2d/godot_physics_server_2d.cpp:654 @ body_set_shape_disabled()
globales.gd:19 @ instanciar()
player.gd:114 @ _on_logic_hit_box_area_entered()

The calling code is this:

var player_death_now = PLAYER_DEATH.instantiate()
	player_death_now.position.x = position.x
	player_death_now.position.y = position.y
	Globales.instanciar(player_death_now)
	Globales.cameraShake(2,1)
	queue_free()

where instanciar is a variable in a autoloaded script that add a instantiated object in the very main scene tree.

This func is called before but this don’t throw any error until it gets into a func connected by signal : _on_logic_hit_box_area_entered(area)

Please help meeeee

not sure if this is the best solution but it worked for me on godot 4 when i had that error.
you make a const of the scene you want to load

const ROOM = “res://Room.tscn”

then you put this line in where you want to load the scene you put the const into the second brackets

get_tree().change_scene_to_file()
get_tree().change_scene_to_file(ROOM)

idk if it will work but hope it helps

i already fix it using get_tree().current_scene.call_deferred(“add_child”, newInstantiateObject)

TY anyway bro! Best for you

1 Like