- Home /
GameManager class doesn't accept GameObject.Find()
Hi All! I'm makeing a little game in a 3D village with 2D interior scenes (one for each building)... I'm starting with a GameManager componnent to manage the global members and methods like StartNewGame(), LoadGame(), SetGlobalVolume() and memebr like xPosition, yPosition, GameObjects[] arrayOfFoundObjects ecc.. All that after a little Intro scene that is a 10 seconds video (cam animation). When video is finished, there is a call to:
Application.LoadLevel ("Village");
DontDestroyOnLoad (GameManager.Instance);
GameManager.Instance.StartState ();
So, after the Intro i have the: public void StartState () {...} in which i have the member: Transform player; that in StartState() i have to set its value to: GameObject.Find ("Player").transform; so i can disable the MouseLook and the Camera components of the Player (FPS Input Controller) to stop the player and show the main menu.
The Unity compiler give me that error:
NullReferenceException: Object reference not set to an instance of an object GameManager.StartState () (at Assets/Scripts/GameManager.cs:39)
where the line is:
GameObject.Find ("Player").transform.GetComponent().enabled = false;
What can I do?
Thanks in advance
PS The GameManager is instantiated in the Village scene where i have the Player object and not in the Intro scene.
GameObject.Find ("Player").transform.GetComponent().enabled = false;
this line is missing the type in the GetComponent, is it there in the script though?
Sorry for the error... no in the script there is the component too:
GetComponent<$$anonymous$$ouseLook>().enabled = false;
Your answer
![](https://koobas.hobune.stream/wayback/20220613143033im_/https://answers.unity.com/themes/thub/images/avi.jpg)