Skip to content

fix: avoid throwing exception when using NetworkList without a NetworkManager (#2539) #2540

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions com.unity.netcode.gameobjects/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Additional documentation and release notes are available at [Multiplayer Documen
- Fixed issue where `NetworkAnimator` would log an error if there was no destination transition information. (#3384)
- Fixed initial `NetworkTransform` spawn, ensure it uses world space. (#3361)
- Fixed issue where `AnticipatedNetworkVariable` previous value returned by `AnticipatedNetworkVariable.OnAuthoritativeValueChanged` is updated correctly on the non-authoritative side. (#3322)
- Fixed usage of `NetworkList` throwing exception when used without a NetworkManager in scene. (#2539)

### Changed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ public IEnumerator<T> GetEnumerator()
public void Add(T item)
{
// check write permissions
if (!CanClientWrite(m_NetworkBehaviour.NetworkManager.LocalClientId))
if (m_NetworkBehaviour && !CanClientWrite(m_NetworkBehaviour.NetworkManager.LocalClientId))
{
LogWritePermissionError();
return;
Expand All @@ -452,7 +452,7 @@ public void Add(T item)
public void Clear()
{
// check write permissions
if (!CanClientWrite(m_NetworkBehaviour.NetworkManager.LocalClientId))
if (m_NetworkBehaviour && !CanClientWrite(m_NetworkBehaviour.NetworkManager.LocalClientId))
{
LogWritePermissionError();
return;
Expand Down Expand Up @@ -490,7 +490,7 @@ public bool Contains(T item)
public bool Remove(T item)
{
// check write permissions
if (!CanClientWrite(m_NetworkBehaviour.NetworkManager.LocalClientId))
if (m_NetworkBehaviour && !CanClientWrite(m_NetworkBehaviour.NetworkManager.LocalClientId))
{
LogWritePermissionError();
return false;
Expand Down Expand Up @@ -539,7 +539,7 @@ public int IndexOf(T item)
public void Insert(int index, T item)
{
// check write permissions
if (!CanClientWrite(m_NetworkBehaviour.NetworkManager.LocalClientId))
if (m_NetworkBehaviour && !CanClientWrite(m_NetworkBehaviour.NetworkManager.LocalClientId))
{
LogWritePermissionError();
return;
Expand Down Expand Up @@ -575,7 +575,7 @@ public void Insert(int index, T item)
public void RemoveAt(int index)
{
// check write permissions
if (!CanClientWrite(m_NetworkBehaviour.NetworkManager.LocalClientId))
if (m_NetworkBehaviour && !CanClientWrite(m_NetworkBehaviour.NetworkManager.LocalClientId))
{
LogWritePermissionError();
return;
Expand Down Expand Up @@ -608,7 +608,7 @@ public T this[int index]
set
{
// check write permissions
if (!CanClientWrite(m_NetworkBehaviour.NetworkManager.LocalClientId))
if (m_NetworkBehaviour && !CanClientWrite(m_NetworkBehaviour.NetworkManager.LocalClientId))
{
LogWritePermissionError();
return;
Expand Down