Does Awake run again on gameObject.SetActive(true)?

Hi guys, quick question

if I:

  • instantiate gameObject
  • the attached script’s Awake function will run
  • i decide to gameObject.SetActive(false)
  • 5 seconds pass
  • i then gameObject.SetActive(true)

will the Awake function run again?

thanks!

No, Awake() is only called once on an object.

OnEnable is called every time it is activated, though.

4 Likes

i was doing a lot of get component calls in the on Awake and was worried it would be running it again every time i setActive(true)

thanks for clearing it up :smile:

As a side note, you could try to use a debug.log command to see if your Awake method is called many times :slight_smile:
Not that I’m not saying you shouldn’t ask here (don’t get me wrong), but instead I am just letting you know, in case you never used it.

It is really handy when you want to debug your script…

 Debug.Log("insert your message here");

yea sorry, thanks for the tip.
just posted whilst on the bus