Search Unity

FixedRateUtils.EnableFixedRateSimple sets deltaTime but update rate is still the same

Discussion in 'Entity Component System' started by whiteDOTS, Apr 2, 2020.

  1. whiteDOTS

    whiteDOTS

    Joined:
    Apr 2, 2020
    Posts:
    3
    Hi,
    I am trying to set a fixed update interval for a group.
    I use this code in my group:
    Code (CSharp):
    1. FixedRateUtils.EnableFixedRateSimple(this, 0.5f);
    0.5 means it should be updated twice per second.

    I have a system in this group:
    Code (CSharp):
    1.  
    2. [UpdateInGroup(...)]
    3. public class Test : ComponentSystem
    4. {
    5.     protected override void OnUpdate()
    6.     {
    7.         Debug.LogWarning("Update@" + UnityEngine.Time.time + " delta=" + Time.DeltaTime);
    8.     }
    9. }
    10.  
    The log message still shows at least 50 times per second in the console.
    It has the correct Time.deltaTIme of 0.5f, but it does not only show twice per second.
    Here is a screenshot, note the UnityEngine.Time.time:
    upload_2020-4-2_16-45-3.png

    It's called about every 0.02 seconds, so around 50 times per second instead of twice per second.

    When I check the Entity Debugger, the system is absolutely in the right group.

    Looking at FixedRateUtils source, I don't see any code that would return false if not enough time has elapsed yet:
    upload_2020-4-2_16-46-19.png

    If I use FixedRateUtils.EnableFixedRateWithCatchUp then it does work, because that one has a 'return if not enough time elapsed' check.

    So whoever wrote EnableFixedRateSimple shipped it without even bothering to test it.
    That's quite disappointing. I have high hopes for DOTS but this looks like it's the same story all over again :/?
     
    Last edited: Apr 2, 2020
    Angelo13C likes this.
  2. Sarkahn

    Sarkahn

    Joined:
    Jan 9, 2013
    Posts:
    440
    I was just messing with this and had similar results. In my case trying to use
    EnableFixedRateWithCatchup
    just straight up locks the editor as soon as I hit play. This is with the Unity 2020b3 and Entities 0.9:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using Unity.Entities;
    4. using UnityEngine;
    5.  
    6. class FixedRateSystemGroup : ComponentSystemGroup
    7. {
    8.     protected override void OnCreate()
    9.     {
    10.         base.OnCreate();
    11.  
    12.         // Causes systems to still be updated every frame but does affect the ElapsedTime/DeltaTime that gets reported
    13.         // to that system
    14.         FixedRateUtils.EnableFixedRateSimple(this, .5f);
    15.  
    16.         // Locks up the editor...
    17.         //FixedRateUtils.EnableFixedRateWithCatchUp(this, 3f);
    18.     }
    19. }
    20.  
    21. [UpdateInGroup(typeof(FixedRateSystemGroup))]
    22. class FixedRateSystem : SystemBase
    23. {
    24.     protected override void OnUpdate()
    25.     {
    26.         Debug.Log($"FixedRateUpdate : {Time.ElapsedTime}");
    27.     }
    28. }
    Can we get some confirmation this is a bug? Or are we using this class incorrectly?
     
    RaL and Angelo13C like this.
  3. Angelo13C

    Angelo13C

    Joined:
    Feb 16, 2020
    Posts:
    11
    Same problem here
     
  4. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,685
    Your code works fine for me.
    Entities 0.9.0
    Unity 2020.1.0b5
    (More over I put it in our production project which big and has many features and fixed time step works fine)
    upload_2020-4-10_16-43-10.png
     
  5. Sarkahn

    Sarkahn

    Joined:
    Jan 9, 2013
    Posts:
    440
    Hey, thanks for testing this! I just want to be clear on the behaviour I'm expecting here. Similar to OP, if I call EnabledFixedRateSimple with a value of 0.5 like
    FixedRateUtils.EnableFixedRateSimple(this, .5f);
    , I would expect that group would only be updated twice per second of actual elapsed time. From your screenshot that doesn't appear to be the case (I'm not sure if you changed the timestep value):

    chrome_ALlEfuOPu3.png

    It looks like it's being called once per frame, which is not what I expect to be happening. Am I missing something?
     
  6. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,685
    My response was more about (see below) :)
    About behaviour - it not take in to account multiple calls per frame, FixedRateUtils it's first step in'to controllable tickrate, we'll see how it expands in future definitely. About this specific case I recommend OP fill bug report.
    P.S. Tried to link Cort Stratton here, but can't find his login on forum.
     
    Sarkahn likes this.
  7. Sarkahn

    Sarkahn

    Joined:
    Jan 9, 2013
    Posts:
    440
    I created a simple repro project using entities 0.9 and 2020.1b5, I had the exact same results - FixedRateSimple does nothing except change the reported Time, FixedRateWithCatchup locks up my editor when I press play. I submitted a bug report, hopefully this one doesn't just get ignored for months like my other reports have.
     
    whiteDOTS likes this.
  8. whiteDOTS

    whiteDOTS

    Joined:
    Apr 2, 2020
    Posts:
    3
    So DOTS bug reports get ignored for months again?

    I find this to be hugely demotivating. I have been using Unity for a long time and assumed that finally with DOTS things are changing, and that Unity would add lots of unit tests and take bug reports seriously.

    I don't know. This is just sad. DOTS seems so promising, but I don't know if I want to go through this all over again just to end up with another 10 years of instability :/
     
  9. diesoftgames

    diesoftgames

    Joined:
    Nov 27, 2018
    Posts:
    122
    Hey just found this thread so wanted to post a workaround for this hang in editor that's worked for me:
    Make sure you're making the call to FixedRateUtils during the update of the system or system group you're setting to fixed rate. So for instance:

    Code (CSharp):
    1.     [UpdateInGroup(typeof(FixedRateSystemGroup))]
    2.     public class SetupFixedRateSystem : ComponentSystem {
    3.         bool HasRun = false;
    4.  
    5.         protected override void OnUpdate() {
    6.             if (!HasRun) {
    7.                 HasRun = true;
    8.                 FixedRateUtils.EnableFixedRateWithCatchUp(
    9.                     World.GetOrCreateSystem<FixedRateSystemGroup>(),
    10.                     UnityEngine.Time.fixedDeltaTime);
    11.             }
    12.         }
    13.     }
    I've no idea why that works, but when I've tried to call it from anywhere else it hangs the editor.
     
    spothieuxEden and Sarkahn like this.