Description
Hi,
If I spawn in an object (say a weapon in an FPS) and then attach it to a player object (via transform.SetParent
), when the scene changes the spawned object is detached from the player, which I don't expect to happen.
To work around this, I have to keep track of the parent of each object and then re-assign them whenever the scene switches. To make matters worse, MoveObjectsToDontDestroyOnLoad is called prior to OnSceneSwitchStarted, so I can't even use this event to store the parent, because it'll already have been detached at that point.
This behaviour is apparently intended and occurs in NetworkSceneManager.MoveObjectsToDontDestroyOnLoad
and NetworkSceneManager.MoveObjectsToScene
. This is presumably done because MoveGameObjectToScene
only works on root objects. But it's not what I would expect and also is not documented that I can see. What I'd've expected to happen is that the object's lifecycle is bound to its parent's, so if the parent was carried between scenes the child would be too; otherwise, it would be destroyed. I think this could be achieved by only calling MoveGameObjectToScene if the object has no parent. If it does have a parent, then I believe it should be carried along with the parent's MoveGameObjectToScene, or destroyed, depending on how the parent is configured.
Thanks,
Carl