com.unity.netcode.gameobjects icon indicating copy to clipboard operation
com.unity.netcode.gameobjects copied to clipboard

OnNetworkDespawn NetworkTickSystem null

Open LukeStampfli opened this issue 2 years ago • 1 comments

Description

When shutting down the NetworkManager, in OnNetworkDespawn NetworkManager.NetworkTickSystem is null which prevents from being able to unsubcribe from the network tick.

Reproduce Steps

  1. Add the following script to your player object:
public class Example: NetworkBehaviour
{
  public override void OnNetworkSpawn()
        {
            base.OnNetworkSpawn();
            NetworkManager.NetworkTickSystem.Tick += NetworkTick;
        }

        private void NetworkTick(){ }

        public override void OnNetworkDespawn()
        {
            NetworkManager.NetworkTickSystem.Tick -= NetworkTick;
            base.OnNetworkDespawn();
        }
}
  1. Enter playmode and start host using the button on the NetworkManager inspector.
  2. Press the stop host button on the NetworkManager exception
  3. See error

Actual Outcome

NullReferenceExceptions gets thrown:

NullReferenceException: Object reference not set to an instance of an object
Unity.Multiplayer.AbilitySystem.AbilityRunner.OnNetworkDespawn () (at C:/Users/Luke Stampfli/Documents/com.unity.multiplayer.abilitysystem/com.unity.multiplayer.abilitysystem/Runtime/AbilityRunner.cs:291)
Unity.Netcode.NetworkBehaviour.InternalOnNetworkDespawn () (at Library/PackageCache/com.unity.netcode.gameobjects@9807499f75/Runtime/Core/NetworkBehaviour.cs:445)
Unity.Netcode.NetworkObject.InvokeBehaviourNetworkDespawn () (at Library/PackageCache/com.unity.netcode.gameobjects@9807499f75/Runtime/Core/NetworkObject.cs:710)
Unity.Netcode.NetworkSpawnManager.OnDespawnObject (Unity.Netcode.NetworkObject networkObject, System.Boolean destroyGameObject)

Expected Outcome

NetworkBehaviours can unsubscribe from tick in OnNetworkDespawn.

Environment

  • OS: Windows
  • Unity Version: 2021.3.1f1
  • Netcode Version: 1.0.0-pre.9
  • Netcode Commit: [e.g. https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/commit/ba418fa5b600ad9eb61fab0575f12fbecc2c6520]

Additional Context

LukeStampfli avatar May 13 '22 14:05 LukeStampfli

Tracked in our backlog MTT-4086

ashwinimurt avatar Jul 12 '22 23:07 ashwinimurt

Was not able to reproduce following the provided repro steps. Tried some other possible repros as well and was not able to make this happen with the current SDK.

ShadauxCat avatar Sep 07 '22 17:09 ShadauxCat