Fix spawn point getting cleared when switching scenes in editor #44
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "noahg/fix-spawn-point-getting-cleared-when-switching-scenes"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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_removedsignal 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_pointvariable tonullwhen the referenced node is deleted, the stale reference is serialized as_spawn_point = NodePath("")instead of removing the line to represent the unassigned /nullvalue. 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
_readyso the sanity checks still work.Unfortunately, if we do explicitly set the variable to
nullwhen 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.
a49fe4fbb2to921cd4022a921cd4022ato0136ffd0d4Rebased on dev
0136ffd0d4tof5e4e86262Rebased on dev
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.
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
@xury wrote in #44 (comment):
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.