custom NetworkServer.RegisterHandler overwrites standard Handler?

When I put this in one of my scripts, the Connect and Disconnect overwritten fuctions inside my custom NetworkManager are not getting called (eg. when a player disconnecteds, it’s playerPrefab does not get cleaned up).

public override void OnStartServer() {
        NetworkServer.RegisterHandler(MsgType.Connect, OnClientConnect);
        NetworkServer.RegisterHandler(MsgType.Disconnect, OnClientDisconnect);
        base.OnStartServer();
    }
    void OnClientDisconnect(NetworkMessage netMsg) {
        vrPlayMenuCanvas.gameObject.SetActive(true);
    }

    void OnClientConnect(NetworkMessage netMsg) {
        vrPlayMenuCanvas.gameObject.SetActive(false);
    }

Is this intended? I thought I can Register multiple handlers for these messages in multiple scripts?

Client Handlers will not be called on a NetworkServer. These are functions that denote actions that happen on the client (e.g. OnClientConnect, OnClientDisconnect) or on the server (OnServerConnect, OnServerDisconnect). OnClientConnect is an event that fires on the CLIENT when it connects to a host/server. OnServerConnect is an event that is fired on the SERVER/HOST when someone connects to it. You currently are registering these client actions to the

As well, if you are just overwriting the standard handlers, you should be able to just overwrite them without having to explicitly register them.

It’s a host on which I have tested it. Therefor both handlers, for clients and server, should be called. The function naming is wrong in this case, it should be “OnServerConnect” and “OnServerDisconnect”, you’re right. But this is just naming my own handlers and it’s not the reason why “OnClientConnected” in NetworkManager stops being called when I register my own handler.

I get a warning on the server btw on Disconnect of another Client: “Sending message header failed”. My own function OnServerDisconnect get called, but not the one I overwrite in the NetworkManager

I would need to see more of your code in order to better understand. But, assuming you are using the handler “OnClientConnected,” then the reason why your handler is not being called, is because it should be “OnClientConnect” instead of “OnClientConnected.” Try changing the name of your handler and see if that works out. If it does not, then I would need to see more in order to help.

I am experiencing the same issue ! I add a RequestHandler to a script, and that break my OwnNetworkManager (which herit from NetworkManager) OnServerConnect and OnServerDisconnect call !

I’m pretty sure base.OnStartServer is overwriting your handlers. Try moving it to the top of the method.

Rant: why can’t UNET use a list of delegates instead of this RegisterHandler crap? :confused:

1 Like