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

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?

Add in you system [UpdateInGroup(typeof(FixedStepSimulationSystemGroup)]

“[UpdateInGroup] — specifies a ComponentSystemGroup that this system should be a member of. If this attribute is omitted, the system is automatically added to the default World’s SimulationSystemGroup (see below)”
source - System Update Order | Entities | 0.16.0-preview.21

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 :slight_smile: Its not enough to just name 3 classes in the change log

2 Likes

https://github.com/Unity-Technologies/EntityComponentSystemSamples/tree/ec16fed3eda2457234c56450b660edb584254e7d/ECSSamples/Assets/Advanced/FixedTimestepSystemUpdate

1 Like

I already looked into this repo, but there wasnt an update to 0.16, so posting an outdated repo here doesnt really help

1 Like

Is not outdated. You are rushing versions. Is just 2 days old. :stuck_out_tongue:
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.

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/com.unity.entities@0.16/api/Unity.Entities.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.

2 Likes

There is a test inside Packages.Entities.Tests folder named “FixedStepSimulationSystemGroupTests.cs” which should help you.

3 Likes

From what I understand you have to do it like this

First create This class

public class CustomFixedRateManager : IFixedRateManager
{
    public bool ShouldGroupUpdate(ComponentSystemGroup @group)
    {
        if (IsTenthOfASecPassed())
        {
            return true;
        }

        return false;
    }

    public float Timestep { get; set; }

    private bool IsTenthOfASecPassed()
    {
        return true;
    }
}

than

var fixedStepSimulationSystemGroup = World.GetOrCreateSystem<FixedStepSimulationSystemGroup();
fixedStepSimulationSystemGroup.FixedRateManager = new CustomFixedRateManager();

Hope this helps.

1 Like

@thebanjomatic his answer is most likely the default way of doing it.

1 Like

Okay guys i got it down with the help of thebanjomatic thanks :slight_smile:

public class TenHzSystemGroup : ComponentSystemGroup
  {
    public TenHzSystemGroup ()
    {
      FixedRateManager = new FixedRateUtils.FixedRateCatchUpManager(0.1f);
    }
  }
[UpdateInGroup(typeof(TenHzSystemGroup ))]
  public class TenHzSystem: SystemBase
{
}

is working :slight_smile:

make sure that you use GetEXISTINGSystem or else you override something and it will just run in non fixed timesteps

8 Likes