Setting collision mask value in physics process

Godot Version

v4.2.2.stable.official

Question

Hello,
I tried to set a specific collision mask value to false when a certain condition is met

func _physics_process(delta):
	handle_gravity(delta)
	move_and_slide()
	update_animation()
	death()
	evolution_check()
	if evolve_allowed == true and start_absorbed_anim == false:
		set_collision_mask_value(4, false)

I noticed that setting the collision mask value in the _ready() function works, but when I try to do it in _physics_process(delta) it doesn’t seem to work.

Does anyone have suggestions on how to properly disable a collision masks during the physics process?

Try deferring the function, I know a lot of physics calls do not like manipulation mid-process

set_collision_mask_value.call_deferred(4, false)
1 Like

Thanks for the response!
I found that using call_deferred() doesn’t solve the problem, but I learned that it’s a safer way for changing physics layers mid frame.

Apparently, changing the layer while disabling the previous layer and mask fixes the problem

if evolve_allowed == true and start_absorbed_anim == false:
		set_collision_layer_value.call_deferred(4, false)
		set_collision_mask_value.call_deferred(4, false)
		set_collision_layer_value.call_deferred(5, true)
1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.