Skip to content

Commit 014a09f

Browse files
committed
fix: avoid throwing exception when using NetworkList without a NetworkManager (Unity-Technologies#2539)
1 parent a7ab94f commit 014a09f

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

com.unity.netcode.gameobjects/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Additional documentation and release notes are available at [Multiplayer Documen
1212

1313
- Removed anoying warnings when using `NetworkList` in offline mode. (#2279)
1414
- Removed anoying warnings when using `NetworkVariable` in offline mode. (#2279)
15+
- Fixed usage of `NetworkList` throwing exception when used without a NetworkManager in scene. (#2539)
1516

1617
## [1.5.2] - 2023-07-24
1718

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

+6-6
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ public IEnumerator<T> GetEnumerator()
371371
public void Add(T item)
372372
{
373373
// check write permissions
374-
if (!CanClientWrite(m_NetworkBehaviour.NetworkManager.LocalClientId))
374+
if (m_NetworkBehaviour && !CanClientWrite(m_NetworkBehaviour.NetworkManager.LocalClientId))
375375
{
376376
throw new InvalidOperationException("Client is not allowed to write to this NetworkList");
377377
}
@@ -392,7 +392,7 @@ public void Add(T item)
392392
public void Clear()
393393
{
394394
// check write permissions
395-
if (!CanClientWrite(m_NetworkBehaviour.NetworkManager.LocalClientId))
395+
if (m_NetworkBehaviour && !CanClientWrite(m_NetworkBehaviour.NetworkManager.LocalClientId))
396396
{
397397
throw new InvalidOperationException("Client is not allowed to write to this NetworkList");
398398
}
@@ -418,7 +418,7 @@ public bool Contains(T item)
418418
public bool Remove(T item)
419419
{
420420
// check write permissions
421-
if (!CanClientWrite(m_NetworkBehaviour.NetworkManager.LocalClientId))
421+
if (m_NetworkBehaviour && !CanClientWrite(m_NetworkBehaviour.NetworkManager.LocalClientId))
422422
{
423423
throw new InvalidOperationException("Client is not allowed to write to this NetworkList");
424424
}
@@ -453,7 +453,7 @@ public int IndexOf(T item)
453453
public void Insert(int index, T item)
454454
{
455455
// check write permissions
456-
if (!CanClientWrite(m_NetworkBehaviour.NetworkManager.LocalClientId))
456+
if (m_NetworkBehaviour && !CanClientWrite(m_NetworkBehaviour.NetworkManager.LocalClientId))
457457
{
458458
throw new InvalidOperationException("Client is not allowed to write to this NetworkList");
459459
}
@@ -482,7 +482,7 @@ public void Insert(int index, T item)
482482
public void RemoveAt(int index)
483483
{
484484
// check write permissions
485-
if (!CanClientWrite(m_NetworkBehaviour.NetworkManager.LocalClientId))
485+
if (m_NetworkBehaviour && !CanClientWrite(m_NetworkBehaviour.NetworkManager.LocalClientId))
486486
{
487487
throw new InvalidOperationException("Client is not allowed to write to this NetworkList");
488488
}
@@ -507,7 +507,7 @@ public T this[int index]
507507
set
508508
{
509509
// check write permissions
510-
if (!CanClientWrite(m_NetworkBehaviour.NetworkManager.LocalClientId))
510+
if (m_NetworkBehaviour && !CanClientWrite(m_NetworkBehaviour.NetworkManager.LocalClientId))
511511
{
512512
throw new InvalidOperationException("Client is not allowed to write to this NetworkList");
513513
}

0 commit comments

Comments
 (0)