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 m4a44 · Mar 31, 2014 at 08:20 PM · updatemonodevelopienumeratorstartcoroutine

IEnumerator in Update

I am just wondering if you can run an IEnumerator (or any iterator) within Update (or an Update called from a mono Update). I am not inheriting from Monodevelop, so I cannot use the function StartCoroutine().

Or should I just reference a mono script and use it's StartCoroutine()?

Edit 1: I am specifically wondering if I can yield a time value (as I can iterate through it with MoveNext(), but it doesn't yield to time yields).

Comment
Add comment · Show 6
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 getyour411 · Mar 31, 2014 at 11:05 PM 1
Share

If you aren't inheriting from $$anonymous$$ono, there is no Update(). . . ?

avatar image CatchCo · Mar 31, 2014 at 11:31 PM 2
Share

So your question is lacking any substance for us to answer on. Can you pose your question in a different way? Such as what you are trying to do and what is not working?

avatar image Bunny83 · Apr 01, 2014 at 01:55 AM 0
Share

Like the others said, your question doesn't make much sense. First you have to distinguish between a simple IEnumerator or IEnumerable and a coroutine (which also returns an IEnumerator but is a different concept). So which one do you talk about? What "other iterators" do you have in $$anonymous$$d?

I guess you ment your class isn't derived from $$anonymous$$onoBehaviour and like getyour411 said, there is no Update in this case. Even when you implement a method and call it Update it has nothing to do with Unity's Update callback.

So you should sort out your question and be a bit more precise about what you want to do.

avatar image m4a44 · Apr 01, 2014 at 12:06 PM 0
Share

I call a non mono "Update" within a mono "Update". And basically, all I want to know is if there is a way to yield or delay an IEnumerator within the non mono class (because I can iterate through it, but it ignores my time yields)...

avatar image perchik · Apr 01, 2014 at 03:07 PM 0
Share

I haven't checked, but I think StartCoroutine is a UnityEngine call, not a $$anonymous$$onoBehaviour class function. Try using UnityEngine;

Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by riazrizvi · Apr 01, 2014 at 03:33 PM

Yes you can iterate over a collection of IEnumerable objects, since without Unity's MonoBehaviour class or yield instruction you can always go back to basics:

  1. Define an IEnumerator derived class that contains your list of IEnumerable objects

  2. Call it with a basic loop, eg

    foreach (EnumerablePerson p in peopleList){...}

The official docs provide a more complete sample.

Comment
Add comment · Show 1 · 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 m4a44 · Apr 02, 2014 at 03:07 AM 0
Share

I'm sorry I wasn't more specific. Updated the question...

avatar image
0

Answer by Bunny83 · Apr 01, 2014 at 06:31 PM

Yes, you can start coroutines from any method as long as the call is issues on the main thread. If a function is called from Update / Start / Awake / ... it's fine to start a coroutine there.

StartCoroutine however is a method which belongs to the MonoBehaviour class. Coroutines (which are objects, not really methods) are always run on a gameobject instance. So you have to use a reference to any MonoBehaviour instance to use StartCoroutine. Keep in mind that the coroutine will be bound to that MonoBehaviour instance. It it is destroyed the coroutine will be stopped.

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 m4a44 · Apr 02, 2014 at 03:06 AM 0
Share

Yeah, I figured as much. Are you saying that yielding (eg. WaitForSeconds) is only available when inheriting from mono?

avatar image whydoidoit · Apr 02, 2014 at 04:07 AM 1
Share

You can only yield in a function which is declared as IEnumerator - you can have that inside anything but you will have to call StartCoroutine on a $$anonymous$$onoBehaviour somewhere. So you IEnumerator can be a library or utility function but it will be bound to a GameObject so it knows when to run.

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

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

Related Questions

How to make a 3d text writeOut method? 1 Answer

Can I use StartCoroutine inside of the same coroutine with a new variable? 0 Answers

Object Not Instantiating After Being Destroyed 0 Answers

why is monodevelop not loading/opening unity 5.1.1f1 0 Answers

StartCoroutine and IEnumerator's - Multiple usage of function 0 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