UnityEngine.Networking.NetworkMigrationManager.ReconnectObjectForConnection C# (CSharp) Method

ReconnectObjectForConnection() public method

This re-establishes a non-player object with client authority with a client that is reconnected. It is similar to NetworkServer.SpawnWithClientAuthority().

public ReconnectObjectForConnection ( NetworkConnection newConnection, GameObject oldObject, int oldConnectionId ) : bool
newConnection NetworkConnection The connection of the new client.
oldObject UnityEngine.GameObject The object with client authority that is being reconnected.
oldConnectionId int This client's connectionId on the old host.
return bool
        public bool ReconnectObjectForConnection(NetworkConnection newConnection, GameObject oldObject, int oldConnectionId)
        {
            if (!NetworkServer.active)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("ReconnectObjectForConnection must have active server");
                }
                return false;
            }
            if (LogFilter.logDebug)
            {
                Debug.Log(string.Concat(new object[] { "ReconnectObjectForConnection: oldConnId=", oldConnectionId, " obj=", oldObject, " conn:", newConnection }));
            }
            if (!this.m_PendingPlayers.ContainsKey(oldConnectionId))
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("ReconnectObjectForConnection oldConnId=" + oldConnectionId + " not found.");
                }
                return false;
            }
            oldObject.SetActive(true);
            oldObject.GetComponent<NetworkIdentity>().SetNetworkInstanceId(new NetworkInstanceId(0));
            if (!NetworkServer.SpawnWithClientAuthority(oldObject, newConnection))
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("ReconnectObjectForConnection oldConnId=" + oldConnectionId + " SpawnWithClientAuthority failed.");
                }
                return false;
            }
            return true;
        }