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

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.

     Entities.ForEach((DynamicBuffer<EmployeeEntitysArray> bbqbusiness) =>
            {
                Entities.ForEach((Entity currentent, ref Person poople) =>
                {
                    
                    bbqbusiness.Add(new EmployeeEntitysArray { EmployeesEntitys = currentent });
                });
            });

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.

Replace line 3 with this: Entities.WithAllReadOnly<Person>().ForEach((Entity currentent) =>

1 Like

Awesome, thanks for that, it works. I’m curious why it didn’t work, is it because foreach’s don’t work on tags?.

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.

1 Like