Question about object position changing in the scene tree after reading and crashes

I hadn’t noticed a serious issue until now, so I’d like to share my experience.

[Issue: Crashes when loading a save file]

Typically, the same player object is placed in different scenes (GameScene) to test operations across various scenarios.
If the player moves from Scene 1 to Scene 2, there are no issues during gameplay.
However, if you save and then load after reaching Scene 2, the game immediately freezes and crashes.

The cause is that the same player object exists in both scenes, leading to double instantiation during the load process, which results in a crash.
The solution seems simple enough? Just delete the player object from all scenes except Scene 1.

With this change, saving and loading while the player is in other scenes no longer causes crashes.

But here arises a major problem: if the player returns to Scene 1 from another scene, saves, and then loads,
it will crash again :clown_face: :joy:

The reason is the same as above. Since the player object exists in the node hierarchy of Scene 1, once the player leaves Scene 1, it is no longer the instantiated object within that scene. Therefore, when returning to Scene 1, the system generates an additional player object, causing a crash.

This is giving me a headache. I am creating a Metroidvania-style map where the player can freely move between multiple scenes. It would be terrible if returning to the initial Scene 1 and loading caused a crash. Is there any way to fix this?

================================================
[Issue: Position of scene tree objects when loading saves]

When a player object enters a new scene tree, where exactly in the scene tree hierarchy will the player’s node be located?


During testing, I found that when a player enters a new scene, it defaults to the very bottom of the scene tree. This makes intuitive sense. Nice!

At the same time, if you save and then load in the new scene, you’ll notice that the player’s position in the scene tree has changed↓

As shown in the image, after loading, the player (P1) automatically moves to the topmost position under the Parallax2D parent node in the scene tree. This causes objects with the same Z-sorting to appear in front of the player.

I don’t understand the reason behind this. I tried creating a new Parallax2D node, but the player only appears under this Parallax2D parent node. Under the current circumstances, is there a way to prevent P1 from jumping around in the scene node tree after loading?

I was able to replicate both and have reported them, thank you for the thorough explaination!

1 Like

Thank you for your report!

This is fundamentally an issue with the engine’s logic. I can’t think of a good workaround, so it would be great if the official team could optimize the underlying code!

When a player moves from Scene 1 to Scene 2 via a portal, the system actively cleans up and places the player object, even if a player node is already present in Scene 2’s node tree. This “ensure only one player exists in the scene” handling is performed automatically.

The crash during save loading occurs because it uses a “universal restoration” process: it loads the scene (with the default player node) and then creates objects based on the save file (resulting in another player object). The conflict between these two overlapping entities causes the crash.

Loading a save doesn’t have the same “ensure only one player exists in the scene” handling as the portal transition. If the underlying logic were similar to the portal mechanism, it would prevent the crash and make things easier for users :thinking:

There is also a similar scenario: if you design a teleportation feature that allows players to instantly travel between scenes, you typically place an object spawner in the scene, and clicking the teleport button generates the object at the specified location.

If the scene’s node tree already contains a player object, spawning a new player object via teleportation will result in the same issue…