Skip to content

Commit a9de999

Browse files
authored
fix: preventing exception from NetworkList, when modified before spawn. (#2169)
1 parent 91ee96d commit a9de999

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

  • com.unity.netcode.gameobjects/Runtime/NetworkVariable/Collections

com.unity.netcode.gameobjects/Runtime/NetworkVariable/Collections/NetworkList.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using Unity.Collections;
4+
using UnityEngine;
45

56
namespace Unity.Netcode
67
{
@@ -65,6 +66,13 @@ public override bool IsDirty()
6566

6667
internal void MarkNetworkObjectDirty()
6768
{
69+
if (m_NetworkBehaviour == null)
70+
{
71+
Debug.LogWarning($"NetworkList is written to, but doesn't know its NetworkBehaviour yet. " +
72+
"Are you modifying a NetworkList before the NetworkObject is spawned?");
73+
return;
74+
}
75+
6876
m_NetworkBehaviour.NetworkManager.MarkNetworkObjectDirty(m_NetworkBehaviour.NetworkObject);
6977
}
7078

0 commit comments

Comments
 (0)