UNET reconnect

Hello.
Now i do the reconnecting if player has disconnected (as in Hearthstone, yes everywhere, in principle). I use HLAPI, i.e. the player is prefab with NetworkBehaviour. When disconnect, its object is destroyed.

Now i think to record the state of the player when the player disconnects, and when connected, write this data to the freshly spawned NetworkBehaviour. But this will lead to a rewriting of a large amount of logic.

Is it possible to cancel the auto-destroying of NetworkBehaviour on the client and the server and when connecting the player - set player authority to this prefab?

Thanks.

yes, just override OnServerDisconnect in your NetworkManager;

/// <summary>
    /// Disconnect client hook;
    /// </summary>
    /// <param name="conn"></param>
    public override void OnServerDisconnect(NetworkConnection conn)
    {
       //NetworkServer.DestroyPlayersForConnection(conn);
    }

Uncommenting “NetworkServer.DestroyPlayersForConnection(conn)” will toggle destroying of player gameObject.

But how do you add the player back after that?

override OnServerAddPlayer

How do you override that functions if I don’t have my own implementation of the NetworkManager? I’m just using HLAPI

Create a class and derive from NetworkManager.

1 Like

Ok, so to clarify:
I have a NetworkManager GameObject, with a NetworkManager component. Should I remove this component, and instead use MyOwnNetworkManager Script?

UPDATE

I implemented it, great!

1 Like

Despite the fact I’m overloading the NetworkManager method, when players reconnect, new player GameObjects are instantiated and spawned. I would like to implement a system in which when player reconnects, check if there is a Player GameObject and uses it when exists. How could I implement something like this?
I am also trying to understand what Severos has imlemented in his functions on this

post: Login system for online multiplayer game

which can be useful for me, but I don’t fully understand everything yet.
Do you know if there is some documentation or a useful post about how to design a system to manage player reconnection, considering user/password?

You might check this https://discussions.unity.com/t/687412

UNET hlapi is going to be deprecated though.

1 Like

My final word is to forget about all of these “high level libraries” and start doing it from low level. It will give you an understanding of how things work and also, you will have precise control over everything. I had 3 stages. 1st, started from unet hlapi, realized that it’s not sufficient at all, had much of overhead + not concurrent. 2nd, moved to LIteNetLib. It gave me a bit more control, but the cpu usage for my goal was bit to high. But then, 3rd stage was moving to low level ENet library.

I know it might be painful and sometimes scarry to dive in low level. But you will learn fast day by day, trust me.

Cheers.

1 Like

Thanks for your recommendation. And what do you think about the LLAPI?

Well. There is no much of concurrency. And receiving is single threaded. That means that your receiving depended on frame rate. In other words, LLAPI is not multi-threaded. Sending is multi-threaded. And by the way, UNET is going to be deprecated soon.
My recommendation is to use ENet : GitHub - nxrighthere/ENet-CSharp: Reliable UDP networking library
Benchmark results: https://github.com/nxrighthere/BenchmarkNet/wiki/Benchmark-Results