Description
Describe the bug
Any NetworkObjects living in a scene (or even DDOL) will get destroyed if during connection attempt, it fails or it gets cancelled.
To Reproduce
Steps to reproduce the behavior:
- Add a GameObject with a NetworkObject (Don't Destroy With Owner =
true
) component to a scene. - Setup a NetworkManager with UNet's transport.
- Start the scene in Play Mode.
- Start the NetworkManager as client, but don't let it connect to a server.
- Shut down the NetworkManager.
Actual outcome
The GameObject holding the NetworkObject is destroyed.
Expected outcome
The GameObject holding the NetworkObject should only be despawned and it should eventually be destroyed when the scene is unloaded, not before.
Environment (please complete the following information):
- OS: Windows 10
- Unity Version: 2020.3
- Netcode Version: 1.0.0-pre.5
Additional context
During the connection attempt, the NetworkManager is in the following state: IsClient = true
, IsConnectedClient = false
. Every NetworkObjects are not yet spawned (IsSpawned = false
).
Then, a NetworkManager Shutdown
is done (because the connection attempt is cancelled or timed out).
NetworkManager's ShutdownInternal
method is invoked, which then invokes NetworkSpawnManager's DespawnAndDestroyNetworkObjects
method which - since those in-scene NetworkObjects aren't spawned yet - fall into its else
case which Object.Destroy
them.