Search Unity

How to Exclude Components From EntityManager.Instantiate?

Discussion in 'Entity Component System' started by MixGrey, Sep 20, 2019.

  1. MixGrey

    MixGrey

    Joined:
    Dec 23, 2014
    Posts:
    9
    If my understanding is correct, when you use EntityManager.Instantiate, it copies all of the components on the entity except for the Prefab component.

    Is there a way to exclude specific components from this process?

    My specific case involves some ISystemStateComponentData components created by a system when it sees new Entities. When I use EntityManager.Instantiate to copy an Entity, I'd like it to exclude copying the SystemState data so the system will initialize the new Entity. I have multiple cases where this needs to happen and may add more, so I need a solution that doesn't require every EntityManager.Instantiate call to also be accompanied by HasComponent and DeleteComponent.

    What is the preferred way to do this?

    EDIT:
    Found the answer not long after posting this thread. My apologies. I'll leave this thread up since it might be useful to someone.

    Poking through the ECS source code, in some of the low level stuff, I found this line:
    var skip = type.IsSystemStateComponent || type.TypeIndex == m_PrefabType;

    where it skips both Prefab and ISystemStateComponentData when Instantiating. So that solves my specific case. I don't believe there's a way to have it exclude regular IComponentData, unless you can have something be both SystemStateData and ComponentData at the same time.
     
    Last edited: Sep 20, 2019
    azmi_unity likes this.