CleanupNetworkIdentities: better comments and call DestroyObject with DestroyMode.Destroy for spawned prefabs directly. more obvious.

This commit is contained in:
vis2k 2021-07-31 17:10:49 +08:00
parent beff4b634a
commit 47bd2b7c78

View File

@ -129,21 +129,19 @@ static void CleanupNetworkIdentities()
{ {
if (identity != null) if (identity != null)
{ {
// spawned scene objects are reset and disabled. // scene object
// they always stay in the scene, we don't destroy them.
if (identity.sceneId != 0) if (identity.sceneId != 0)
{ {
// spawned scene objects are only reset and disabled.
// they always stay in the scene, we don't destroy them.
identity.Reset(); identity.Reset();
identity.gameObject.SetActive(false); identity.gameObject.SetActive(false);
} }
// spawned prefabs are destroyed // spawned prefabs
else else
{ {
// call NetworkServer.Destroy directly instead of // spawned prefabs are unspawned and destroyed.
// GameObject.Destroy()-> DestroyObject(identity, DestroyMode.Destroy);
// NetworkIdentity.OnDestroy()->
// NetworkServer.Destroy()
Destroy(identity.gameObject);
} }
} }
} }