“$Collision.disabled = true” in the code doesn't work

Godot Version 4,3

I try to make “$Collision.disabled = true” in the code but it doesn’t work and collisions keep happening.

but it doesn’t work only in this code:

func _on_area_entered(area: Area2D) -> void:
	if area.has_method("fire"):
		$Collision.disabled = true
		print("$Collision.disabled ", $Collision.disabled)

The function “_on_area_entered” is executed, the print works and writes ($Collision.disabled true), but collisions keep happening.

if I write it like this, everything works:

func _ready() -> void:
	$Collision.disabled = true

You may have to defer modifying collision properties during collision checks.

func _on_area_entered(area: Area2D) -> void:
	if area.has_method("fire"):
		$Collision.set_deferred("disabled", true)
		# Still won't print true, have to wait till the end of frame
		#print("$Collision.disabled ", $Collision.disabled)
1 Like

Thank you! :3

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