com.unity.netcode.gameobjects
com.unity.netcode.gameobjects copied to clipboard
OnNetworkDespawn NetworkTickSystem null
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
- 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();
}
}
- Enter playmode and start host using the button on the NetworkManager inspector.
- Press the stop host button on the NetworkManager exception
- 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
Tracked in our backlog MTT-4086
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.