How to get the current NetworkClient?

It seems like the only way I can find is to use myNetworkManager.client.

However, this variable is always null for me.

This might be because I override OnClientConnect, because I don’t want to set the client as ready until he joins the correct scene (Why this isn’t the default behavior is ridiculous). It seems like just removing all the functionality of OnClientConnect might be causing the networkManager.client reference to not get set. I had to manually set the client connection to a new variable clientConnection in OnClientConnect so that I can reference it later. So maybe I have to do this for the NetworkClient as well.

How do I get it?

Hello, I know this is a pretty old question but I had this same issue today and was able to solve the problem. You can get the current NetworkClient object from the NetworkManager instance in the scene.

In the hierarchy, I have a specific GameObject hold the standard networking scripts (including a NetworkManager). Then, on a different GameObject I have a script which needs the NetworkClient to do some communication. In that other script I have a public NetworkManager property which is wired up by dragging the NetworkManager GameObject into the slot via the inspector. That way my other script (the one that needs the active NetworkClient object) has access to the instance of the NetworkManager and can reference the NetworkClient via the “client” property.

This one way exist to retrieve client instance directly at any place within your scripts.