Skip to content

Commit 6081b6e

Browse files
committed
fix: avoid throwing exception when using NetworkList without a NetworkManager (offline)
1 parent dfd08d8 commit 6081b6e

File tree

1 file changed

+6
-6
lines changed
  • com.unity.netcode.gameobjects/Runtime/NetworkVariable/Collections

1 file changed

+6
-6
lines changed

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

+6-6
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ public IEnumerator<T> GetEnumerator()
374374
public void Add(T item)
375375
{
376376
// check write permissions
377-
if (!CanClientWrite(m_NetworkBehaviour.NetworkManager.LocalClientId))
377+
if (m_NetworkBehaviour && !CanClientWrite(m_NetworkBehaviour.NetworkManager.LocalClientId))
378378
{
379379
throw new InvalidOperationException("Client is not allowed to write to this NetworkList");
380380
}
@@ -395,7 +395,7 @@ public void Add(T item)
395395
public void Clear()
396396
{
397397
// check write permissions
398-
if (!CanClientWrite(m_NetworkBehaviour.NetworkManager.LocalClientId))
398+
if (m_NetworkBehaviour && !CanClientWrite(m_NetworkBehaviour.NetworkManager.LocalClientId))
399399
{
400400
throw new InvalidOperationException("Client is not allowed to write to this NetworkList");
401401
}
@@ -421,7 +421,7 @@ public bool Contains(T item)
421421
public bool Remove(T item)
422422
{
423423
// check write permissions
424-
if (!CanClientWrite(m_NetworkBehaviour.NetworkManager.LocalClientId))
424+
if (m_NetworkBehaviour && !CanClientWrite(m_NetworkBehaviour.NetworkManager.LocalClientId))
425425
{
426426
throw new InvalidOperationException("Client is not allowed to write to this NetworkList");
427427
}
@@ -456,7 +456,7 @@ public int IndexOf(T item)
456456
public void Insert(int index, T item)
457457
{
458458
// check write permissions
459-
if (!CanClientWrite(m_NetworkBehaviour.NetworkManager.LocalClientId))
459+
if (m_NetworkBehaviour && !CanClientWrite(m_NetworkBehaviour.NetworkManager.LocalClientId))
460460
{
461461
throw new InvalidOperationException("Client is not allowed to write to this NetworkList");
462462
}
@@ -485,7 +485,7 @@ public void Insert(int index, T item)
485485
public void RemoveAt(int index)
486486
{
487487
// check write permissions
488-
if (!CanClientWrite(m_NetworkBehaviour.NetworkManager.LocalClientId))
488+
if (m_NetworkBehaviour && !CanClientWrite(m_NetworkBehaviour.NetworkManager.LocalClientId))
489489
{
490490
throw new InvalidOperationException("Client is not allowed to write to this NetworkList");
491491
}
@@ -508,7 +508,7 @@ public T this[int index]
508508
set
509509
{
510510
// check write permissions
511-
if (!CanClientWrite(m_NetworkBehaviour.NetworkManager.LocalClientId))
511+
if (m_NetworkBehaviour && !CanClientWrite(m_NetworkBehaviour.NetworkManager.LocalClientId))
512512
{
513513
throw new InvalidOperationException("Client is not allowed to write to this NetworkList");
514514
}

0 commit comments

Comments
 (0)