Skip to content

Despawned non-scene NetworkObject gets destroyed on shutdown #1054

Closed
@simonpriest-fl

Description

@simonpriest-fl

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

  1. Load scene with NetworkSceneManager
  2. Start host
  3. Instantiate a network prefab
  4. Spawn the prefab
  5. Despawn the prefab
  6. 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):

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions