When despawning a client owned object, the client attempts to send a NetworkVariableDeltaMessage when the NetworkObject is "null"
See original GitHub issueDescription
I have a situation where destroying a NetworkObject on the server causes the object to be deleted on the client while the clients NetworkBehaviourUpdater still tries to write its variables. This results in the following callstack being spammed repeatedly
MissingReferenceException: The object of type 'MyNetworkBehaviour' has been destroyed but you are still trying to access it. Your script should either check if it is null or you should not destroy the object. UnityEngine.Component.GetComponentInParent (System.Type t, System.Boolean includeInactive) (at <b5cd1660e28545eca6b51cc4a296a19e>:0) UnityEngine.Component.GetComponentInParent[T] () (at <b5cd1660e28545eca6b51cc4a296a19e>:0) Unity.Netcode.NetworkBehaviour.get_NetworkObject () (at Library/PackageCache/com.unity.netcode.gameobjects@aac7ffb9ef/Runtime/Core/NetworkBehaviour.cs:326) Unity.Netcode.NetworkBehaviour.NetworkVariableUpdate (System.UInt64 targetClientId, System.Int32 behaviourIndex) (at Library/PackageCache/com.unity.netcode.gameobjects@aac7ffb9ef/Runtime/Core/NetworkBehaviour.cs:626) Unity.Netcode.NetworkBehaviour.VariableUpdate (System.UInt64 targetClientId) (at Library/PackageCache/com.unity.netcode.gameobjects@aac7ffb9ef/Runtime/Core/NetworkBehaviour.cs:598) Unity.Netcode.NetworkBehaviourUpdater.NetworkBehaviourUpdate (Unity.Netcode.NetworkManager networkManager) (at Library/PackageCache/com.unity.netcode.gameobjects@aac7ffb9ef/Runtime/Core/NetworkBehaviourUpdater.cs:61) Unity.Netcode.NetworkManager.OnNetworkManagerTick () (at Library/PackageCache/com.unity.netcode.gameobjects@aac7ffb9ef/Runtime/Core/NetworkManager.cs:1604) Unity.Netcode.NetworkTickSystem.UpdateTick (System.Double localTimeSec, System.Double serverTimeSec) (at Library/PackageCache/com.unity.netcode.gameobjects@aac7ffb9ef/Runtime/Timing/NetworkTickSystem.cs:102) Unity.Netcode.NetworkManager.OnNetworkPreUpdate () (at Library/PackageCache/com.unity.netcode.gameobjects@aac7ffb9ef/Runtime/Core/NetworkManager.cs:1568) Unity.Netcode.NetworkManager.NetworkUpdate (Unity.Netcode.NetworkUpdateStage updateStage) (at Library/PackageCache/com.unity.netcode.gameobjects@aac7ffb9ef/Runtime/Core/NetworkManager.cs:1476) Unity.Netcode.NetworkUpdateLoop.RunNetworkUpdateStage (Unity.Netcode.NetworkUpdateStage updateStage) (at Library/PackageCache/com.unity.netcode.gameobjects@aac7ffb9ef/Runtime/Core/NetworkUpdateLoop.cs:185) Unity.Netcode.NetworkUpdateLoop+NetworkPreUpdate+<>c.<CreateLoopSystem>b__0_0 () (at Library/PackageCache/com.unity.netcode.gameobjects@aac7ffb9ef/Runtime/Core/NetworkUpdateLoop.cs:232)
Reproduce Steps
I attempted to create a test project but was unable to reproduce it outside of my project. I think it is to do with a client updating a network variable when the server destroys the NetworkObject
Actual Outcome
When the server despawns the NetworkObject, the client still tries to send changed NetworkVariableDeltaMessages even though the NetworkObject is null
Expected Outcome
If an object is Despawned, the client stops interacting with the NetworkObject.
Environment
- OS: Win 10
- Unity Version: 2022.2.0b4
- Netcode Version: latest
- Netcode Commit: [e.g. https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/commit/28109b4227a9a286682cb9c6f5852570d42e8642]
Additional Context
While trying to fix it myself, It seems that between NetworkBehaviourUpdater.AddForUpdate() and NetworkBehaviourUpdater.NetworkBehaviourUpdate() the NetworkObject becomes null
I have a “fix” in my branch which just makes sure to remove any null NetworkObject before running the update https://github.com/JayPeet/com.unity.netcode.gameobjects/commit/3c3b18a05882d36feabf199284eda3f7bf9b444b
Issue Analytics
- State:
- Created a year ago
- Comments:11 (7 by maintainers)
Top GitHub Comments
Merged! Thanks.
That seemed to fix it for me. Thank you! 😃