Search Unity

Reference back to entity translation

Discussion in 'Entity Component System' started by Reloque, Dec 5, 2019.

  1. Reloque

    Reloque

    Joined:
    Apr 28, 2015
    Posts:
    207
    So, I have an entity that has another entity as target;

    Code (csharp):
    1. target.targetEntity = referenceEntity;
    That means in another job I have reference to that entity. I want to turn towards that entity, but I can't really figure out how to get the translation data component of my target entity. I mean, I'd expect it to be something like this;

    Code (csharp):
    1.  
    2.                 // target has an Entity
    3.                 // That entity has a Translatopn
    4.                 Entity targetEntity;
    5.                 targetEntity = target.targetEntity;
    6.                 Entities.Equals((targetEntity, ref Translation targetTranslation) =>
    7.                 {
    8.                     Debug.Log("Found it");
    9.                 });
    10.  
    But that is not right at all. I am probably not finding the right google terms for it either. How would I get the translation associated with an entity, by referencing that entity?
     
  2. TRS6123

    TRS6123

    Joined:
    May 16, 2015
    Posts:
    246
    Use ComponentDataFromEntity (it allows you to access a component from another entity):
    var translationFromEntity = GetComponentDataFromEntity<Translation>(true);
     
  3. Reloque

    Reloque

    Joined:
    Apr 28, 2015
    Posts:
    207
    I looked at that, but where do i reference what entity I want the translation from? Where do I put in that I want the translation from target.targetEntity?
     
  4. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    4,264
    ComponentDataFromEntity has an Entity indexer, similar to a Dictionary.