Search Unity

entity name

Discussion in 'Entity Component System' started by l33t_P4j33t, Feb 21, 2020.

  1. l33t_P4j33t

    l33t_P4j33t

    Joined:
    Jul 29, 2019
    Posts:
    232
    how do i get the name of an entity?
     
  2. ippdev

    ippdev

    Joined:
    Feb 7, 2010
    Posts:
    3,853
    You identify an entity by its index and version.
     
  3. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,770
    You can set name of entity, but that is just for debugging purposes.
     
  4. l33t_P4j33t

    l33t_P4j33t

    Joined:
    Jul 29, 2019
    Posts:
    232
    yes, that's the intent
    want to get the name of the entity that a raycast is hitting
     
    ippdev likes this.
  5. ippdev

    ippdev

    Joined:
    Feb 7, 2010
    Posts:
    3,853
    Depending on how many entities you are tracking or whether they are unique or not you can tag them with a uniquely named component. It is a good way to group entites as well, and you can for example add an index inside the name component and assign it at creation and keep matching indexed builtin Arrays for always same sized groupings and List<T> for groupings that may shrink or grow, using whatever data you want associated with each in mono land in whatever type is the preference for your game logic. You can access data from them using an EntityManager created query filtering for your component and [ReadOnly] for performance using myComponentsQuery.ToEntityArray(Allocator.Temp)
     
  6. ippdev

    ippdev

    Joined:
    Feb 7, 2010
    Posts:
    3,853
    A method you could use that would have utility in a number of scenarios is to tag the entities that got hit by a raycast and perform a query from mono land. Then you can set Debug.Log or manipulate game logic using the raycast data for example getting the Translation and Rotation data of the entity hit using the query filter API.
     
  7. BackgroundMover

    BackgroundMover

    Joined:
    May 9, 2015
    Posts:
    224
    Would EntityManager.GetName(entity) do it?