Is it safe to run physics related code in signal functions?

Godot Version

v4.3

Question

I’ve heard you shouldn’t run physics related code (like move_and_slide()) outside of _physics_process() (e.g. in _process()) because it’s unsafe and can mess up the physics simulation. I’m wondering if the same applies to running physics related functions/code in functions called by signals as they’re run independently of _physics_process() or does it depend on which signal it is. For example an Area3Ds body_entered which I assume would get called as the physics engine notices a body has entered the Area3D.

In short: is it safe to run physics functions inside of signal functions that are not physics dependent?

If you know for sure that the signal has been emitted in a physics frame and it’s not been deferred then, yes it’s safe. Otherwise try to avoid doing that.

Actually, I may be wrong. I was thinking calling methods like apply forces or impulses to rigid bodies. If you modify the state of the physics world (adding/removing bodies for example) it may probably fail.