Skip to content

Commit 7f0d80c

Browse files
committed
fix: Fixed null reference exception in OnValidate
1 parent 8c747a3 commit 7f0d80c

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

MLAPI/Core/NetworkingManager.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,17 @@ private void OnValidate()
254254

255255
for (int i = 0; i < NetworkConfig.NetworkedPrefabs.Count; i++)
256256
{
257-
NetworkConfig.NetworkedPrefabs[i].Prefab.GetComponent<NetworkedObject>().ValidateHash();
257+
if (NetworkConfig.NetworkedPrefabs[i] != null && NetworkConfig.NetworkedPrefabs[i].Prefab != null)
258+
{
259+
if (NetworkConfig.NetworkedPrefabs[i].Prefab.GetComponent<NetworkedObject>() == null)
260+
{
261+
if (LogHelper.CurrentLogLevel <= LogLevel.Normal) LogHelper.LogWarning("The network prefab [" + i + "] does not have a NetworkedObject component");
262+
}
263+
else
264+
{
265+
NetworkConfig.NetworkedPrefabs[i].Prefab.GetComponent<NetworkedObject>().ValidateHash();
266+
}
267+
}
258268
}
259269

260270
// TODO: Show which two prefab generators that collide

0 commit comments

Comments
 (0)