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
1
Question by Nanako · Dec 03, 2014 at 09:40 PM · startframeget-time

What's the best way to get the total time since the start of the current frame?

As title. basically i want to know how much time has passed since this frame started processing, while we are still in this frame.

Comment
Add comment · Show 2
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 Eck · Dec 03, 2014 at 09:57 PM 2
Share

After a quick look through the documentation it looks like using Time.realtimeSinceStartup is your best bet combined with Time.time (which is the timestamp at the start of this frame).

http://docs.unity3d.com/ScriptReference/Time-realtimeSinceStartup.html

avatar image Nanako · Dec 06, 2014 at 07:54 AM 0
Share

something is very wrong here.

 public static float CurrentFrameTime()
     {
         return Time.realtimeSinceStartup - Time.time;
     }

This consistently returns a value of approximately 0.34 seconds when i'm calling it. If that were true my game would be running at a snail pace, and yet i'm running at a pretty smooth 50 fps

1 Reply

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

Answer by Kiwasi · Dec 06, 2014 at 10:24 AM

Real time could be used by storing the value of realtime at the beginning of the frame. The subtract it from realtime when you need to check it.

A StopWatch would also work. Manipulate your script execution order so it starts at the beginning of each frame. Then you can check it while you are running.

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 Eric5h5 · Dec 06, 2014 at 06:39 PM 1
Share

Time.realtimeSinceStartup definitely changes during a frame. It changes from one line of code to the next, depending on how long it took to execute the instructions for that code.

avatar image Kiwasi · Dec 06, 2014 at 06:42 PM 0
Share

Will edit my answer then. Thanks.

avatar image Nanako · Dec 06, 2014 at 07:44 PM 0
Share

if that's so, any idea why my example code didn't do the trick?

In any case i'm using a stopwatch now, and it works well. but still..

avatar image Bunny83 · Dec 06, 2014 at 09:19 PM 0
Share

@Nanako: Time.time runs completely independent from realtimeSinceStartup. Time.time is increased "manually" each frame and is affected by the timescale. realtimeSinceStartup is basically your system time ($$anonymous$$us the start offset). It can update within a frame or not at all between two or more frames depending on the underlying system timer and your framerate.

Using a stopwatch is the best approach i think. You could use a seperate script which you place at the top of your execution order to ensure it's called first. If this script you would Reset and Start your Stopwatch. In any other script you then can read the passed time.

Time.realtimeSinceStertup can be used ins$$anonymous$$d of the stopwatch, however since it's a float value the larger the value gets over time the more you lose precision. Since you're interested in sub-frame-times a Stopwatch is way better in this case.

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

27 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

Related Questions

Initialising List array for use in a custom Editor 1 Answer

SendMessage is running before Start 1 Answer

unity doesnt start after registering 2 Answers

Help from start 3 Answers

How do I start game paused 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