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
8
Question by GutoThomas · Jun 29, 2012 at 01:35 AM · coroutineienumeratortime.timescale

Does coroutines are affected by Time.timeScale?

When I create an IEnumerator like this one:

 IEnumerator Example () {
 
 yield return new WaitForSeconds(20);
 //do something
 
 }

Let's say that in another script I set Time.timeScale = 0 for some time. When I do this, the coroutine continue running to complete the 20 seconds or it pauses while timeScale is equals to 0?

Comment
Add comment · Show 1
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 Blind56 · Aug 22, 2016 at 02:46 PM 0
Share

dat question structure tho

2 Replies

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

Answer by aldonaletto · Jun 29, 2012 at 02:08 AM

Setting timeScale to 0 doesn't stop coroutines, but stops WaitForSeconds. Coroutines continue executing each frame, but WaitForSeconds apparently uses the current Time.deltaTime, which becomes zero when timeScale = 0.
The simple test below shows this:

 function TestCoroutine(){
   for (var n=0; n < 5; n++){ // count 5 frames...
     print("frame "+n); 
     yield;
   }
   print("start delay 5 s");
   yield WaitForSeconds(5); 
   print("delay ended");
 }
 
 var pause = false;
 
 function Update () {
   if (Input.GetKeyDown("escape")){
     pause = !pause;
     if (pause){
       Time.timeScale = 0;
       TestCoroutine();
     } else {
       Time.timeScale = 1;
     }
   }
 }

When Escape is pressed, timeScale is set to 0 and TestCoroutine is started - the 5 frames are counted and WaitForSeconds(5) is started, but the 5 seconds wait time lasts forever until you press Escape again to return timeScale to 1.

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 GutoThomas · Jun 29, 2012 at 03:04 AM 0
Share

That's really handy for my case! Thank you! :)

avatar image IzzySoft · Jun 18, 2015 at 02:16 AM 2
Share

Did you try something akin to this:

     public static IEnumerator WaitForRealSeconds( float delay )
     {
         float start = Time.realtimeSinceStartup;
         while( Time.realtimeSinceStartup < start + delay && cancelShowngTooltip == false )
         {
             yield return null;
         }
     }
     
     private IEnumerator ShowTooltipAfterDelay( float delay )
     {
         yield return StartCoroutine( WaitForRealSeconds( delay ) );
         
         if( cancelShowngTooltip == false )
             Debug.Log( "Show Tooltip now." );
     }
avatar image
2

Answer by $$anonymous$$ · Jun 11, 2018 at 03:17 PM

Yes, it affects and it's effect is normal when you keep that game objects which contains coroutine ON, While it is on every thing works fine. If you TURN OFF the game object then every thing going to be mess.

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How can you tell if a gameobject is looking directly at another gameobject? 1 Answer

WaitForSeconds Not Working 4 Answers

Problem with coroutine 2 Answers

How Return Or Restart A Coroutine When A Variable Increase? 0 Answers

Ienumerator wait for event 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