Search Unity

Feedback Feature Request: Time.FixedUpdateCount or something similar

Discussion in 'Physics' started by Aristonaut, Aug 12, 2019.

  1. Aristonaut

    Aristonaut

    Joined:
    May 4, 2019
    Posts:
    15
    Currently we have access to a Time.FrameCount to get the total number of frames that have passed. It would be nice to have a similar Time.FixedCount or Time.PhysicsCount or something that would give you the number of fixed updates or physics steps that have passed. This would be very useful for creating self-updating properties on an object that get blindly gotten from anywhere. Something like:


    Code (CSharp):
    1. private int frictionUpdated;
    2. private Vector2 friction;
    3. public Vector2 Friction   //<== used blindly in many external places
    4. {
    5.   get
    6.   {
    7.     if (frictionUpdated == Time.fixedCount) friction;
    8.     frictionUpdated = Time.fixedCount;
    9.     return friction = /*some long calculations*/
    10.   }
    11. }
    You can do this kind of buffering with Time.frameCount, but not physics.

    Currently I am stuck lazy-buffering things in a more laborious way. It would be nice to simplify some of it with this easily-added feature.
     
  2. Aristonaut

    Aristonaut

    Joined:
    May 4, 2019
    Posts:
    15
    The hardest part of this feature would be the name, so if anyone has suggestions, that would be nice.
     
  3. SparrowGS

    SparrowGS

    Joined:
    Apr 6, 2017
    Posts:
    2,536
    If given a steady fixed delta time, couldn't you derive it from something like (timeSinceStartUp * fixedDeltaTime)?

    But yeah sure, if they can add it why not.
    shouldn't be too hard to name, .FrameCount and .PhysicsFrameCount or .FixedFrameCount .
     
  4. Grizmu

    Grizmu

    Joined:
    Aug 27, 2013
    Posts:
    131
    Fair enough. If normal updates are counted I don't see a reason not to count FixedUpdates as well.
     
  5. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    2,073
    Would be useful, I have simulated it by setting execution order on my special component and than count the FixedUpdate by myself. But it gives this "hackish" feeling.