Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Rafes · Jul 17, 2011 at 04:27 PM · startsendmessageframebroadcastmessage

SendMessage is running before Start

I am instancing and object then sending a message to the new instance. I added some debug messages with Time.time and it appears that SendMessage runs before Start() in the same frame. This is a problem since Start() will often be used to initialize something. In my case, it is a something which I need to be available when SendMessage triggers a call.

Is this the expected behaviour or a bug?

Shouldn't Start() be the first call the frame after instanciation? The wiki doesn't have this information here: http://www.unifycommunity.com/wiki/index.php?title=Event_Execution_Order

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
2
Best Answer

Answer by sneftel · Jul 17, 2011 at 04:35 PM

Start() is called on the next frame, but SendMessage() is delivered immediately. Awake() and OnEnable() are called before Instantiate() returns, so if you can sufficiently initialize the object there, do that.

Comment
Add comment · Show 4 · 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 Bunny83 · Jul 17, 2011 at 06:30 PM 0
Share

Awake and OnEnable are called from the internal constructor. When Instantiate returns Awake has already been called so it's like the constructor of your class ;)

avatar image sneftel · Jul 17, 2011 at 06:44 PM 0
Share

Hmmmm... I don't think they are called from a constructor. Looking at the stack trace from Awake() invoked from Instantiate() (the real stack trace, not the Unity-scrubbed one), it looks like Awake() is directly invoked by UnityEngine.Object.INTERNAL_CALL_Internal_InstantiateSingle, without an intervening constructor call.

avatar image sneftel · Jul 17, 2011 at 06:44 PM 0
Share

Of course, by "the internal constructor" you probably meant the function that does the constructing. I apologize for being pedantic. :)

avatar image Rafes · Jul 18, 2011 at 12:16 AM 0
Share

Thanks! Confirmation means I can move on! If you are a Pool$$anonymous$$anager user, please see this post for our work-around if this is a problem: http://poolmanager.freeforums.org/post23.html#p23 We basically added another event that can be used for init after Awake if needed, but is guaranteed to run right after Awake. I'm hoping this won't be necessary with the next release of Unity - I read it will allow us to explicitly set an order during Awake() if needed.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

BroadcastMessage Functionality Help 1 Answer

Is it possible to use SendMessage() on an uninstantiated prefab? 0 Answers

What's the best way to get the total time since the start of the current frame? 1 Answer

Broadcast Message Problems 1 Answer

SendMessage getting "stuck" / looping animation, not returning to Update 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