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 DaJuice · Sep 24, 2012 at 02:00 PM · coroutineoptimizationupdate

Optimization: Central "update" system vs using Updates

I have searched on the internetz and found nothing about a system that would use a coroutine to update each frame, then in this coroutine, I'd run through a List of objects that contains all the Actions.

According to most people, using coroutine is more efficient than using Update, what if I use only one coroutine and iterate through a List each tick of the coroutine?

I'm not used to C#/Unity, let alone optimization, so I don't know if it a good way to go.

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
0

Answer by whydoidoit · Sep 24, 2012 at 02:43 PM

A coroutine used like that is not more efficient that an Update because it would always run every frame. Further - having a single "Update" call does not tie together the lifetimes of your objects - so you could still be calling the action on an object that had been destroyed unless you also add that management to your central routine. In the end it would probably be better to just use Update or coroutines on the objects in question.

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 DaJuice · Sep 24, 2012 at 03:29 PM 0
Share

Hey man! You are everywhere! Handling would be done, automatically too, don't worry ;)(the handling would be done by a component in the GameObject from which everything about updates will be called, but it will just be some kind of bridge between my central iterator and my behaviours, this component will be the core of my "pausing system" anyway, so I don't think it'll be much heavier to add this update control to it.)

I'm taking notes here... So when a coroutine is called every frame and it is in a $$anonymous$$onoBehaviour (or something that already has the working Update method), it is not more efficient.

$$anonymous$$y game will need my characters to have several "Updates" and rather than having a switch to lead to the good method inside my main Update or anything like this, I'd prefer to skip this and have the good update method called directly.

Now, is centralizing all the actions less efficient than starting a coroutine for each object that needs an update? Or maybe I should just stick to the normal Update method as my solution seems too heavy on memory and/or cpu?

avatar image whydoidoit · Sep 24, 2012 at 03:40 PM 0
Share

Yeah coroutines are really just like Update calls apart from you get the wait instructions - which are surely actually doing some checking in an optimal way (there is no "magic" support for coroutines - they are just enumerators that Unity decides when to execute the next step of). It's more optimal to put yield return new WaitForSeconds(3) than it is to fiddle with the time variables and the ifs necessary to get that to work in an Update function (which would get messy quick and would be sub optimal).

So a coroutine that looks like this:

    IEnumerator $$anonymous$$yCoRoutine()
    {
         while(true)
         {
              //Do somthing
              yield null;
         }
    }

Is like an Update routine - it's nice because you can have more than one - but it isn't per se more efficient.

avatar image whydoidoit · Sep 24, 2012 at 03:49 PM 0
Share

I guess every coroutine you start has a little overhead, as would any iteration of a loop and a check to see if it was valid. Not sure on how much - but it seems pretty efficient to me - I have a lot (dozens) of things that I start "secondary" Update functions for.

avatar image DaJuice · Sep 24, 2012 at 04:03 PM 0
Share

Thanks alot! It is good to see you care :)

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

10 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

Related Questions

convert timer from update() to coroutine or invokerepeating 0 Answers

Update() cannot be a coroutine 1 Answer

Coroutine is not called between frames 2 Answers

Reading input outside of Update or some other ticking system 2 Answers

Update () cant be a coroutine 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