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
0
Question by Fattie · Sep 26, 2013 at 09:32 AM · updatestart

Is it absolutely unconditionally true that Start runs BEFORE the FIRST Update?

I appreciate there are numerous questions / doco pages on the various aspects of what-comes-first.

But, is it absolutely true that Start() runs BEFORE the FIRST Update() ?

Is this always the case, even if the gameObject enters the scene inactive, it comes from a prefab, or whatever the hell else happens?

(You could almost ask: IS THERE ANY CASE where the first Update() WILL come prior to Start() ?)

Thanks.

FTR, this in relation to the astounding Jessy Insight here:

Astounding method to delay runloop until after Start()

Comment
Add comment · Show 3
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 meat5000 ♦ · Sep 26, 2013 at 12:35 PM 1
Share

I notice if you deactivate then reactivate a script, Start() is not called. It was most inconvenient.

avatar image Fattie · Sep 26, 2013 at 12:44 PM 0
Share

Right, you need (I think) OnEnable() for that - but it's very hard to keep it fresh in your head!

avatar image meat5000 ♦ · Sep 26, 2013 at 12:51 PM 0
Share

That lead me to this :)

2 Replies

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

Answer by whydoidoit · Sep 26, 2013 at 12:36 PM

Well Start won't necessarily complete before the first Update, if Start is a coroutine, only the code before the yield will execute before Update, then Update, then Update again, then whatever comes after the yield. Thereafter the code will continue to run after Update.

 IEnumerator Start()
 {
      Debug.Log("Before Update");
      yield return null;
      Debug.Log("After Update");
      yield return null;
      while(true)
      {
          Debug.Log("Start coroutine");
          yield return null;
      }
 }


 void Update()
 {
      Debug.Log("In Update");
 }
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 whydoidoit · Sep 26, 2013 at 12:44 PM 1
Share

Also be aware that it is generally a bad idea to use Start as a coroutine if there is any danger your object will be disabled and re-enabled. Ins$$anonymous$$d use OnEnable to start a coroutine.

avatar image Fattie · Sep 26, 2013 at 12:46 PM 0
Share

Right on with the completion aspect. (Indeed, note Jessy's incredible trick in the link - I'd never thought of it.)

You're pretty sure there's no unusual circumstances where Start would not proceed Update ?

(You know how there's a freaking vast number of "corner cases" with this stuff. If it's just been made inactive .. whatever .. loaded .. maybe I'm straight wrong and it's "absolutely bulletproof truth".)

avatar image whydoidoit · Sep 26, 2013 at 12:47 PM 0
Share

I code as if it were and have never noticed any problem.

avatar image Fattie · Sep 26, 2013 at 12:49 PM 0
Share

"I code as if it were and have never noticed any problem."

Fair Enough.

avatar image Fattie · Sep 30, 2013 at 06:06 AM 0
Share

i think this is the best thing to an answer on this trouble-raising issue! heh

avatar image
2

Answer by Visual Programmer · Sep 26, 2013 at 12:31 PM

Start is always called before the first Update (hence why it is called start). You can even test if for yourself by putting in Debug.Log("This is start") and Debug.Log("This is update") in each function.

Comment
Add comment · Show 2 · 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 Fattie · Sep 26, 2013 at 12:44 PM 0
Share

O$$anonymous$$. But would you bet your life on this knowledge?

avatar image Visual Programmer · Sep 26, 2013 at 12:54 PM 1
Share

No need to bet my life. It's how it works. Start is always called before, but as whydoidoit mentioned, you can delay the completion of the function.

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

18 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 avatar image avatar image

Related Questions

Why if I execute .SetText on the Start it dont works. 1 Answer

Start being called after Update of another GameObject? 0 Answers

Start() not called upon instantation? 1 Answer

Saving the starting position of a Lerp during Update 2 Answers

Update and Awake not being called. 1 Answer


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