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 sopesope · Apr 10, 2014 at 06:03 AM · yieldcoroutinesienumeratorloops

Yield return inside a loop slowdown problem

During Update (and using flags to call it whenever I do certain button presses) I call the FlipDiDoo coroutine to rotate a group of gameobjects. IEnumerator FlipDiDoo() { float anguloDeseado = 0.0f;

                 for (float iter = 0.0f; iter < 180; iter += 1.0f){
 
             yield return StartCoroutine (Wait (1.0f));
 
             foreach (GameObject hoja in hojas) {
                 hoja.transform.RotateAround (transform.position, ejeRot, -1);
 
             }
             //Debug.Log (iter);
         }
 
         foreach (GameObject folha in hojas) {
             folha.transform.eulerAngles = new Vector3 (Mathf.Round (folha.transform.eulerAngles.x), Mathf.Round (folha.transform.eulerAngles.y), Mathf.Round (folha.transform.eulerAngles.z));
         }
         control.GetComponent<CameraZoomPinch>().isFlipping = false;
         
     }
 
     IEnumerator Wait(float duration){
 
         for (float timer = 0; timer < duration; timer += Time.deltaTime){
             yield return 0;
             Debug.Log("TIMER " + timer);
         }
     }

I need it to do a smooth 180º rotation, which it does… until I lower the value I pass into the Wait coroutine. If it's 0.01f it should rotate one degree every 0.01 seconds, totalling 1.8 seconds for the full 180º rotation, right? Except it doesn't, it slows down horribly, totalling somewhere between 10 -15 seconds. I even tried:

  • Removing the foreach to see if that was where the delay came from, which didn't remove the delay.

  • Changing the Wait value to 0.0f, to no avail.

  • Taking away the yield call to the Wait subroutine, which eliminated the smoothness altogether.

  • Using a yield return call instead, which also caused slowdown.

  • Changing the for loop to a while/adding value inside the loop, with the same slowdown result.

So, I'm guessing it has something to do with calling a yield inside a loop but I just can't find exactly what I'm missing. This is usually a good place (I haven't needed to ask something here EVER, which says a lot about it's usefulness) to troubleshoot but this is really cracking my head. Any other info you need, I'll be glad to provide. Thanks in advance.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Patel-Sagar · Apr 10, 2014 at 06:08 AM

You should try mathf.lerp. it will give you smoothness, guarantee to reach 180 in your time and also device FPS independence.

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 sopesope · Apr 10, 2014 at 03:15 PM 0
Share

I'll look into it, modify my code accordingly and get back to you via this thread with any questions if you don't $$anonymous$$d. Thanks!

avatar image
0

Answer by sopesope · Apr 11, 2014 at 12:07 AM

I ended up doing a variation on this solution, which works just fine and does exactly what I was aiming for: http://answers.unity3d.com/questions/29110/easing-a-rotation-of-rotate-around.html

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

22 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

Related Questions

How to use Coroutines in C++/CLI? 1 Answer

Having trouble using coroutines, making unity hang 0 Answers

Coroutines not passing yield 1 Answer

WaitUntil doesn't work and the coroutine starts anyways 1 Answer

Mysteries of yield 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