How to set the position of a rigidbody2d using a signal

@wayfarer852 When I tried your suggestion an error appeared ‘Ball.gd:15 @_on_area_2D_entered(): Can’t change this state while flushing queries. Use call_deferred() or set_deferred() to change monitoring state instead.’

@wayfarer852 I did a typo I ment to say ‘Ball.gd:15 @ _on_area_2D_body_entered(): Can’t change this state while flushing queries. Use call_deferred() or set_deferred() to change monitoring state instead.‘

could you share the code where you put _on_area_2D_body_entered() ? if you don’t deactivate the monitoring of the Area2D or free it i don’t think you should get this error

I think I might of figured it out but I don’t think it should be using call_deferred() I looked it up and i think it uses a main thread in the cpu

func _on_area_2d_body_entered(_body: Node2D) -> void:
	call_deferred("set_freeze_enabled", true)
	call_deferred("set_global_position", Vector2(0,-150))

Honestly i don’t know much about best practices concerning call and set deferred, However if it’s for a small project I have used those functions many times and have never encountered an issue with it.

Does your game have the expected behavior now ?

Yes it works, thank you very much @wayfarer852 and @dragonforge-dev .

1 Like