Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question [Solved] What is the "correct" way of ticking systems in a fixed time (entity 0.16.0)?

Discussion in 'Entity Component System' started by Cell-i-Zenit, Oct 31, 2020.

  1. Cell-i-Zenit

    Cell-i-Zenit

    Joined:
    Mar 11, 2016
    Posts:
    288
    Hi,

    so currently i manually tick every system since i need to tick some systems every 0.1 seconds, but then i lose the "System" Window, which helps seeing how long some system takes.

    I saw that there is now a newly added systemgroup which is called FixedStepSimulationSystemGroup.

    I guess this allows me to remove my manual ticking code and use this one.

    Anyone has an idea how?
     
  2. ScriptsEngineer

    ScriptsEngineer

    Joined:
    Jun 8, 2018
    Posts:
    37
  3. Cell-i-Zenit

    Cell-i-Zenit

    Joined:
    Mar 11, 2016
    Posts:
    288
    It cant be that easy since they added the IFixedRateManager interface and somehow we are supposed to use that.

    I would prefer if unity could just give us some example code on how to use it :) Its not enough to just name 3 classes in the change log
     
    bobbaluba and ScriptsEngineer like this.
  4. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,579
    ScriptsEngineer likes this.
  5. Cell-i-Zenit

    Cell-i-Zenit

    Joined:
    Mar 11, 2016
    Posts:
    288
    CPlusSharp22 likes this.
  6. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,579
    Is not outdated. You are rushing versions. Is just 2 days old. :p
    DOTS team mentioned, they will keep features unchanged on repo, for certain number of iterations, to make sure, others with older preview are not left behind.

    But yeah, I did expect that should work too on 0.16. If does't oh well, we may wait for official repo update. If that is what we looking for.
     
    Last edited: Oct 31, 2020
  7. thebanjomatic

    thebanjomatic

    Joined:
    Nov 13, 2016
    Posts:
    36
    So I think the way this works is that you would create a ComponentSystemGroup for you 10hz update group, use UpdateInGroup to assign systems to that group, and then assign a new FixedRateUtils.FixedRateCatchUpManager(0.1f) to the FixedRateManager property on the component system group.

    Documentation is pretty sparse, but I pieced that together from the changelogs and FixedRateUtils.cs
    https://docs.unity3d.com/Packages/c...s.FixedRateUtils.FixedRateCatchUpManager.html

    FixedRateCatchUp:
    /// Configure the given ComponentSystemGroup to update at a specific fixed rate, using the provided timestep.
    /// If the interval between the current time and the last update is bigger than the timestep,
    /// the group's systems will be updated more than once.
     
    bobbaluba and Cell-i-Zenit like this.
  8. UsmanMemon

    UsmanMemon

    Joined:
    Jan 24, 2020
    Posts:
    87
    There is a test inside Packages.Entities.Tests folder named "FixedStepSimulationSystemGroupTests.cs" which should help you.
     
  9. UsmanMemon

    UsmanMemon

    Joined:
    Jan 24, 2020
    Posts:
    87
    From what I understand you have to do it like this

    First create This class
    Code (CSharp):
    1. public class CustomFixedRateManager : IFixedRateManager
    2. {
    3.     public bool ShouldGroupUpdate(ComponentSystemGroup @group)
    4.     {
    5.         if (IsTenthOfASecPassed())
    6.         {
    7.             return true;
    8.         }
    9.  
    10.         return false;
    11.     }
    12.  
    13.     public float Timestep { get; set; }
    14.  
    15.     private bool IsTenthOfASecPassed()
    16.     {
    17.         return true;
    18.     }
    19. }
    than
    Code (CSharp):
    1. var fixedStepSimulationSystemGroup = World.GetOrCreateSystem<FixedStepSimulationSystemGroup();
    2. fixedStepSimulationSystemGroup.FixedRateManager = new CustomFixedRateManager();
    Hope this helps.
     
    Cell-i-Zenit likes this.
  10. UsmanMemon

    UsmanMemon

    Joined:
    Jan 24, 2020
    Posts:
    87
    @thebanjomatic his answer is most likely the default way of doing it.
     
    Cell-i-Zenit likes this.
  11. Cell-i-Zenit

    Cell-i-Zenit

    Joined:
    Mar 11, 2016
    Posts:
    288
    Okay guys i got it down with the help of thebanjomatic thanks :)

    Code (CSharp):
    1. public class TenHzSystemGroup : ComponentSystemGroup
    2.   {
    3.     public TenHzSystemGroup ()
    4.     {
    5.       FixedRateManager = new FixedRateUtils.FixedRateCatchUpManager(0.1f);
    6.     }
    7.   }
    +

    Code (CSharp):
    1. [UpdateInGroup(typeof(TenHzSystemGroup ))]
    2.   public class TenHzSystem: SystemBase
    3. {
    4. }
    is working :)

    make sure that you use GetEXISTINGSystem or else you override something and it will just run in non fixed timesteps
     
    Last edited: Oct 31, 2020
    Sarkahn, Timboc, bobbaluba and 5 others like this.