Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
4
Question by DtBeloBrown · Mar 09, 2010 at 11:55 PM · bugtimedeltatimeinitialization

Time.deltaTime not set to 0 if Time.timeScale set to 0 too early!

Can someone confirm this bug exists or suggest where to look for my mistake?

Notice that the problem also happens if you try to set timeScale to 0 in Awake(). (which in this case would be the sensible place to put it.)

void Update() { //if(Time.frameCount < 2) //deltaTime becomes 0.02, not zero. //same problem if put in Awake();

     if(Time.frameCount == 2)     //works as expected.
         Pause();
     if(Input.GetKeyDown(KeyCode.Space))
         Pause();
     else if (Input.GetKeyUp(KeyCode.Space))
         Play();
     Debug.Log("Delta"+Time.deltaTime);
 }

 void Pause () {
     Time.timeScale = 0;
     AudioListener.pause = true;
 }
 void Play () {
     Time.timeScale = 1;
     AudioListener.pause = false;
 }

}

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

4 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by Jaap Kreijkamp · Mar 10, 2010 at 03:25 AM

Time.deltaTime is the time between previous and the current frame, so setting the timeScale within an Update doesn't change the value for deltaTime for the Updates called in the current frame.

Comment
Add comment · Show 4 · 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 DtBeloBrown · Mar 10, 2010 at 03:40 PM 0
Share

While this is true, in subsequent calls to Update many frames later, deltaTime should be 0 and I still see it as a s$$anonymous$$dy 0.02 indefinitely (until timeScale is changed again some time after frame count is >= 2). Let me know if you do run it and get similar results.

avatar image Jaap Kreijkamp · Mar 11, 2010 at 03:40 AM 0
Share

So if I understan it correctly, it works well after frame 2 (deltaTime == 0) but wrong before frame 2 (deltaTime == 0.02)? Apparently Unity's code does force Time.timeScale to 1 in first frame or so. As I've used timeScale == 0 without problems I would suspect it only occurs on first frames after startup, a cheap hack around would be having an startup scene, that waits 2 frames and then loads the real stuff.

avatar image DtBeloBrown · Mar 26, 2010 at 03:10 PM 0
Share

That is correct. I just ended up waiting for the two frames and starting my scene with no sounds to prevent any audio noises in those first frames.

avatar image Socapex · Jan 05, 2011 at 02:16 AM 0
Share

If it is correct, mark your question as answered (by this answer).

avatar image
2

Answer by Gareth Rees · Jun 12, 2010 at 08:21 PM

I've seen this bug too (Unity 2.6.1f3): if I set Time.timeScale in an Awake() call before the first frame, or in an Update() call in the first frame, then Time.deltaTime is not properly adjusted. (Animations do stop, though: I guess they interrogate Time.timeScale directly).

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 DtBeloBrown · Jun 14, 2010 at 11:42 PM 0
Share

Thanks for confir$$anonymous$$g that.

avatar image starkos · May 15, 2012 at 03:04 PM 0
Share

This is still the case in Unity 3.5.1

avatar image
0

Answer by arioch82 · Dec 01, 2010 at 11:47 AM

I've bumped into this too... setting Time.timeScale=0.0f in an Awake in the first scene won't change the deltaTime (always 0.02f). this is really annoying...

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 starkos · May 15, 2012 at 03:13 PM

Here's a way to work around it:

 function Awake() {
    StartCoroutine("Pause");
 }
 
 function Pause() {
    yield WaitForEndOfFrame();
    Time.timeScale = 0.0f;
 }
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

1 Person is following this question.

avatar image

Related Questions

Execute code every x seconds with Update() 4 Answers

speed change in standalone compared to editor? 1 Answer

I can't get framerate independence to work... 1 Answer

Different behavior between editor and standalone changing time step 0 Answers

Lots of !IsFinite() Errors and FPS crawling to a halt - How to debug? 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