Fix spawn point getting cleared when switching scenes in editor #44

Merged
noahg merged 4 commits from noahg/fix-spawn-point-getting-cleared-when-switching-scenes into dev 2026-04-04 17:35:05 +00:00
Member

This resolves a bug that was overlooked in #43.
The player spawner's spawn point variable was getting cleared whenever the scene was changed.
This is because the scene tree's node_removed signal is also emitted when switching scenes in the editor, not just when a node is deleted from the edited scene.

This fix eliminates needing to clear the spawn point variable for getting the configuration warnings by instead checking whether the spawn point node is inside the tree.
Now the spawn point is not cleared explicitly inside the script and leaves it to the editor.

This also includes a fix for the configuration warnings not being cleared and the property drawer not being updated when undoing deleting the referenced spawn point node.

The only remaining quirk I noticed is that by not explicitly setting the _spawn_point variable to null when the referenced node is deleted, the stale reference is serialized as _spawn_point = NodePath("") instead of removing the line to represent the unassigned / null value. When printing this value the output is <Object#null> instead of <null>.
This empty / stale reference value still evaluates to falsy and will still trigger a configuration warning and will fail the assert in _ready so the sanity checks still work.

Unfortunately, if we do explicitly set the variable to null when the referenced spawn point node is deleted, then the editor can no longer reassign the value when undoing deleting the node.
It is more useful to retain the reassign on undo deletion functionality than to make sure the value does not get serialized with the empty / stale reference value.

This resolves a bug that was overlooked in [#43](https://git.bugjam.dev/BUGJam/pounce-game/pulls/43). The player spawner's spawn point variable was getting cleared whenever the scene was changed. This is because the scene tree's `node_removed` signal is also emitted when switching scenes in the editor, not just when a node is deleted from the edited scene. This fix eliminates needing to clear the spawn point variable for getting the configuration warnings by instead checking whether the spawn point node is inside the tree. Now the spawn point is not cleared explicitly inside the script and leaves it to the editor. This also includes a fix for the configuration warnings not being cleared and the property drawer not being updated when undoing deleting the referenced spawn point node. The only remaining quirk I noticed is that by not explicitly setting the `_spawn_point` variable to `null` when the referenced node is deleted, the stale reference is serialized as `_spawn_point = NodePath("")` instead of removing the line to represent the unassigned / `null` value. When printing this value the output is `<Object#null>` instead of `<null>`. This empty / stale reference value still evaluates to falsy and will still trigger a configuration warning and will fail the assert in `_ready` so the sanity checks still work. Unfortunately, if we do explicitly set the variable to `null` when the referenced spawn point node is deleted, then the editor can no longer reassign the value when undoing deleting the node. It is more useful to retain the reassign on undo deletion functionality than to make sure the value does not get serialized with the empty / stale reference value.
noahg self-assigned this 2026-04-03 06:23:01 +00:00
Respond to the node's `tree_exited` signal instead of the scene tree's `node_exited` signal because it is only after that point that we can distinguish between the node being deleted from the editor and just being unloaded while switching scenes. The distinguishing difference is that the node's owner will be null if it was deleted from the scene in the editor.
This does not seem to be documented clearly anywhere so I had to resort to determining this by observation during trial and error.
noahg force-pushed noahg/fix-spawn-point-getting-cleared-when-switching-scenes from a49fe4fbb2 to 921cd4022a 2026-04-03 20:41:17 +00:00 Compare
noahg force-pushed noahg/fix-spawn-point-getting-cleared-when-switching-scenes from 921cd4022a to 0136ffd0d4 2026-04-04 00:58:45 +00:00 Compare
Author
Member

Rebased on dev

Rebased on dev
noahg force-pushed noahg/fix-spawn-point-getting-cleared-when-switching-scenes from 0136ffd0d4 to f5e4e86262 2026-04-04 15:46:04 +00:00 Compare
Author
Member

Rebased on dev

Rebased on dev
Owner

This behavior is way more stable now, thank you for fixing this up! There seems to only be two very minor remaining issues, but they probably aren't worth fixing since they only break under reasonable circumstances:

  • I have a PlayerSpawner in museum_2.tscn and a spawn point in a nested scene: room_foyer.tscn
    If re-parent the spawn point so that it is a child of a different node (still within room_foyer.tscn) this breaks the connection to the spawn point in museum_2.tscn.

  • Renaming the spawn point (in the same situation described above) breaks the connection.

All other behaviors seem to be resolved.

This behavior is way more stable now, thank you for fixing this up! There seems to only be two very minor remaining issues, but they probably aren't worth fixing since they only break under reasonable circumstances: * I have a PlayerSpawner in museum_2.tscn and a spawn point in a nested scene: room_foyer.tscn If re-parent the spawn point so that it is a child of a different node (still within room_foyer.tscn) this breaks the connection to the spawn point in museum_2.tscn. * Renaming the spawn point (in the same situation described above) breaks the connection. All other behaviors seem to be resolved.
xury approved these changes 2026-04-04 16:27:02 +00:00
xury left a comment
Owner

In my testing, this PR fixed the issues we were having.
The only remaining issues are very minor, and could be considered a different task anyway.
LGTM

In my testing, this PR fixed the issues we were having. The only remaining issues are very minor, and could be considered a different task anyway. LGTM
Author
Member

@xury wrote in #44 (comment):

This behavior is way more stable now, thank you for fixing this up! There seems to only be two very minor remaining issues, but they probably aren't worth fixing since they only break under reasonable circumstances:

* I have a PlayerSpawner in museum_2.tscn and a spawn point in a nested scene: room_foyer.tscn
  If re-parent the spawn point so that it is a child of a different node (still within room_foyer.tscn) this breaks the connection to the spawn point in museum_2.tscn.

* Renaming the spawn point (in the same situation described above) breaks the connection.

All other behaviors seem to be resolved.

Thanks for testing this out. I'm glad most of the issues are resolved now.
Good catch with the nested scene edge cases. They may simply be limitations of the editor.
Since the most important issues have been solved in this PR, I will go ahead and merge these changes so no one else has to fight with the spawn point being cleared like you had been experiencing.
Later I will look into the edge cases you identified to see if there is a way to make this even more robust.

@xury wrote in https://git.bugjam.dev/BUGJam/pounce-game/pulls/44#issuecomment-719: > This behavior is way more stable now, thank you for fixing this up! There seems to only be two very minor remaining issues, but they probably aren't worth fixing since they only break under reasonable circumstances: > > * I have a PlayerSpawner in museum_2.tscn and a spawn point in a nested scene: room_foyer.tscn > If re-parent the spawn point so that it is a child of a different node (still within room_foyer.tscn) this breaks the connection to the spawn point in museum_2.tscn. > > * Renaming the spawn point (in the same situation described above) breaks the connection. > > > All other behaviors seem to be resolved. Thanks for testing this out. I'm glad most of the issues are resolved now. Good catch with the nested scene edge cases. They may simply be limitations of the editor. Since the most important issues have been solved in this PR, I will go ahead and merge these changes so no one else has to fight with the spawn point being cleared like you had been experiencing. Later I will look into the edge cases you identified to see if there is a way to make this even more robust.
noahg deleted branch noahg/fix-spawn-point-getting-cleared-when-switching-scenes 2026-04-04 17:35:06 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
BUGJam/pounce-game!44
No description provided.