Skip to content

Commit

Permalink
fix: destroy owned objects (#1352)
Browse files Browse the repository at this point in the history
* fix: destroy owned objects

fix #1346
Broken in PR #1206

alternative to #1351

* fix nre

* Simplify
  • Loading branch information
paulpach committed Dec 24, 2019
1 parent d83efbb commit d7a58d2
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions Assets/Mirror/Runtime/NetworkIdentity.cs
Expand Up @@ -112,11 +112,25 @@ public sealed class NetworkIdentity : MonoBehaviour
/// </summary>
public NetworkConnection connectionToServer { get; internal set; }


private NetworkConnectionToClient _connectionToClient;
/// <summary>
/// The NetworkConnection associated with this <see cref="NetworkIdentity">NetworkIdentity.</see> This is valid for player and other owned objects in the server.
/// <para>Use it to return details such as the connection&apos;s identity, IP address and ready status.</para>
/// </summary>
public NetworkConnectionToClient connectionToClient { get; internal set; }
public NetworkConnectionToClient connectionToClient
{
get => _connectionToClient;

internal set
{
if (_connectionToClient != null)
_connectionToClient.RemoveOwnedObject(this);

_connectionToClient = value;
_connectionToClient?.AddOwnedObject(this);
}
}

/// <summary>
/// All spawned NetworkIdentities by netId. Available on server and client.
Expand Down Expand Up @@ -184,7 +198,6 @@ internal void SetClientOwner(NetworkConnection conn)
Debug.LogError($"Object {this} netId={netId} already has an owner", this);
}
connectionToClient = (NetworkConnectionToClient)conn;
connectionToClient.AddOwnedObject(this);
}

static uint nextNetworkId = 1;
Expand Down Expand Up @@ -1055,7 +1068,6 @@ public void RemoveClientAuthority()

NetworkConnectionToClient previousOwner = connectionToClient;

connectionToClient.RemoveOwnedObject(this);
connectionToClient = null;

// we need to resynchronize the entire object
Expand Down

0 comments on commit d7a58d2

Please sign in to comment.