Search Unity

Finding an Entity’s Archetype

Discussion in 'Entity Component System' started by PublicEnumE, Aug 3, 2019.

  1. PublicEnumE

    PublicEnumE

    Joined:
    Feb 3, 2019
    Posts:
    729
    Is there an API to find an Entity’s archetype (preferably from inside of a job)?

    I’ve been searching for a GetArchetype() method (or similar), but so far to no avail. Thank you for any pointers.
     
  2. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    Code (CSharp):
    1. this.EntityManager.GetChunk(entity).Archetype
    If you need it from within a job, you can just get it from the Chunk during iteration.
    I am not aware of anyway of getting it from within a job if it's just an Entity reference.

    However if you need to do this there's a good chance you're doing something you probably shouldn't so i would consider revising what you're trying to do.
     
    Last edited: Aug 4, 2019
  3. Enzi

    Enzi

    Joined:
    Jan 28, 2013
    Posts:
    966
    Like Tertle said, for example try to use Component Tags as definitions to find out which type it is for your conditions. Do you really need the archetype in the first place?
    Outside of instantiating I can't think of many uses.
     
  4. PublicEnumE

    PublicEnumE

    Joined:
    Feb 3, 2019
    Posts:
    729
    I won’t be using Archetypes in this way. Thanks for the help, folks.