Search Unity

Adding/Removing marker components?

Discussion in 'Entity Component System' started by fholm, Nov 12, 2018.

  1. fholm

    fholm

    Joined:
    Aug 20, 2011
    Posts:
    2,052
    Does adding or removing a 'marker' component (i.e. an IComponentData without any fields on it) cause an entity to be shifted to another archetype chunk? If they are, is there any performance issues with adding/removing tons of marker components?
     
  2. dartriminis

    dartriminis

    Joined:
    Feb 3, 2017
    Posts:
    157
    Yes it does (ArchetypeChunk.Has(ComponentType) works on marker components).

    Are there performance issues? Maybe...
    Added or removing a component effectively moves the remaining component data for that entity to a chunk with like archetypes.The performance cost of this varies depending on the size of the other entity's components, and probably some other factors as well. However, keep in mind that part of the performance benefit of ECS comes from keeping entity data packed together with like archetypes. Adding a tag component will cost performance in that you must move some data, however, that entity (and its data) is now packed together with like archetypes for more efficient processing, which could net you a performance gain overall.
    As always, remember to profile.
     
  3. fholm

    fholm

    Joined:
    Aug 20, 2011
    Posts:
    2,052
    Okey, thank's for the confirmation.