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 vmc_petter · May 20, 2021 at 10:04 AM · timemonobehaviourfixedupdatetime.deltatimetime.time

Get actual Time.deltaTime from FixedUpdate()

Hi!

I know that reading Time.deltaTime and Time.time from FixedUpdate() does return the values for fixedDeltaTime and fixedTime instead of the actual ones, but I would like to read the actual deltaTime and time. I need to do it as early as possible during the frame, which by my knowledge is FixedUpdate().

  1. Is there some other way to read the actual deltaTime and time from FixedUpdate()?

  2. Is there some other per-frame event that executes before FixedUpdate() from which I can read the actual deltaTime and time? I wish there was an EarlyUpdate event in which we could do per-frame preprocessing stuff.

The reason why I want to do this is because I need to predict the number of times FixedUpdate() will be called per frame, in order to do some interpolation of physics related network data over the FixedUpdate calls.

Comment
Add comment · Show 6
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 Llama_w_2Ls · May 20, 2021 at 10:49 AM 0
Share

Where did you hear that

reading Time.deltaTime and Time.time from FixedUpdate() does return the values for fixedDeltaTime and fixedTime instead of the actual ones


I think it still does return the time it takes for a frame to complete and not fixedDeltaTime, or else that would defeat the point of having a separate property. Also, how would it know it's being accessed from within a specific function?

avatar image vmc_petter Llama_w_2Ls · May 20, 2021 at 11:21 AM 1
Share

From the documentation, and confirmed through testing:

When this is called from inside MonoBehaviour.FixedUpdate, it returns Time.fixedDeltaTime.

https://docs.unity3d.com/ScriptReference/Time-deltaTime.html

I agree that it somewhat defeats the purpose with the separate properties.

avatar image Magso · May 20, 2021 at 11:39 AM 1
Share

You could do Time.deltaTime / Time.fixedDeltaTime in Update. Also they are both 'actual ones' because Update is called every frame and FixedUpdate is called every physics frame, delta time is the amount of time elapsed since the last frame.

avatar image vmc_petter Magso · May 20, 2021 at 12:00 PM 0
Share

Unfortunately the thing I need it for cannot wait until Update(). Need to access it earlier, either before or during the first FixedUpdate() of the frame.

Yes, but I would say that the "actual", or "main", meaning of the property Time.deltaTime is the elapsed time since last frame, as the documentation says, and the fact that it returns fixedDeltaTime during FixedUpdate() is just a special case, even though there already is a separate property called Time.fixedDeltaTime for that.

I guess they could introduce a "Time.elapsedSinceLastFrame" property for this that isn't context dependent.

avatar image Earthshine vmc_petter · May 20, 2021 at 12:47 PM 1
Share

Can you use Time.deltaTime from Update in previous frame instead?

I believe you're familiar with the order of execution for event functions and it doesn't look like Unity can access Time.deltaTime for the frame from FixedUpdate due to this exact frame is not yet rendered.

FixedUpdate is often called more frequently than Update. It can be called multiple times per frame, if the frame rate is low and it may not be called between frames at all if the frame rate is high.

Show more comments

0 Replies

· Add your reply
  • Sort: 

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

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

Related Questions

Slow update best practice 0 Answers

difference with Time.time, Time.deltatime, Time.frameCount 3 Answers

Can I use Stopwatch without syncing time across network. 0 Answers

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

It is not updated per second 0 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