Local variable gets null after assigning.
Hey,
I have a network object with a class attached named Hook.cs, and another network object with Player.cs class attached to it.
To be clear hook is like a bullet and the player is the one who shoots it.
now whenever my player collided with my hook, Player.cs calls a method on Hook.cs :
private void OnTriggerEnter(Collider incomingHook) { if (incomingHook.gameObject.tag == "Hook") { Debug.Log("hook collided"); incomingHook.gameObject.transform.parent.GetComponent<NetworkOnHook>().HookCatch(Object.gameObject,Object.InputAuthority); HandleAfterHook(); } }
and this is the method that has been called:
public void HookCatch(GameObject plr, PlayerRef playerRef) { if (Object.HasInputAuthority) { if (Runner.TryGetPlayerObject(playerRef, out var playerObj)) { hookedPlayerController = playerObj.GetComponent<NetworkPlayerController>(); Debug.Log(hookedPlayerController.playerID); } } }
and as you can see, my variable hookedPlayerController is not null at the moment it has been initialized, but when I check that on my fixedUpdateNetwork method or Update or other methods, it's null.
I wonder what the problem is and I appreciate a tip or a guide.
0