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
2
Question by Curious-George · Jun 11, 2014 at 03:53 PM · coroutine

Monobehaviour IEnumerator Main() getting called automatically

I created a coroutine called "Main" on my Monobehaviour, and Unity seems to call it between Awake() and Start(). I can't find any reference to this behaviour in the Unity docs.

Can I count on this behaviour? Is this functionality deprecated? Did I miss it in the docs?

Comment
Add comment · Show 5
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 Jeff-Kesselman · Jun 11, 2014 at 03:54 PM 0
Share

I think more information is needed. Where do you actually start the co-routine? if its in Awake I could see this happening.

Can you show us the code please?

avatar image Loius · Jun 11, 2014 at 04:47 PM 0
Share

I don't know anything about Unity running $$anonymous$$ain functions. If you rename the function to "Not$$anonymous$$ain", what happens? If one of your things is calling it you should get some errors; once you fix them, if the function is still being called at this weird time, you know it's one of your things doing it.

avatar image Bunnybomb7670 · Jun 11, 2014 at 04:55 PM 0
Share

oh wow it actually does. I just tried it in my game. it does call $$anonymous$$ain.

avatar image Bunnybomb7670 · Jun 11, 2014 at 04:57 PM 0
Share

Just stick this code in any C# script and it will run without being called from anywhere. I think it has something to do with C# internally.

     void $$anonymous$$ain()
     {
         Debug.Log("$$anonymous$$AIN!");
     }
avatar image Curious-George · Jun 11, 2014 at 06:54 PM 0
Share

yeah.. I made a fresh project. It calls both "void $$anonymous$$ain()" and "IEnumerator $$anonymous$$ain()". I tried "void Start()" as a coroutine, and it seems to work, which also satisfies my use case, but it would have been nice not to have to spend 3 hours trying to figure out Unity automagically starting my coroutine..

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Chris_Dlala · Jun 11, 2014 at 09:44 PM

Hi. I assume it is being run as an entry point of some kind for C#. This is the standard entry point for C# applications (see here). Completely avoid using it! I imagine you will get no consistent behaviour from it. I hope that helps =)

Comment
Add comment · 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

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

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

Related Questions

Coroutines and waiting for a function to finish execution 1 Answer

Yield everytime boolean is True (C#) 1 Answer

How do I use Yield in C#? 3 Answers

Animation Event issue what am I doing wrong here 2 Answers

Activating 3 rotations based on multiple presses on one key 2 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