Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Recommended way of checking if an Entity still exists?

Discussion in 'Entity Component System' started by PhilSA, Sep 2, 2020.

  1. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    Let's say I store an entity in a component and that entity might get destroyed at some point, how should I check that the entity still exists in a job?

    Is there a generic way that doesn't rely on a HasComponent with a specific component type?
     
    Lukas_Kastern likes this.
  2. Kirkules_

    Kirkules_

    Joined:
    Aug 5, 2014
    Posts:
    65
  3. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    But entityManager can't be used in a job, right?
     
  4. Kirkules_

    Kirkules_

    Joined:
    Aug 5, 2014
    Posts:
    65
    yes so you'd have to check prior to running job that would have a bad entity reference.

    Unless it's .WithoutBurst().Run();
     
  5. Mockarutan

    Mockarutan

    Joined:
    May 22, 2011
    Posts:
    158
    If you have some idea of what type of entity it is (what components it will own), you can just check if it has that specific component. If it does not have a component that it should have, then the entity does not exist. in a specific case I check if it has Translation or LocalToWorld, because the entity type I'm looking at in that specific situation will have at least one of them.