Search Unity

How to use the AttachComponent (ComponentDataWrapper) ?

Discussion in 'Entity Component System' started by 5argon, Nov 29, 2018.

  1. 5argon

    5argon

    Joined:
    Jun 10, 2013
    Posts:
    1,555
    I see the code comment says you have to create a new entity with child-parent mapping as Entity field if it is a normal Attach : IComponentData. So what is the point of having a ComponentDataWrapper where I will not even get any chance to assign the Entity field from the inspector? When GameObjectEntity make it into Entity, wouldn't it be instantly destroyed? How should it supposed to be used?

    From my guess

    Parent
    > Child1
    > Child2
    > Attach1
    > Attach2

    Each Attach is an empty game object with just GOE and AttachComponent, because attaching AttachComponent to the child directly would destroy the child entity. Then in some way on enable I have to quickly get both attach and wire up the Entity by using the wrapper.Value before the first transform can update. Is that the right way to use? It feels very convoluted. (It would make sense if AttachComponent were SharedComponentDataWrapper with 2 exposed GameObjectEntity field or something..)
     
    Last edited: Nov 29, 2018