Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
1
Question by Makiavel · Feb 15, 2021 at 08:28 PM · timetimescaleyield waitforseconds

WaitForSecondsRealtime issue during timescale change

I am trying to slow down the game temporary when my player picks up a buff item. I am doing it by starting the following Coroutine on collision:

 public IEnumerator SlowMo () {
             Time.timeScale = StaticVariables.Buff_SlowMo_Speed;
             Overlay_SlowDown.SetActive(true);
             Time.fixedDeltaTime = StaticVariables.fixedDeltaTime * Time.timeScale;
             yield return new WaitForSecondsRealtime (StaticVariables.Buff_SlowMo_Duration);
             Time.timeScale = 1;
             Time.fixedDeltaTime = StaticVariables.fixedDeltaTime * Time.timeScale;
             Overlay_SlowDown.SetActive(false);
         }

StaticVariables holds

 public static float Buff_SlowMo_Speed =  0.5f; 
 public static float Buff_SlowMo_Duration = 1;

The problem is, nothing after the yield function is triggered, and I have no idea why. Timescale does not return to normal and the overlay game object does not get disabled. I am using the timescale manipulation code from the unity examples. I honestly have almost no experience with the timescale manipulation and would be very grateful if someone pointed out the (probably quite dumb) mistake I am making.

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 Makiavel · Feb 16, 2021 at 10:52 AM 0
Share

Ok, kept testing, not only WaitForSecondsRealitme not working, WaitForSeconds isn't working either, and the Timescale manipulation isn't working either... No idea what the hell is going on. Will comment when I find out, maybe it helps someone .

1 Reply

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

Answer by Makiavel · Feb 16, 2021 at 11:07 AM

Ok, I am an idiot (duh). I forgot the difference between the Coroutines and Functions. If you call a function on another game object, you can destroy the object that called it as long as you don't need anything from it and the function does not return anything. Coroutines... , I completely forgot the object that called coroutines has to be present for the entire duration of it for the coroutine to finish. My object that called coroutine got destroyed after the collision and so the coroutine started and didn't finish. I simply moved the coroutine call into the object that isn't destroyed and instead of calling the coroutine directly, I call a simple function that calls the coroutine.

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 Bunny83 · Feb 16, 2021 at 11:15 AM 0
Share

I glanced over your question yesterday and was about tp point out the common reasons why a coroutine may stop executing, one more time, though I didn't have any time. Great you figured it out yourself.

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

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

Related Questions

How to to do a progress bar wich scale down in 6 seconds ? (timeScale used) 0 Answers

How slow motion everything except animation 1 Answer

Is there a way to speed up the game more than 100 times? 1 Answer

2nd independent deltaTime and timeScale variables, or a way to mimic this? 1 Answer

AudioSources don't play when setting Time.timescale to 0 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