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 aorata · Feb 16, 2013 at 06:36 PM · yieldcoroutinesdevicedevices

Optimizing coroutines?

I have a bit of a problem.

I am trying to make this happen:

Have 100 slots in a circle and have another object move from slot to slot at a very high speed. (speed, or time in each slot varies through the game). If the object is in slot 45, it will wait a little moment (yield) and then move to 46, then 47, etc.

I have done this already, with a coroutine that checks the position of the object and sends it to the next position. However, when the times get really small (time interval between moving form slot a to slot b), the REAL speed at which the object moves (the speed you as a user see on the device) varies from device to device. For example, I ran this program on my computer and it took x secs to go through all the slots, however, on an android device, it took x/2 to move through all the slots...

I need it to be exactly the same on all devices. Any help will be much appreciated!

Thanks in advance!

ps: help can be, optimizing tips, or just other ways of doing the same thing. Thanks!

Comment
Add comment · Show 2
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 · Feb 17, 2013 at 02:38 AM 0
Share

Can't you just include the coroutine? Or at least the important parts. "yield" could be used to yield for very different things. What do you yield? null? WaitForSeconds? ...

avatar image aorata · Feb 17, 2013 at 09:22 PM 0
Share

yield WaitForSeconds

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Bunny83 · Feb 17, 2013 at 02:44 AM

The easiest way in a coroutine to get the behaviour you want is to yield until the next FixedUpdate with WaitForFixedUpdate. This will ensure that the behaviour is the same on all platforms. The only exception is when you're FPS drops below the maximum allowed timestep. In this case you should try some performance optimizations.

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 aorata · Feb 17, 2013 at 09:23 PM 0
Share

Thanks Bunny83, I didn't know this, I'll give it a try. Thanks!

avatar image
0

Answer by Alan47 · Feb 17, 2013 at 02:36 AM

I don't know about your entire setup and the environment your script is supposed to work in, but do you have to use a coroutine for this task? If there is something time-critical that should work the same on all devices, regardless of computational power, you should generally try to use either the "Update()" method and utilize Time.deltaTime or Time.smoothDeltaTime to calculate the position or use "FixedUpdate()". You can then also realize a "wait for object to be in slot X" like behaviour using coroutines like in this fragment:

 while(/* insert object location condition here */){
    yield Wait(1);
 }
 yield return;

If you choose to do this, please be aware that this is quite CPU intensive, especially if you have multiple copies of such coroutines going on at the same time. I used to work with coroutines extensively in the past, but I finally realized that the best way to use the Unity coroutines most often is to not use them at all.

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

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

yield, Coroutines, InvokeRepeating... 1 Answer

Are coroutines freezing my game? 0 Answers

How do I properly use Coroutines, yield and animators to sequence commands ? 2 Answers

Inconsistent StopCoroutine behavior with CustomYieldInstruction 1 Answer

Problem with Stopping Nested Coroutines: Control Never Returned to Parent 3 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