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?

first make sure the gameobject with the teleport script on it have a collider component, if not add one by choosing an appropriate one by clicking add component. then change the line where it says void OnTriggerEnter() to void OnTriggerEnter(Collider collider) and the line OnTriggerStay() to void OnTriggerStay(Collider collider)

2 Answers

2

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.

there is this other notification that says "field teleport.player was never assigned to and will always have its default value null ps.the collider collider has no effect

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

NetworkManager.singleton.client

I think you haven't read the question, right? > 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

you need to create a player, have you done that yet? if yes then rename it to Player with a capital p, and can I see a screenshot of the code or a snippet and a screenshot of the inspector