Search Unity

Searchfor Entity/Archetype with a specific value?

Discussion in 'Entity Component System' started by JamesWjRose, Oct 22, 2019.

  1. JamesWjRose

    JamesWjRose

    Joined:
    Apr 13, 2017
    Posts:
    687
    I need to search a through entities, or more specifically an archetype, where a specific entity's value = 123

    I looked at EntityQuery, but it SEEMS to return entities based on the types, not the value. or am I missing something?
     
  2. charleshendry

    charleshendry

    Joined:
    Jan 7, 2018
    Posts:
    97
    If lots of entities share the same values you could use ISharedComponentData to set the values. Each chunk then has entities with the same values. You can then use SetFilter in an entity query to return the entities with a specific value and iterate over them.

    Otherwise using IComponentData, you filter by this component type and iterate over all of them but checking each components value before performing an operation. Depending on your data, this could be more performant in some cases.
     
  3. JamesWjRose

    JamesWjRose

    Joined:
    Apr 13, 2017
    Posts:
    687
    Thanks Charles, however the value I am looking for is an identity there is only one of that value. I am super surprised there is not a method for searching an entity with a specific value.

    Also, thanks for the point about iSharedComponentData, that may be of help elsewhere.

    Oh the fun of learning a new API while it's in beta.
     
    MNNoxMortem likes this.