InvalidOperationException: Trying to get iterator for * but the required component type

Good day everyone.

I am trying to move from to be deprecated [Inject] to ComponentGroup.

What I am trying to rewrite is basically:

 private struct NetLibraries
        {
            [ReadOnly] public SharedComponentDataArray<NetLibrary> Libraries;
            [ReadOnly] public EntityArray Entities;

            public readonly int Length;
        }

        [Inject] private NetLibraries netLibraries;

To:

private ComponentGroup netLibraryGroup;

protected override void OnCreateManager()
        {
            netLibraryGroup = GetComponentGroup(new EntityArchetypeQuery
            {
                All = new ComponentType[] { ComponentType.ReadOnly<NetLibrary>() },
                Any = new ComponentType[0],
                None = new ComponentType[0],
            });
        }

However, when I am trying to access its own SharedComponentDataArray (I know it will be deprecated soon too)

var netLibraries = netLibraryGroup.GetSharedComponentDataArray();

I am getting the following exception:

InvalidOperationException: Trying to get iterator for ECSNet.NetLibrary but the required component type was not declared in the EntityGroup.
Could anyone help me? How to get the data in most optimized way? Thank you.

Replace ArchetypeQuery to default group getting. Or move to Chunk Iteration.

1 Like

Hello. Thank you for your reply. Would you suggest to move to chunk iteration or wait for a new API? I found chunk iteration slower than SharedComponentDataArray. Correct me if I’m wrong.

Depending for what propose.
ComponentDataArray will be gone someday. When it happen, you will need to migrate every code before updating the ECS package. Archetype chunk will let you migrate easily but will demand more code now.
To be honest, without a roadmap from Unity and more information about what are you trying to do it’s really hard to predict what will be best for medium and long terms. Maybe the best it’s just focus on what it’s more comfortable for you right now.

It shouldn’t be. Can you show what code did you tried?

[ ]'s

1 Like

Hi there. Thank you for your answer.

I’ve used your method: Rewriting a system using chunks/queries instead of to-be-deprecated injected group structs page-2#post-3791698

So basically now the code looks like that:

        private ComponentGroup netLibraryGroup;
        [ReadOnly] private ArchetypeChunkSharedComponentType<NetLibrary> chunkType;

        protected override void OnCreateManager()
        {
            chunkType = GetArchetypeChunkSharedComponentType<NetLibrary>();

            netLibraryGroup = GetComponentGroup(new EntityArchetypeQuery
            {
                All = new ComponentType[] { ComponentType.ReadOnly<NetLibrary>() },
                Any = new ComponentType[0],
                None = new ComponentType[0],
            });
        }

        protected override void OnUpdate()
        {
            var chunks = netLibraryGroup.CreateArchetypeChunkArray(Allocator.Temp);

            foreach (var chunk in chunks)
            {
                var sharedIndex = chunk.GetSharedComponentIndex(chunkType);
                var sharedComponent = EntityManager.GetSharedComponentData<NetLibrary>(sharedIndex);
            }

            chunks.Dispose();
        }

What I would like to achieve, chunk iteration by using ComponentGroup to illuminate use of ComponentDataArray. or SharedComponentDataArray. but still have GetEntityArray() from the componentGroup.