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 gardian06 · Feb 20, 2013 at 04:48 PM · coroutinestatus

Determining the status of a Coroutine

is there any way to see what the current status of a coroutine is? for example if I am driving my GUI based on the current status of a coroutine display X while coroutine is at PointX, and display Y while coroutine is at PointY, and display Z when coroutine is finished.

I know that you could probably do this with globals, but I am more thinking of actually seeing what the last thing yield returned by the coroutine was.

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

Answer by vbbartlett · Feb 21, 2013 at 01:37 AM

Only way would be to have the script maintain a state variable and update it in the coroutine. The script has access to its own variables whether in the Update() or in a coroutine.

class Example:MonoBehaviour {

 int m_state;
 IEnumerator CoroutineFunction ()
 {
   m_state = 0;
   // do something
   yield return null;
   m_state++;
   // do something else
   yield return null;
   m_state++;
   // do something else
   yield return null;
   m_state++;
   // do something else
   yield return null;
 }
 void Update()
 {
   switch(m_state)
   ....
 // or
   if(m_state == *desiredState*)
   ...
 }
Comment
Add comment · Show 3 · 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 gardian06 · Feb 21, 2013 at 01:43 PM 0
Share

that is essentially/exactly what I meant by "global" (a variable that exists outside of a method, or main). I was thinking that because the keyword return is used that a value would be visible with regard to the IEnumerator

avatar image Bunny83 · Feb 21, 2013 at 02:20 PM 1
Share

Well, you could probably use reflection on the IEnumerator object you used to start the coroutine, but that's not really a good approach since the class is auto-generated by the compiler and is a private class.

avatar image gardian06 · Feb 25, 2013 at 06:09 AM 0
Share

@Bunny83 a little more explanation, and that is probably the answer to the question (whether I like it or not)

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

11 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

Related Questions

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

Yield not working properly 1 Answer

'pausing' a game to wait for user to select object before proceeding 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