I need to bee able to toggle it's physics, but my code just won't work. What it's supposed to do is change whether it's sleeping and remove or put back the collision layers.

#I've tried deferred and not, neither work.
#This function is a setter for the controlling variable, which is a bool.
func change_static(val):
	controlling = val
	print(controlling)
	if !val:
		set_deferred("collision_layer", 1)
		set_deferred("collision_mask", 1)
		set_deferred("sleeping", false)
	else:
		set_deferred("collision_layer", 0)
		set_deferred("collision_mask", 0)
		set_deferred("sleeping", true)

``` 

Did you try mode variable setted as kinematic? It should lock all object's physic behavior, but I read it in docs and made superficial test, maybe in real project it might not work.

In addition to what @TTaykAH said, you could also try setting the mode to static if you don't want it to move when other physics objects hit the RigidBody.

9 days later

I'm trying that, but it won't change it's value either. None of the properties of the RigidBody2D want to be changed.

How is it not being changed? Are you getting an error in the Godot console or is it just not acting as expected?

If you are getting an error in the console, you may want to try using set_deferred (I think that’s what it’s called) instead of directly setting it, as it may be that it’s in the middle of a physics check and so the property cannot be directly changed that instant. Using set_deferred should fix it though, as it will set the property after physics update.

a month later

Without set_deffered it yells at me, so I am using set_deffered, without any luck

(Also I literally forgot about godotforums for a while, sorry for late response!)

WAIT WAIT wait It is changing. It has been the whole time. The editor was being silly and not showing that it changed until I went to a different node and back.

REEE

deferred calling defers the call to a later frame update and the editor might not update at all unless something happens in the editor in response to user doing something...

a year later