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,22 +951,29 @@ static void DestroyObject(uint netId)
{
localObject.OnStopClient();
if (!InvokeUnSpawnHandler(localObject.assetId, localObject.gameObject))
// user handling
if (InvokeUnSpawnHandler(localObject.assetId, localObject.gameObject))
{
// default handling
if (localObject.sceneId == 0)
{
Object.Destroy(localObject.gameObject);
}
else
{
// scene object.. disable it in scene instead of destroying
localObject.gameObject.SetActive(false);
spawnableObjects[localObject.sceneId] = localObject;
}
// reset object after user's handler
localObject.Reset();
}
// default handling
else if (localObject.sceneId == 0)
{
// dont call reset before destroy so that values are still set in OnDestroy
Object.Destroy(localObject.gameObject);
}
// scene object.. disable it in scene instead of destroying
else
{
localObject.gameObject.SetActive(false);
spawnableObjects[localObject.sceneId] = localObject;
// reset for scene objects
localObject.Reset();
}
// remove from dictionary no matter how it is unspawned
NetworkIdentity.spawned.Remove(netId);
localObject.Reset();
}
else
{