Open TheCaveOfWonders opened 10 months ago
Hi @TheCaveOfWonders Please download and install com.unity.netcode.gameobjects@1.10.0 and test to see if the issue is resolved on your end.
If you continue to experience any problems, please report back to this ticket so we can investigate further.
Thank you for your patience and cooperation!
I'm having the same error as well. I updated from 1.8.1 to 1.10.0 as @fluong6 suggested but it still gave me the same error:
NullReferenceException: Object reference not set to an instance of an object
Unity.Netcode.NetworkVariable`1[T].set_Value (T value) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.10.0/Runtime/NetworkVariable/NetworkVariable.cs:94)
Cargo+<Countdown>d__13.MoveNext () (at Assets/Resources/Gamemodes/FreeForAll/Cargo/Cargo.cs:46)
UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at <228a75ed9d5b4a658c89f48527e7e2e0>:0)
@TheCaveOfWonders & @Conundroy
This issue pertains to writing to a NetworkVariable when the NetworkObject is no longer spawned and most likely being destroyed. Under both conditions, writing to a NetworkVariable during that time will result in that information not being synchronized nor persisted.
With that said, I am pretty sure the updates in v1.11.0 should resolve this issue.
Not knowing the exact conditions of the scene being unloaded and what else might be getting destroyed, if you still get this exception (@Conundroy specifically at that line number) then it is very likely that the NetworkBehaviour
component is in the middle of being destroyed. The best solution, under that scenario would be to check if the NetworkBehaviour.IsSpawned
is still true before setting the value.
If we happen to write to a network variable at the same time as we're leaving the scene, we get a null ref exception GameObjects (including networked ones) are being destroyed as we're leaving the scene.
Reproduce Steps
Actual Outcome
A null ref exception is thrown.
Expected Outcome
No error is thrown.
Environment