Skip to content

Commit 96eba85

Browse files
EmandMNoelStephensUnity
authored andcommitted
Check for IsSpawned on despawn
1 parent 56f8b71 commit 96eba85

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1966,6 +1966,12 @@ public void SpawnAsPlayerObject(ulong clientId, bool destroyWithScene = false)
19661966
/// <param name="destroy">(true) the <see cref="GameObject"/> will be destroyed (false) the <see cref="GameObject"/> will persist after being despawned</param>
19671967
public void Despawn(bool destroy = true)
19681968
{
1969+
if (!IsSpawned)
1970+
{
1971+
NetworkLog.LogErrorServer("Object is not spawned!");
1972+
return;
1973+
}
1974+
19691975
foreach (var behavior in ChildNetworkBehaviours)
19701976
{
19711977
behavior.MarkVariablesDirty(false);

com.unity.netcode.gameobjects/Runtime/Spawning/NetworkSpawnManager.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1318,12 +1318,6 @@ internal void SendSpawnCallForObserverUpdate(ulong[] newObservers, NetworkObject
13181318

13191319
internal void DespawnObject(NetworkObject networkObject, bool destroyObject = false, bool authorityOverride = false)
13201320
{
1321-
if (!networkObject.IsSpawned)
1322-
{
1323-
NetworkLog.LogErrorServer("Object is not spawned!");
1324-
return;
1325-
}
1326-
13271321
if (!NetworkManager.IsServer && !NetworkManager.DistributedAuthorityMode)
13281322
{
13291323
NetworkLog.LogErrorServer("Only server can despawn objects");

0 commit comments

Comments
 (0)