fix: stopping values being reset before OnDestory is called (#2485)

* fix: stopping values being reset before OnDestory is called

* matches server side logic
* if an object is being fully destroyed it doesn't need its values to be reset
This commit is contained in:
James Frowen 2020-12-03 15:50:52 +00:00 committed by GitHub
parent d07c0ceb0a
commit a51ee1fa3b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -951,23 +951,30 @@ static void DestroyObject(uint netId)
{ {
localObject.OnStopClient(); localObject.OnStopClient();
if (!InvokeUnSpawnHandler(localObject.assetId, localObject.gameObject)) // user handling
if (InvokeUnSpawnHandler(localObject.assetId, localObject.gameObject))
{ {
// reset object after user's handler
localObject.Reset();
}
// default handling // default handling
if (localObject.sceneId == 0) else if (localObject.sceneId == 0)
{ {
// dont call reset before destroy so that values are still set in OnDestroy
Object.Destroy(localObject.gameObject); Object.Destroy(localObject.gameObject);
} }
// scene object.. disable it in scene instead of destroying
else else
{ {
// scene object.. disable it in scene instead of destroying
localObject.gameObject.SetActive(false); localObject.gameObject.SetActive(false);
spawnableObjects[localObject.sceneId] = localObject; spawnableObjects[localObject.sceneId] = localObject;
} // reset for scene objects
}
NetworkIdentity.spawned.Remove(netId);
localObject.Reset(); localObject.Reset();
} }
// remove from dictionary no matter how it is unspawned
NetworkIdentity.spawned.Remove(netId);
}
else else
{ {
if (logger.LogEnabled()) logger.LogWarning("Did not find target for destroy message for " + netId); if (logger.LogEnabled()) logger.LogWarning("Did not find target for destroy message for " + netId);