Skip to content

In-Scene NetworkObjects get destroyed if NetworkManager shuts down while not fully connected (e.g. failed connection attempt) #1670

Closed
@WhippetsAintDogs

Description

@WhippetsAintDogs

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:

  1. Add a GameObject with a NetworkObject (Don't Destroy With Owner = true) component to a scene.
  2. Setup a NetworkManager with UNet's transport.
  3. Start the scene in Play Mode.
  4. Start the NetworkManager as client, but don't let it connect to a server.
  5. 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.

Metadata

Metadata

Labels

priority:mediumThis issue has medium priority and may take some time to be resolvedtype:bugBug Report

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions