Search Unity

Entity Id / index / version

Discussion in 'Data Oriented Technology Stack' started by SubPixelPerfect, Apr 16, 2018.

  1. SubPixelPerfect

    SubPixelPerfect

    Joined:
    Oct 14, 2015
    Posts:
    193
    Entity consists of two variables index and version
    and 2 entities considered as equal only when both index and version are equal

    Could you please explain why entity identity defined by a combination of two variables?
    and what index and version mean?
     
  2. timjohansson

    timjohansson

    Unity Technologies

    Joined:
    Jul 13, 2016
    Posts:
    68
    Internally we store some information about the entity in an array - that is the index. After an entity is destroyed that index can be used by another entity you create - otherwise we would run out of entity ids really quickly if you create and destroy lots of enties - so we also have a version which is increased every time an id is reused. So if the index is identical but the version is different they are not the same entity, one is deleted and a new one happened to get the same index in the internal array.

    The fact that it is two variables is mostly an internal implementation detail though, you should just treat the Entity as an opaque identifier and avoid making assumptions about those numbers.
     
    RaL, DwinTeimlon, SugoiDev and 4 others like this.
  3. SubPixelPerfect

    SubPixelPerfect

    Joined:
    Oct 14, 2015
    Posts:
    193
    thank you for clear and instant answer