Start() VS Awake()

Hi,

What is diffrent between this 2 function exactly?

So thanks.

1 Like

The documentation explains this well.

p.s. Wrong forum. Should be in the support forum, not gossip.

11 Likes

so thanks.
but i read the document before.my english is not so good.i did not understand it.if u can help me please.

so thanks.

If you can tell us what your native language is, perhaps there is someone on the forums who could help translate what’s in the documentation.

1 Like

Generally the main difference is:

Awake: Here you setup the component you are on right now (the “this” object)

Start: Here you setup things that depend on other components.

if you split it that way you can always be sure that the other object is ready to work with you as game objects in scenes on scene load are loaded in blocks:

  1. All awake are executed
  2. All start are executed
  3. all go into update
26 Likes

During a game, if you use

gameObject.active = false;

then later

gameObject.active = true;

do the object’s scripts run their Start or Awake functions again?

3 Likes

Nope, Awake and Start happen once in the lifetime of any game object.

6 Likes

Awake is called first and should be used as the constructor. So you can construct a object with Awake() and create a reference to another script.

Then start is called. Start is used if you want to delay the order of initialization and pass info to the other script about the constructed object and to do stuff that is not closely tied to instantiation.

6 Likes

Thanks for the answer I always got confused in that Matter.

I would like to add a few of my observations: be aware that some key Unity variables might not be set yet when you call Awake(). For instance: NetBehaviour.isLocalPlayer is always “false” in Awake(), even if it will become “true” inside Start(). Moreover, Awake() is always called before any network messages are received, while you can receive a message before Start() gets called. And the last one: if you set .enabled = false in Start(), the component will still receive messages (like LateUpdate()) during that first frame, while if you do the same in Awake(), no messages will be received.

Disclamer: all statements above are just my humble observations, don’t take them as a rule.

5 Likes

Wow. Supreme necromancy of this nature should not be taken in stride. We must alert the council, for I fear that He has returned.

As a novice in programming and writing software in general, I generally like to think of “Awake()” as when my object wakes up in the morning. It’s still in bed, so not all of the faculties are there yet. It hasn’t put on all of its clothes or brushed its teeth. But it knows who it is. “Start()” I like to think of as basically the first Update(). I don’t think of it as being before the the first Update() because I’ve been burned before.

In general, Start() is useful for GetComponent() calls and any object that has no Update() logic, and basically just invokes a method or spawns something. Kind of like a “one-off” method. The best part about Start() is that it’s like an Awake() that doesn’t give you random errors about things not existing yet… and it only happens one time per object. Which, when you think about it, basically lets you write an entire method to avoid creating a bool variable “Initialized” and setting it for true after the first Update() and doing all your setup logic in an if statement… which when you then think about that, it’s not much more work to do it that way.

In the end, Love is really the answer.

7 Likes

The way I see it is really simple. Use Awake() for initiating ONLY this component, and Start() for communicating between components before the game starts. That makes sure all components are ready before they communicate, and you have Start() free to do all your world-building and preparation.

@Master-Frog basically what you said!

1 Like

…how so?

The first “Start” gets called after all of the "Awake"s have been called.

Awake() gets called during initialisation, where Start() gets called after. So during Awake() you can’t assume that other things have finished initialising yet, but by the time Start comes around you can.

With that in mind, personally, I use “Awake” for any internal setup (ie: all the things I can do without dependency on other GameObjects), and Start() for any external setup (eg: hooking up to other GameObjects). So by the end of Awake() a component should be ready to receive any call from other components, but it can’t necessarily make calls to other components because it doesn’t know if they’ve finished setting themselves up yet.

6 Likes

This very short video explains it well: Start MonoBehaviour Methods - Unity Learn

(Posting it here to save others the trouble of reading through a lengthy topic about it, as this is where google led to)

3 Likes

So is it like…
Awake is loading all the game content when i start the game and its kinda all hidden
Start is all that starting animations(productions loading and stuff)
Update all that is done in the Main menu after everything is loaded
?

Really great Community. I am going to be one of you :slight_smile:

1 Like

Just sth that I realized if anyone hops on to this thread later on;

Trying to manipulate the exposed variables of AudioMixer does not work in any Awake() function of a script. I spent at least an hour to try to figure out why my audio did always get reset and reading from PlayerRefs at the start of the game did not affect my audio level until I moved the sliders. I got a bit suspicious of Awake function and tried to set up the exposed variables of AudioMixer in the Start function and it worked without problems.

1 Like

Yeah, that’s a “known issue” which is “by design” and yet completely undocumented, and has been that way for years. Discussed at length in a thread somewhere.

It’s because some part of the audio system is initialised after Awake(), and that includes setting values from elsewhere which override anything you set in Awake().

Link .

1 Like