Skip to content

Commit f258f0b

Browse files
committed
Added null checks to NetworkedObject
1 parent 5beac0f commit f258f0b

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

MLAPI/MonoBehaviours/Core/NetworkedObject.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,23 +124,26 @@ public bool isSpawned
124124

125125
private void OnDestroy()
126126
{
127-
SpawnManager.OnDestroyObject(NetworkId, false);
127+
if (NetworkingManager.singleton != null)
128+
SpawnManager.OnDestroyObject(NetworkId, false);
128129
}
129130

130131
/// <summary>
131132
/// Spawns this GameObject across the network. Can only be called from the Server
132133
/// </summary>
133134
public void Spawn()
134135
{
135-
SpawnManager.OnSpawnObject(this);
136+
if (NetworkingManager.singleton != null)
137+
SpawnManager.OnSpawnObject(this);
136138
}
137139
/// <summary>
138140
/// Spawns an object across the network with a given owner. Can only be called from server
139141
/// </summary>
140142
/// <param name="clientId">The clientId to own the object</param>
141143
public void SpawnWithOwnership(int clientId)
142144
{
143-
SpawnManager.OnSpawnObject(this, clientId);
145+
if (NetworkingManager.singleton != null)
146+
SpawnManager.OnSpawnObject(this, clientId);
144147
}
145148
/// <summary>
146149
/// Removes all ownership of an object from any client. Can only be called from server

0 commit comments

Comments
 (0)