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,7 +103,8 @@ 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:
$ReleaseSwitch.play() if is_inside_tree() and $ReleaseSwitch:
$ReleaseSwitch.play()
objects_on_switch.erase(body) objects_on_switch.erase(body)
current_weight -= weight current_weight -= weight
print("FloorSwitch: Pillar left switch, weight: ", weight, ", total: ", current_weight) print("FloorSwitch: Pillar left switch, weight: ", weight, ", total: ", current_weight)
@@ -108,7 +113,8 @@ 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:
$ReleaseSwitch.play() if is_inside_tree() and $ReleaseSwitch:
$ReleaseSwitch.play()
objects_on_switch.erase(body) objects_on_switch.erase(body)
current_weight -= weight current_weight -= weight
_check_activation() _check_activation()