Search Unity

ArchetypeChunk.GetNativeArray<person> cannot be called on zero sized component data

Discussion in 'Entity Component System' started by calabi, Jul 6, 2019.

  1. calabi

    calabi

    Joined:
    Oct 29, 2009
    Posts:
    232
    I'm trying to add some entities to a DynamicBuffer on to some other entities but I get the above titled error, when using the below code.

    Code (CSharp):
    1.      Entities.ForEach((DynamicBuffer<EmployeeEntitysArray> bbqbusiness) =>
    2.             {
    3.                 Entities.ForEach((Entity currentent, ref Person poople) =>
    4.                 {
    5.                    
    6.                     bbqbusiness.Add(new EmployeeEntitysArray { EmployeesEntitys = currentent });
    7.                 });
    8.             });
    Am I misunderstanding, is it trying to get the Dynamicbuffer from the entitys with the Person component, they don't have EmployeeEntitiysArray component attached.

    I'm not sure what I'm doing wrong I've tried other ways but they don't seem to work either(GetBufferfromentity doesn't seem to work). I'm not entirely sure how I get access to the DynamicBuffer on an entity with an IComponentSystem/JobSystem.
     
  2. TRS6123

    TRS6123

    Joined:
    May 16, 2015
    Posts:
    246
    Replace line 3 with this:
    Entities.WithAllReadOnly<Person>().ForEach((Entity currentent) =>
     
    eterlan likes this.
  3. calabi

    calabi

    Joined:
    Oct 29, 2009
    Posts:
    232
    Awesome, thanks for that, it works. I'm curious why it didn't work, is it because foreach's don't work on tags?.
     
  4. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    It's exactly as the error states. Under the hood the ForEach syntax is just doing chunk iteration and zero sized components (tags) can't be queried as they don't exist in the chunk.
     
    eterlan likes this.