Skip to content

Commit 50eb30c

Browse files
committed
Fix null reference exception
1 parent 6280f0f commit 50eb30c

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

com.unity.netcode.gameobjects/Runtime/Core/NetworkObject.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3232,7 +3232,10 @@ internal void SynchronizeNetworkBehaviours<T>(ref BufferSerializer<T> serializer
32323232
{
32333233
reader.ReadValueSafe(out ushort networkBehaviourId);
32343234
var networkBehaviour = GetNetworkBehaviourAtOrderIndex(networkBehaviourId);
3235-
networkBehaviour.Synchronize(ref serializer, targetClientId);
3235+
if (networkBehaviour != null)
3236+
{
3237+
networkBehaviour.Synchronize(ref serializer, targetClientId);
3238+
}
32363239
}
32373240
}
32383241
}

testproject/Assets/Tests/Runtime/Support/SpawnRpcDespawnInstanceHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public NetworkObject Instantiate(ulong ownerClientId, Vector3 position, Quaterni
4949
{
5050
if (NetworkLog.CurrentLogLevel <= LogLevel.Error)
5151
{
52-
NetworkLog.LogError($"Failed to create object locally. [{nameof(m_PrefabHash)}={m_PrefabHash}]. {nameof(NetworkPrefab)} could not be found. Is the prefab registered with {nameof(NetworkManager)}?");
52+
NetworkLog.LogError($"[{nameof(m_PrefabHash)}={m_PrefabHash}] Failed to create object locally. {nameof(NetworkPrefab)} could not be found. Is the prefab registered with {nameof(NetworkManager)}?");
5353
}
5454
return null;
5555
}

0 commit comments

Comments
 (0)