Search Unity

How to efficiently apply logic to target entities

Discussion in 'Entity Component System' started by jeremies_unity, Sep 17, 2019.

  1. jeremies_unity

    jeremies_unity

    Joined:
    Oct 16, 2018
    Posts:
    26
    We have a lot of effects in our game (procs/triggers, health linking, homing projectiles) that require "target" entities. We currently GetComponentData and GetBuffer on the targets to apply logic on them and/or the source.

    This seems like a very naive approach, and I would like to know what's the best practice for this use case.

    For example, would it be better to have a separate query for these target entities and fill NativeHashMaps beforehand?
     
    Opeth001 and Deleted User like this.
  2. Singtaa

    Singtaa

    Joined:
    Dec 14, 2010
    Posts:
    492
    In general, ComponentDataFromEntity + Burst Jobs should be the recommended way of dealing with arbitrary entities. If you have a lot of extreme one-to-many relations (i.e. tons of homing missiles but only a handful of targets), then you can utilize the batch api to gain more performance.
     
  3. jesta

    jesta

    Joined:
    Jun 19, 2010
    Posts:
    294
    Is there an equivalent of ComponentDataFromEntity for DynamicBuffers?
     
  4. Singtaa

    Singtaa

    Joined:
    Dec 14, 2010
    Posts:
    492
    Yes, BufferFromEntity. Those are the only two *FromEntity right now. There are times I wish there are more, like ArchetypeFromEntity and ChunkFromEntity.
     
  5. TheGabelle

    TheGabelle

    Joined:
    Aug 23, 2013
    Posts:
    242
    Is it possible to test a query against an entity?
     
  6. Singtaa

    Singtaa

    Joined:
    Dec 14, 2010
    Posts:
    492
    TheGabelle likes this.
  7. TheGabelle

    TheGabelle

    Joined:
    Aug 23, 2013
    Posts:
    242
    It'd be nice if I could check if an entity tests true using an EntityQueryDesc, but ComponentDataFromEntity.Exists() will yield the same results if I use a few. Thanks!