Search Unity

how to slow down update and Frame rate of JobComponentSystem

Discussion in 'Entity Component System' started by Michelle_Ca, May 11, 2020.

  1. Michelle_Ca

    Michelle_Ca

    Joined:
    Aug 19, 2019
    Posts:
    113
    Is there a way to slow down the update in JobComponentSystem and make it update like just 3 time/Frame per second and run Entities.ForEach just three time every second ?
     
  2. MhmdAL1111

    MhmdAL1111

    Joined:
    Oct 25, 2017
    Posts:
    30
    I'm not sure if there is a way to reduce the actual update frequency but you can just do this:
    Code (CSharp):
    1.  
    2.     int updatesPerSecond = 3;
    3.     float timeSinceLastUpdate = 0;
    4.     protected override void OnUpdate()
    5.     {
    6.         timeSinceLastUpdate += Time.DeltaTime;
    7.  
    8.         if(timeSinceLastUpdate >= 1f / updatesPerSecond)
    9.         {
    10.             timeSinceLastUpdate = 0;
    11.  
    12.             //Entities.ForEach....
    13.         }
    14.     }
     
    Michelle_Ca and Deleted User like this.
  3. Deleted User

    Deleted User

    Guest

    Pay attention that the solution above will lose accuracy with time.
     
    Michelle_Ca and MhmdAL1111 like this.
  4. Bivens32

    Bivens32

    Joined:
    Jul 8, 2013
    Posts:
    36
    Just curious, why/how does it lose accuracy over time?
     
  5. vildauget

    vildauget

    Joined:
    Mar 10, 2014
    Posts:
    121
    Possible workaround, disabling onupdate, and kick update from monobehavior,

     
    nicolasgramlich and Michelle_Ca like this.
  6. Opeth001

    Opeth001

    Joined:
    Jan 28, 2017
    Posts:
    1,117
    I think the most efficient way for the moment is using
    Code (CSharp):
    1. FixedRateUtils.EnableFixedRateWithCatchUp(_simulationGroup, timesInSecond);
    More details here.
     
    Last edited: May 11, 2020
  7. Deleted User

    Deleted User

    Guest

  8. Bivens32

    Bivens32

    Joined:
    Jul 8, 2013
    Posts:
    36
  9. Deleted User

    Deleted User

    Guest

    I think it should be okay yea, I thought there was an endless accumulation of timeSinceLastUpdate but it gets reset to 0. Technically should be okay but I still doubt stability on different platforms. Stopwatch might do the trick or https://github.com/ashoulson/RailgunNet/blob/master/RailgunNet/RailClock.cs