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 Update RateManager / VariableRateManager of ComponentSystemGroup without triggering an DoUpdate

Discussion in 'Entity Component System' started by Tudor, Mar 29, 2023.

  1. Tudor

    Tudor

    Joined:
    Sep 27, 2012
    Posts:
    150
    It appears to me that when you update your custom variable rate ComponentSystemGroup, you instantly trigger the OnUpdate of the systems that UpdateInGroup for that group.

    Is there a way to prevent this? For example if I have a custom variable rate update group set to update every 5 seconds, and I change it to instead update every second. I want the next OnUpdate to happen after one second, not instantly.

    I change the update group by doing:
    var updateGroup = state.World.GetExistingSystemManaged<MyVariableRateUpdateGroup>();
    updateGroup.RateManager = new RateUtils.VariableRateManager(1000, true);

    I can't find any other relevant settings or docs or examples in unity repos. Pls help me understand how this works :D

    ---

    Basically:
    - you can't set the rate of your group from a system that's part of that group (infinite loop)
    - you can set it from another system, and it triggers an instant OnUpdate, so you have to get really creative to sync it with a command buffer with a bunch of flags. Feels so wrong
    gg
     
    Last edited: Mar 29, 2023
  2. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,292
    For the similar case, I've made a separate tick system that tracks when specific entities has to be updated.
    When "tick" happens, this system marks query - entities as "active" via tag. With 1.0 you could do the same with enable mask.

    Then just include component into the query.
    This way you can specify time when to tick without actually triggering anything.
    No groupping, or rate managers or whatever extra.

    Tl;DR:
    TickSystem - .WithAll<TickEachX> - Check time
    Entity to tick - <TickEachX>
    Logic systems -> .WithAll<TickEachX> + .WithAll<ShouldTick> (or enable mask per component)
     
    Tudor likes this.
  3. Tudor

    Tudor

    Joined:
    Sep 27, 2012
    Posts:
    150
    Ok thanks. I was thinking I was missing some hidden "don't run on rateUpdate change" setting for IRateManagers or UpdateGroups.

    This default behaviour is conceptually strange to me. I would expect a system with a set fixed interval, to always wait before running; it has one job :) to wait; not to sometimes wait.