Texture coordinate indexes are different in code and in the material editor

When working with multiple texture coordinates that I have defined in my vertex factory, when I go to the material editor the index do not match up. My Init() code in my vertex factory is as follows:

void Init(const FMyMeshVertexBuffer* VertexBuffer)
{
    check(!IsInRenderingThread());
    
    ENQUEUE_UNIQUE_RENDER_COMMAND_TWOPARAMETER(
        InitMyMeshVertexFactory,
        FMyMeshVertexFactory*,VertexFactory,this,
        const FMyMeshVertexBuffer*,VertexBuffer,VertexBuffer,
        {
            // Initialize the vertex factory's stream components.
            DataType NewData;
            NewData.PositionComponent = STRUCTMEMBER_VERTEXSTREAMCOMPONENT(VertexBuffer,FMyMeshVertex,Position,VET_Float3);
            NewData.ColorComponent = STRUCTMEMBER_VERTEXSTREAMCOMPONENT(VertexBuffer,FMyMeshVertex,Color,VET_Color);               
            NewData.TextureCoordinates.Add(FVertexStreamComponent(VertexBuffer,STRUCT_OFFSET(FMyMeshVertex,TextureCoordinate), sizeof(FMyMeshVertex),VET_Float2));
            NewData.TextureCoordinates.Add(FVertexStreamComponent(VertexBuffer,STRUCT_OFFSET(FMyMeshVertex,Size), sizeof(FMyMeshVertex),VET_Float2));
            NewData.TextureCoordinates.Add(FVertexStreamComponent(VertexBuffer,STRUCT_OFFSET(FMyMeshVertex,MyType), sizeof(FMyMeshVertex),VET_Float2));
            NewData.TangentBasisComponents[0] = STRUCTMEMBER_VERTEXSTREAMCOMPONENT(VertexBuffer,FMyMeshVertex,TangentX,VET_PackedNormal);
            NewData.TangentBasisComponents[1] = STRUCTMEMBER_VERTEXSTREAMCOMPONENT(VertexBuffer,FMyMeshVertex,TangentZ,VET_PackedNormal);

            VertexFactory->SetData(NewData);
        });
}

Now when going to my material, I’d expect TextureCoordinate to be at index 0, Size to be at index 1, and MyType to be at index 2. When I go to work on my material, the indexes are 0, 2, 4 respectively. Am I setting something wrong? Should I be inserting instead of adding to make sure the indexes are exactly as I want them?

I am also running into this issue. Multiple texture coordinate streams seem to have the index increase by 2 and not 1 as expected.

Is there a better way of doing this?

I have the same problem, I modified DynamicMeshVertex to use multiple texture coordinates. Now, when I edit material, coordinate indexes in TexCord are 0, 2, 4, 6.

What’s the reason for that? How can I fix this, and use respectively indexes 0, 1, 2, 3?

I found the cause of this. You have to pack two texture coordinated into a float4. Then the texture coordinates work out properly.