I have a simple piece of code:
_ui = Instantiate(userInterface, Vector3.zero, Quaternion.identity) as GameObject;
_ui.name = "UI";
_uiScript = _ui.GetComponent<UISetup>();
Debug.Log ("ASSIGNING PLAYER");
_uiScript.AssignPlayer(_pcScript);
Debug.Log ("PLAYER ASSIGNED");
I also have a Debug.Log(“UI SETUP START”); at the beggining of Start() method in UISetup class. The thing is, what I can see in my console is:
ASSIGNING PLAYER
PLAYER ASSIGNED
UI SETUP START
And also, a lot of stuff like null reference errors etc, because UISetup.AssingPlayer() uses stuff, that is initialized in Start().
I thought it is safe to assume, that after calling Instantiate(), Start() method of instantiated object and its components will be finished. Is there any pretty way for dealing with such situations? Maybe I could force waiting for Start() to be finished somehow?