• 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 BaterieCZ · Dec 20, 2017 at 10:23 PM · fpstimetime.timeticks

How to measure time independently on frame rate?

I am recieving data every server tick (25 ticks per second) and I need to count ticks per second on client. I am using Time.time for measuring those ticks (I tested even Time.fixedTime) and when I have Vsync turned on I see 26t/s, when half vsync I see 27t/s.

I know that Time.time ansd Time.fixedTime is counted by number of screen refreshes, but I need to count ticks independtly on screen refresh rate? Is there something like microtime() in PHP? I need time what is independent on screen to properly calculate ticks per second.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Buckslice · Dec 20, 2017 at 11:24 PM

I think the built in Stopwatch class will work for you.

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 BaterieCZ · Dec 21, 2017 at 11:29 AM 0
Share

Hi, Sorry this not working. I tested Stopwatch and System.DateTime but still getting same results depended on Vsync or framerate. I dont know why.

avatar image
1

Answer by Xarbrough · Dec 21, 2017 at 01:17 AM

Time.time and Time.fixedTime are not "counted by screen refreshes", they are just not very accurate overall. You can also use link text to not scale it by timeScale etc. However, again, not very accurate. Most likely this function calls something similar to System.DateTime.Now from the .NET framework. The later you can also try if you just want a time that is exact for around one second.

For precise measurements, the Stopwatch class, as mentioned by Buckslice, is better, but then again, it's never going precise enough to sync specific timing to one another, but if you are only displaying some "x per second" data it should work fine.

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 BaterieCZ · Dec 21, 2017 at 11:30 AM 0
Share

Stopwatch and System.DateTime not working too... When I have vsync, I am getting 27t/s and when turned off its ok with 25t/s Still depends on framerate then...

avatar image Xarbrough BaterieCZ · Dec 21, 2017 at 12:05 PM 0
Share

Are you starting and stopping your time measurement in Update? I see the problem, you can't call Time.time from a different thread, but the Stopwatch and DateTime classes should be thread-safe. In that case I would try running my own timer-thread or even use a threaded timer from the .NET framework. If you can post a simple code example, I could make one, too. ;)

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

101 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

Related Questions

Help with time.time when new scene starts. 1 Answer

It is not updated per second 0 Answers

Lerping takes 10 x longer than it should 1 Answer

Lerp returning max value halfway 1 Answer

Time based scoring 2 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