Way to change MaterialMeshInfo inside IJobChunk?

Hey everyone,

Like the title says, I need to change the material id of entity’s MaterialMeshInfo.

The problem is, I can’t use the ref MaterialMeshInfo inside IJobChunk Execute.

How do I pass a query with the data to IJobChunk and then modify it inside?

(Note: I know I can do this inside IJobEntity but I need to use Chunks).

Thanks!

the array you get from chunk.GetNativeArray points to inside the chunk, so you simply have to get a value, modify it and reassign it at the same index

    [BurstCompile]
    public struct UpdateTranslationFromVelocityJob : IJobChunk
    {
        public ComponentTypeHandle<MaterialMeshInfo> MMTypeHandle;

        [BurstCompile]
        public void Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask)
        {
            NativeArray<MaterialMeshInfo> mmInfo = chunk.GetNativeArray(ref MMTypeHandle);

            var enumerator = new ChunkEntityEnumerator(useEnabledMask, chunkEnabledMask, chunk.Count);
            while (enumerator.NextEntityIndex(out var i))
            {
                var info = mmInfo[i];

                info.Material++;

                mmInfo[i] = info;
            }
        }
    }
1 Like

Thank you so much! Just what I was looking for. Works great for me!