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
2
Question by James Simpson · May 13, 2010 at 03:33 AM · javascriptupdatetimedeltatime

Time.deltaTime not consistent over time

I am trying to do network time synchronization across clients, but I noticed some weird behavior and setup a simple project to test Time.deltaTime as it counted up. All I do is have a variable in the project that starts at 0 and holds the milliseconds since the program started. I display this on the screen and then open the program in 2 separate windows. I then compare the difference in the time displayed, and instead of the difference staying constant, it fluctuates quite substantially.

float counter = 0.0f;

void Update() { counter += Time.deltaTime * 1000; }

Unless I am understanding this incorrectly, no matter the framerate or when the players were opened, the difference between the value for counter should remain constant. Am I approaching this incorrectly, or is this a possible bug?

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

1 Reply

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

Answer by duck · May 13, 2010 at 07:17 AM

Yes, accumulating deltaTime into your own variable will always be less accurate than measuring Time.time directly.

Simply use Time.time instead of your counter variable and you should get much better results.

Comment
Add comment · Show 6 · 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 James Simpson · May 13, 2010 at 03:01 PM 0
Share

This won't work for my needs though, because I want a rolling counter to where it maxes out at 9999 ms and then starts back at 0. I simplified the code for the purpose of this. Is there no way to do that accurately?

avatar image duck ♦♦ · May 13, 2010 at 03:23 PM 1
Share

Yes there is. Use: $$anonymous$$athf.Repeat( Time.time, 10000 );

avatar image duck ♦♦ · May 16, 2010 at 02:07 PM 0
Share

did this solve your problem? (if so remember to vote up & accept the answer).

avatar image James Simpson · May 17, 2010 at 06:08 PM 0
Share

Sorry, I was moving out of my apartment for the past couple days and hadn't had a chance to test it out. Works like a charm though, thanks!

avatar image martinasenovdev · Sep 05, 2017 at 08:14 PM 0
Share

why is that? can you provide some sources for this claim? accumulating deltaTime should not be any more different than getting Time.time

avatar image shieldgenerator7 martinasenovdev · Sep 23, 2018 at 05:16 PM 0
Share

Floating point error. Adding floats together isn't always accurate. For example, 2.0 + 2.0 = 3.999999 ins$$anonymous$$d of 4. Floats are weird.

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

2 People are following this question.

avatar image avatar image

Related Questions

Execute code every x seconds with Update() 4 Answers

Single Step (pause, resume), or externally clock game loop 0 Answers

Updating an array indices dynamically 2 Answers

Add 1 Per Second to an Int 1 Answer

Constant Yield Time 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