Search Unity

Mass resetting of components, and entity 'reservation' techniques

Discussion in 'Entity Component System' started by threedots1, Jul 26, 2021.

  1. threedots1

    threedots1

    Joined:
    Oct 9, 2014
    Posts:
    88
    I can't seem to find an overload of EntityCommandBuffer or EntityManager that allows mass resetting the state of a component to 0. Am I missing something?

    I guess I could write my own IJobEntityBatch that iterates through the chunks and uses UnsafeUtility.MemClear to do the job, but I feel like I'm missing something.

    My issue is I need to perform searches from many entity A to many entity B, in many different systems, and reserve entity B so future searches from other entity As in the same frame don't return the same result. When an entity B is selected some commands are queued up in a command buffer, but nothing reserves it for the current frame.

    I've thought about using a HashSet to act as a way to reserve entity Bs but in many cases Adding to the hashset can't happen until fairly late in the process, which would require performing the same work again and keeping a list of all failed entity Bs.... expensive process.

    Current thought is to add a permanent Reservation type component, simply a bool, and clear them at the end of each frame. This is why'd I like the ability to just zero out component value without going through an RemoveComponent/AddComponent step.

    Anyone tackled a similar problem? What was your solution?
     
  2. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,769
    If you doing something every frame, or very often, use bool to set state inside component.

    If you do something much less often, It is better to use component tag, as you can filter out such entities from processing in various jobs, reducing potentially required computing.

    Adding, removing component affects archetype, creating overhead. So this need be taken into consideration and weighted, when is suitable to use this approach.

    To reset component, you just use it as filter, in Entities.Foreach. Then do something with that component. Most likely one of most efficient and simplistic ways to do it. You can use bool, or mentioned component tag, to filter required entities.
     
    Last edited: Jul 26, 2021