diff --git a/src/scripts/floor_switch.gd b/src/scripts/floor_switch.gd index 5391f3b..43a42ea 100644 --- a/src/scripts/floor_switch.gd +++ b/src/scripts/floor_switch.gd @@ -89,6 +89,10 @@ func _on_body_entered(body): func _on_body_exited(body): # 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: # For pillar switches, verify the object is still valid (not being held now) if switch_type == "pillar": @@ -99,7 +103,8 @@ func _on_body_exited(body): if object_type == "Pillar": var weight = _get_object_weight(body) if weight > 0: - $ReleaseSwitch.play() + if is_inside_tree() and $ReleaseSwitch: + $ReleaseSwitch.play() objects_on_switch.erase(body) current_weight -= 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 var weight = _get_object_weight(body) if weight > 0: - $ReleaseSwitch.play() + if is_inside_tree() and $ReleaseSwitch: + $ReleaseSwitch.play() objects_on_switch.erase(body) current_weight -= weight _check_activation()