When to use Start() and when to use Awake()?

I have a Start functions running in about 4 scripts, and it’s causing a hang when I load the game to test.

Should I be using Awake? Or Should I have just one centralized script running one Start function?

My problem is my fourth script using Start, it’s not finding the objects initially, probably because they’re also being instantiated in a Start function on another script, would yield help me out here? Here’s the code;

function Start ()
{
	//Find Left Wing Locator
	wingLocL = GameObject.Find("OwlAdl01_WingLoc_L");
	//Find Right Wing Locator
	wingLocR = GameObject.Find("OwlAdl01_WingLoc_R");
	
	//Instantiate Left Closed Wing
	tempMeshL = Instantiate (wingsClosedL[iWing], wingLocL.transform.position, wingLocL.transform.rotation);
	//Make Left Closed Wing child of Left Wing Locator
	tempMeshL.transform.parent = wingLocL.transform;
	
	//Instantiate Right Closed Wing
	tempMeshR = Instantiate (wingsClosedR[iWing], wingLocR.transform.position, wingLocR.transform.rotation);
	//Make Right Closed Wing child of Right Wing Locator
	tempMeshR.transform.parent = wingLocR.transform;
}

This might help:

http://answers.unity3d.com/questions/2710/what-is-the-general-use-of-awake-start-update-fixedupdate-lateupdate

Why are you performing these actions at runtime instead of in the Editor and saving with a scene?

Personally, I use Awake primarily to set things up that I actually want serialized, but which can’t be. My main use for Awake is to register event listeners. Start is only used for code that has nothing to do with dependencies, but that sets off whatever events are helpful at the beginning of the game.

Thanks for the tip FizixMan but I only want this code executed once when the game is first launched.

The reason I’m performing these actions at runtime is because the objects I’m searching for are only instantiated at runtime. Basically I spawn various body parts of a character when the game launches, and you can then swap out/customize these body parts with a button press. Maybe it would be wiser if I had the initial meshes in place in the editor rather than instantiating it all on Start/Awake, that hadn’t occurred to me until now :stuck_out_tongue: Thanks for the tips on how you use Start and Awake, I think I’ve probably been using both too liberally.

If you want a script to run once on game startup, then create an empty GameObject, place it into your scene, and attach some “GameStartup” script to it.