Describe the bug
When the host shuts down, any non-scene NetworkObjects that were previously spawned get destroyed. This happens even if they were despawned. I can't find an explicit statement about what's supposed to happen in this case in the docs, but my assumption was that despawned objects are not supposed to be affected.
This seems to happen because of the IsSceneObject flag. This flag is set when objects are spawned, but not unset when they're despawned. In DestroyNonSceneObjects, we destroy all NetworkObjects where the flag is false and not null. That means if a prefab NetworkObject is instantiated but never spawned, it won't be destroyed. If it's instantiated, spawned, then despawned, its IsSceneObject flag will still be false after despawning, so it'll be destroyed.
It seems like IsSceneObject should perhaps be reset to null at the same time we reset IsSpawned to false in OnDestroyObject.
To Reproduce
- Load scene with NetworkSceneManager
- Start host
- Instantiate a network prefab
- Spawn the prefab
- Despawn the prefab
- Stop the host
Actual outcome
The instance of the prefab will be destroyed
Expected outcome
The instance of the prefab should remain in the scene as a despawned NetworkObject, and can be spawned again if the host is started later
Environment (please complete the following information):
Describe the bug
When the host shuts down, any non-scene NetworkObjects that were previously spawned get destroyed. This happens even if they were despawned. I can't find an explicit statement about what's supposed to happen in this case in the docs, but my assumption was that despawned objects are not supposed to be affected.
This seems to happen because of the
IsSceneObjectflag. This flag is set when objects are spawned, but not unset when they're despawned. InDestroyNonSceneObjects, we destroy all NetworkObjects where the flag isfalseand not null. That means if a prefab NetworkObject is instantiated but never spawned, it won't be destroyed. If it's instantiated, spawned, then despawned, itsIsSceneObjectflag will still befalseafter despawning, so it'll be destroyed.It seems like
IsSceneObjectshould perhaps be reset tonullat the same time we resetIsSpawnedtofalseinOnDestroyObject.To Reproduce
Actual outcome
The instance of the prefab will be destroyed
Expected outcome
The instance of the prefab should remain in the scene as a despawned NetworkObject, and can be spawned again if the host is started later
Environment (please complete the following information):