Search Unity

GetComponentDataArray cannot be called on zero-sized iComponentData

Discussion in 'Entity Component System' started by kstothert, Jan 20, 2019.

  1. kstothert

    kstothert

    Joined:
    Dec 8, 2016
    Posts:
    68
    Code (CSharp):
    1. GetComponentDataArray<NoxEcs.CameraTarget> cannot be called on zero-sized IComponentData
    I have tried adding the component in all the recommended ways,

    Code (CSharp):
    1. EntityManager.AddComponent(entity, ComponentType.Create<CameraTarget>())
    2.  
    3. PostUpdateCommands.AddComponent<CameraTarget>(entity, new CameraTarget{});
    4.  
    5. EntityManager.AddComponent(entity, typeof(CameraTarget))
    all give the same error
     
  2. fholm

    fholm

    Joined:
    Aug 20, 2011
    Posts:
    2,052
    The component struct must contain fieds for you to be able to use GetComponentDataArray
     
    kstothert likes this.
  3. kstothert

    kstothert

    Joined:
    Dec 8, 2016
    Posts:
    68
    of course...thanks
     
  4. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,759
    Zero sized components don't exist, because they have no data.

    The archetype just has knowledge that the type is part of the chunk so can be used for filtering but there's nothing in the chunk because again, they have no data. What would be stored? So if nothing exists there's nothing to get.
     
  5. GilCat

    GilCat

    Joined:
    Sep 21, 2013
    Posts:
    676
    As quote above those don't really exist. Empty components are used as "Tags" and to know their existence of those zero sized components you can call
    Code (CSharp):
    1.           // for getting the amount of components in the group
    2.           ComponentGroup.CalculateLength();
    3.           // for testing the existence for such component in an entity
    4.           EntityManager.HasComponent(Entity, typeof(NoxEcs.CameraTarget));
    5.           // for testing the existence of such component in a Chunk
    6.           ArchetypeChunk.Has(ArchetypeChunkComponentType<NoxEcs.CameraTarget> chunkComponentType);
    Try to access components with no data will cause exception like:

    ArgumentException: ArchetypeChunk.GetNativeArray<> cannot be called on zero-sized IComponentData
    ArgumentException: GetComponentDataArray<> cannot be called on zero-sized IComponentData