OnUpdate () method in ComponentSystems

Hello everybody.
Can you please tell us what could be the reason that the OnUpdate () method in ComponentSystems is not updated in every frame, but only when ComponentDataArray is updated? That is, when Entity is created and its component falls into the ComponentDataArray, only the OnUpdate () method is triggered.

public Queue<EData> NotEntityEvent = new Queue<EData>();
public struct EventsData
    {
        public readonly int Length;
        public ComponentDataArray<EData> EventData;
    }
    [Inject] private EventsData _EventsData;
   
    protected override void OnUpdate()
    {
        if (NotEntityEvent.Count != 0)
        {
            for (int i = 0; i < NotEntityEvent.Count; i++)
            {
                EData Temp = NotEntityEvent.Dequeue();
                Listeners[(int)Temp.Event](Temp);
            }
        }
        if (_EventsData.Length != 0)
        {
            for (int i = 0; i < _EventsData.Length; i++)
            {
                Listeners[(int)_EventsData.EventData[i].Event](_EventsData.EventData[i]);
                PostUpdateCommands.DestroyEntity(_EventsData.EventData[i].Entity);
            }
        }
      

    }

OnUpdate will only be called if one of these conditions is filled

  1. If there is at least 1 entity from within any component group that was created within the system

  2. There are no component groups (it will always update then)

  3. The [UpdateAlways] attribute is attached to the system (it might be AlwaysUpdate, on phone can’t check)

So in your case, you’ll want to attach the attribute

2 Likes

[AlwaysUpdateSystem] works. Thank you very much for the help.

1 Like