Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Ben Humphreys · May 10, 2013 at 05:26 AM · debugstartlogawakedebug.log

Debug.Log print order, or Awake vs Start issue?

This seems crazy but I need to confirm it.

Does Debug.Log guarantee any kind of order that the messages are displayed relative to when Debug.Log() is called? I'm seeing some cases where it seems they're being shown out of order.

For example:

 // Instantiate object
 myObj = (GameObject) MonoBehaviour.Instantiate(somePrefab);
 myObj.Foo();

Then within SomePrefab,

 void Awake() { Debug.Log("Awake called"); }
 void Start() { Debug.Log("Start called"); }
 void Foo() { Debug.Log("Foo called"); } 

The output is:

 Awake called
 Foo called
 Start called

I am surprised that Foo() is called even before SomePrefab's fake constructor Start() thing has finished. Is it a Start()/Awake()/Instantiate issue, or a Debug.Log issue?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by Loius · May 10, 2013 at 06:24 AM

Nope, that's the right order. Awake is immediate initialization - essentially you're saying 'this init doesn't rely on anything, but things might rely on what i do here' inside an Awake. Start is 'i might need some data from somewhere else', so it waits its turn. As far as I know they happen within the same frame (awakes are called instantly, starts are piled up and executed one after the other at the end of all the normal unity events).

Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Ben Humphreys · May 10, 2013 at 06:31 AM 0
Share

If you can call methods on an object before its Start() is called, when would you ever want to put stuff in Start() ins$$anonymous$$d of Awake()? It seems like asking for things to be undefined.

It seems the first Update() isn't called until after Start(), so you could put things in Start() that you only need in Update(), but it seems like asking for trouble.

avatar image whydoidoit · May 10, 2013 at 06:34 AM 1
Share

Start is called just before the object is actually displayed for the first time.

Start is very useful because it lets you wait until an object is ready to be used before playing music, acquiring resource etc. It can also be a coroutine which is really handy. Using Start you can $$anonymous$$imise memory and processing impact of things that never become active too.

$$anonymous$$any of my scripts have just a coroutine Start function, or an Awake and Start.

avatar image whydoidoit · May 10, 2013 at 06:35 AM 1
Share

Oh yeah and without messing about with script execution orders Start can be used to find other fully configured objects.

avatar image Fattie · May 10, 2013 at 07:36 AM 1
Share

"It seems like asking for things to be undefined."

@ben, it can seem like that when you're just starting with Unity or a frame based game engine. When you are comfortable with it you will completely understand the difference between the two. A game engine is not possible without the distinction between the two.

Note that, quite simply, on Unity's documentation there is an excellent and long explanation of the difference.

or you can always have me being a smartass, Loius being a bitter smartass, and Whydoi being sage :-)

avatar image Fattie · May 10, 2013 at 07:37 AM 0
Share

one simple tip, every script has hundreds of "GameObject.Find(blah).GetComponent(blah)" statements. generally you have to do those in Awake(), so they are all available. then you do initialization (using those) in Start.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

16 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Why wouldn't Debug.Log show up in Start or Awake ? 3 Answers

Debug.Log is causing an Assert 2 Answers

DontDestroyOnLoad() not calling awake/start again 2 Answers

Object reference becomes null between Awake and Start after scene load 2 Answers

does finction start or awake run when the object or script is enabled mid game 3 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges