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 BjornVTI · Oct 30, 2012 at 11:51 AM · yieldwaitforsecondsstuck

WaitForSeconds get stuck after update of Unity Pro

After I updated to Unity Pro 3.5.6f4 my (previously working) script stopped working:

 IEnumerator Start () {
     // More code here...
     Screen.SetResolution(1920, 1080, true, 0);
     
     Debug.Log("Begin yield");
     Debug.Log(Time.timeScale);
         
     // Wait for new screen resolution to take effect
     yield return new WaitForSeconds(1.0f);
     Debug.Log("Done yielding");
     
     // More code here...
 }

The output from the above log is:

 Begin yield
  
 1

So I can not get past the yield statement. I have tried to remove and reapply the script. I have also tried to do "Reimport all" on my project. All without success. Any ideas??

Comment
Add comment · Show 9
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 whydoidoit · Oct 30, 2012 at 11:52 AM 0
Share

Hmmm, are you sure you aren't disabling or destroying the object? I've not seen any problems with the latest release so I would imagine it is something in your code.

avatar image BjornVTI · Oct 30, 2012 at 11:57 AM 0
Share

Well the script is connected to the camera and I am pretty sure that is not deleted nor disabled.

This guy had a similar problem but his time-scale was set to zero (but my time-scale is one): http://answers.unity3d.com/questions/60725/waitforseconds-problem-with-unity-pro.html

avatar image whydoidoit · Oct 30, 2012 at 12:00 PM 0
Share

So if you look at this script in the inspector then it's game object is checked active and so is it's particular script?

avatar image BjornVTI · Oct 30, 2012 at 12:12 PM 0
Share

Yes, both the game object (camera) and the script are active.

avatar image whydoidoit · Oct 30, 2012 at 12:16 PM 0
Share

How strange. Hmmm, well with a valid timeScale and an active object - I've not seen that behaviour and I pretty much use this technique in Start all the time. If you can easily replicate then you should report it as a bug.

$$anonymous$$ight be worth adding a Debug.Log in an OnDisable method just to prove the point.

Show more comments

2 Replies

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

Answer by BjornVTI · Oct 30, 2012 at 04:29 PM

The answer in this case was that another script set the Time.timeScale to zero. This was not visible outside the yield statement. But was clearly visible by running:

 float delay = 1.0f;
 print ("Start Time:\t" + Time.time);
 print ("Time scale:\t" + Time.timeScale);
 float done = Time.time + delay;
             
 while(Time.time < done) { 
     print ("Time:\t"+ Time.time + "\tRealtime:\t" + Time.realtimeSinceStartup + "\tTimeScale:\t" + Time.timeScale);
     yield return 0;
 }

Which gave me the following output:

 Start Time:    0
 Time scale:    1

 Time:    0    Realtime:    0.15797        TimeScale:    1
 Time:    0    Realtime:    0.8051        TimeScale:    0
 Time:    0    Realtime:    1.154805    TimeScale:    0
 Time:    0    Realtime:    1.188964    TimeScale:    0
 Time:    0    Realtime:    1.19767        TimeScale:    0

Which made the real problem visible (ie. the time scale gets set to zero)

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

Answer by BjornVTI · Oct 30, 2012 at 01:50 PM

After an idea from: http://answers.unity3d.com/questions/14785/waitforseconds-vs-yield-every-frame.html

I tried to replace the waitforseconds instruction with the following instead

 float delay = 1.0f;
 print ("Start Time:\t" + Time.time);
 print ("Delay:\t" + delay);
 print ("Time scale:\t" + Time.timeScale);
 float done = Time.time + delay;
 
 while(Time.time < done) { 
     print ("Time:\t"+ Time.time + "\tRealtime:\t" + Time.realtimeSinceStartup);
     yield return 0;
 }

But this gives me the following output:

 Start Time:    0
 Delay:    1
 Time scale:    1
 Time:    0    Realtime:    0.1746936
 Time:    0    Realtime:    0.8073034
 Time:    0    Realtime:    0.9108546
 Time:    0    Realtime:    1.17599
 Time:    0    Realtime:    1.183453
 Time:    0    Realtime:    1.199383
 Time:    0    Realtime:    1.207282
 Time:    0    Realtime:    1.218535

So for some reason the time is standing still.

Comment
Add comment · Show 3 · 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 whydoidoit · Oct 30, 2012 at 01:51 PM 0
Share

Add a print of Time.timeScale inside the while loop too - just to make sure something isn't setting it to 0.

avatar image BjornVTI · Oct 30, 2012 at 02:14 PM 0
Share

As you suspected, Time.timeScale is zero inside the loop. Good catch, now I have something to work with!

avatar image BjornVTI · Oct 30, 2012 at 02:21 PM 0
Share

Well, I found it. Someone on our $$anonymous$$m had made some changes inside another script, and that change set the timeScale to 0.

Thank you whydoidoit for helping me solve this!

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

no "pointers" to get directly to a variable passed to a function? 1 Answer

Getting an error when trying to yield 2 Answers

is there any function call will be call after i activate an object ? 1 Answer

Yield Not Working - While Loop 3 Answers

Why does Yield WaitForSeconds () only run once 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