mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 11:00:32 +00:00
fix: isServer false in OnDestroy (#2101)
* fix isServer false in OnDestroy * making sure that OnDestroy doesn't call Destroy again
This commit is contained in:
parent
a124f3f439
commit
d46469a79c
@ -189,6 +189,11 @@ public sealed class NetworkIdentity : MonoBehaviour
|
||||
[FormerlySerializedAs("m_ServerOnly")]
|
||||
public bool serverOnly;
|
||||
|
||||
/// <summary>
|
||||
/// Set to try before Destroy is called so that OnDestroy doesn't try to destroy the object again
|
||||
/// </summary>
|
||||
internal bool destroyCalled;
|
||||
|
||||
/// <summary>
|
||||
/// The NetworkConnection associated with this NetworkIdentity. This is only valid for player objects on a local client.
|
||||
/// </summary>
|
||||
@ -705,7 +710,8 @@ void OnDestroy()
|
||||
|
||||
// If false the object has already been unspawned
|
||||
// if it is still true, then we need to unspawn it
|
||||
if (isServer)
|
||||
// if destroy is already called don't call it again
|
||||
if (isServer && !destroyCalled)
|
||||
{
|
||||
// Do not add logging to this (see above)
|
||||
NetworkServer.Destroy(gameObject);
|
||||
|
@ -1247,10 +1247,16 @@ static void DestroyObject(NetworkIdentity identity, bool destroyServerObject)
|
||||
// when unspawning, dont destroy the server's object
|
||||
if (destroyServerObject)
|
||||
{
|
||||
identity.destroyCalled = true;
|
||||
UnityEngine.Object.Destroy(identity.gameObject);
|
||||
}
|
||||
// if we are destroying the server object we don't need to reset the identity
|
||||
// reseting it will cause isClient/isServer to be false in the OnDestroy call
|
||||
else
|
||||
{
|
||||
identity.Reset();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Destroys this object and corresponding objects on all clients.
|
||||
|
Loading…
Reference in New Issue
Block a user