fix floor switch error

This commit is contained in:
2026-01-11 12:27:31 +01:00
parent 37b0d61566
commit 07a7ed3bca

View File

@@ -89,6 +89,10 @@ func _on_body_entered(body):
func _on_body_exited(body): func _on_body_exited(body):
# Object left the switch # Object left the switch
# Check if node is still in scene tree (might be removed during level cleanup)
if not is_inside_tree():
return
if body in objects_on_switch: if body in objects_on_switch:
# For pillar switches, verify the object is still valid (not being held now) # For pillar switches, verify the object is still valid (not being held now)
if switch_type == "pillar": if switch_type == "pillar":
@@ -99,6 +103,7 @@ func _on_body_exited(body):
if object_type == "Pillar": if object_type == "Pillar":
var weight = _get_object_weight(body) var weight = _get_object_weight(body)
if weight > 0: if weight > 0:
if is_inside_tree() and $ReleaseSwitch:
$ReleaseSwitch.play() $ReleaseSwitch.play()
objects_on_switch.erase(body) objects_on_switch.erase(body)
current_weight -= weight current_weight -= weight
@@ -108,6 +113,7 @@ func _on_body_exited(body):
# Walk switch: Remove any object # Walk switch: Remove any object
var weight = _get_object_weight(body) var weight = _get_object_weight(body)
if weight > 0: if weight > 0:
if is_inside_tree() and $ReleaseSwitch:
$ReleaseSwitch.play() $ReleaseSwitch.play()
objects_on_switch.erase(body) objects_on_switch.erase(body)
current_weight -= weight current_weight -= weight