All Questions

Community

Y
David Yushkov

Error with get_node("CollisionShape2D").disabled = true

body_set_shape_disabled: Can't change this state while flushing queries. Use call_deferred() or set_deferred() to change monitoring state instead. <C++ Error> Condition "body->get_space() && flushing_queries" is true. <C++ Source> servers/physics_2d/physics_2d_server_sw.cpp:730 @ body_set_shape_disabled() <Stack Trace> Enemy.gd:11 @ _on_StompDetector_body_entered()


  • Nathan Lovato replied

    You get an error but the game doesn't stop, right? Godot might be catching this error because you're using a more recent version of Godot. As the error message says, you can use call_deferred to let the engine disable the collision shape when it can. That method defers the call to the next time the object is idle (isn't being processed or modified):

    get_node("CollisionShape2D").call_deferred("set", "disabled", true)