Search Unity

Determining if any new entities were created or changed

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

  1. threedots1

    threedots1

    Joined:
    Oct 9, 2014
    Posts:
    88
    I need to export data from ECS into an array or dynamic buffer to allow for faster processing by other systems.

    I want to limit doing this to only when there has been new entities added, or components updated on existing entities. Basically rebuild the entire array/buffer if a change has occurred that frame.

    What would be the recommended method of doing this? I'm thinking either:
    • In the systems that create/update these entities, write a flag to a nativearray (isn't there a new native container for a single struct now?) that can be read later to determine changes. This might be problematic as multiple systems could add/remove tag components and update values etc.
    • Use filters on queries to determine if changes have occurred. I've been playing with this idea but can't seem to figure out what filters would actually accomplish this. Basically looking for:
    Code (CSharp):
    1. if (query.EntitiesHaveChanged() || query.HasChangedComponents())  
    2.   RebuildArray();
    The cost of filtering may just outweigh the cost of just copying the data every frame though...

    Cheers.
     
  2. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    4,271
    Inside an IJobEntityBatch, you can check ArchetypeChunk.DidOrderChange() and ArchetypeChunk.DidChange().