#Owned NetworkObjects are being auto destroyed when Owner disconnects

4 messages · Page 1 of 1 (latest)

sturdy meadow
#

My players can use skills which create slow moving projectiles. When they disconnect I want them to carry on, transferring ownership to server but they just are auto destroyed atm. I can't seem to find a way to do this. Looking through Ownership/ServerManager/ClientManager docs I'm not sure how I disable this behavior.

deft nova
# sturdy meadow My players can use skills which create slow moving projectiles. When they discon...

Hi there, here's a script you can put on the object to remove the ownership before it gets despawned due to its owner disconnecting:

using FishNet.Connection;
using FishNet.Managing.Server;
using FishNet.Object;

public class OwnershipRemovalOnDisconnect : NetworkBehaviour
{
    public override void OnStartServer()
    {
        ServerManager.Objects.OnPreDestroyClientObjects += OnPreDestroyClientObjects;
    }

    public override void OnStopServer()
    {
        if (ServerManager)
            ServerManager.Objects.OnPreDestroyClientObjects -= OnPreDestroyClientObjects;
    }

    private void OnPreDestroyClientObjects(NetworkConnection conn)
    {
        if (conn == Owner)
            RemoveOwnership();
    }
}
sturdy meadow
#

Ah there it is, thank you.

quiet locust
#

Nice, I had same issue 😄 Was just not priority! Thank you @deft nova