- Home /
start called directly after instantiate?
Hey,
If I have following code:
void Spawn()
{
GameObject newObject = (GameObject) Instantiate(Resources.Load("newObject", typeof (GameObject)));
newObject.GetComponent().enabled = false;
}
will the start() and awake() functions of "anyScript" be called or before the component is deactivated or will it be called when the component is getting enabled again?
Answer by Jeff-Kesselman · May 08, 2014 at 08:19 PM
The Unity scripting environment is basically mono-threaded. Im pretty sure that they don't get called until after the method returns. But Im not 100% sure, especially with Awake.
Its possible Awake gets called as part of construction.
But it would be easy enough to check. Create a public field on the monobehaviour that is initialized to false. Set it to true where you have enabled=false above, and print it in Awake and Start.
Yes, Awake is called as part of Instantiate. I assume this is on purpose, so you have the option of immediately using it "fully set up."
Your answer
Follow this Question
Related Questions
Full list of predefined voids? 2 Answers
Initialising List array for use in a custom Editor 1 Answer
C# void names 1 Answer
Multiple Cars not working 1 Answer
Update and Awake not being called. 1 Answer