I have an in-scene object that needs to access the camera of the local PlayerObject, once it has spawned.
Inside the start method of said object, i have the following code:
NetworkManager.Singleton.OnClientStarted += () => {
print(NetworkManager.Singleton.LocalClient.PlayerObject); // This is null in the clients
_mainCam = NetworkManager.Singleton.LocalClient.PlayerObject.GetComponentInChildren<Camera>();
_portalCam.projectionMatrix = _mainCam.projectionMatrix;
};
This works fine on the host, and everything initializes as expected, but for clients joining, the local PlayerObject is null here. It does eventually spawn, but thats after OnClientStarted
has been called. According to the documentation it should be called “once the local client is ready” (Event OnClientStarted | Netcode for GameObjects | 1.7.1).
Shouldnt OnClientStarted only be called after the local player object has been set up, or am i mistaken?
If not, does anyone know why its being called before the player has spawned in? Or what other callback i can use?