GameObject.Find/WithTag returns null

Ok guys so I’m having the following problem.

In the constructor of one of my scripts no matter what I do, the variable “player” is null, even though it shouldn’t be.

private StateManager manager;
	private GameObject player;
	private PlayerController controller;
	
	public OnRailsPlayState (StateManager managerRef) // Constructor
	{
		// Ensures that each State had a reference to the manager class // JS
		// manager of class Statemanger now holds a reference to StateManager // JS
		manager = managerRef;
		if(Application.loadedLevelName != "OnRailsPrototypeFinal")
			Application.LoadLevel("OnRailsPrototypeFinal");
		
		
		player = GameObject.Find ("SpeedCharacter");
		if(player != null)
			controller = player.GetComponent<PlayerController>();
		
		Debug.Log (player);
		Debug.Log (controller);

Yes there is a GameObject in the scene named “SpeedCharacter” just as it is typed there.
The only thing I can think of is that it has something to do with the States system I’m trying to implement.

The Game starts in a scene that has a GameObject called GameManager in it with my stateManger script attached to it. At that point it is in the BeginSttae.

You click a buton in this scene and it switches you to a new scene and (state, the OnRailsPlayState listed here in code). In this scene is where the game object “SpeedCharacter” is.

So it shouldn’t be null.

Any help at all would be greatly appreciated.

Thank you.

Hey guys I solved the problem. Basically I was switching states faster then the next scene was loading, thus the player object I declared in my script couldn’t find the gameObject thus it was coming back as null.

Implemented a load screen to load between scene changes and now it works since it delays the swapping of states until the scene is loaded.