Multiple Materials on dynamically created mesh


my plan is to create a procedrual Voxel world (which I already accomplished in Unity and now porting to UE) and right now I’m experimenting with UCustomMeshComponent respectively UGeneratedMeshComponent and I would like to have procedural grass colors. In order to do this I want to use another noise function and dynamically set the materials Color values, but as soon as I create another mesh with the same material the color of the material will be same that I set before, it seems that I’m editing the “root” Material. So my question is: Is there any way to create multiple instances of the material and edit them individually?

Another question: Right now I would create a mesh for each block as I didn’t found a way yet to assign multiple materials to a dynamically created mesh as it can be done in Unity, where you have another Array for UV-Textures. Is this possible at all or will I have to use my approach co create a mesh for every visible block?

Thanks in advance,

You should create dynamic material instance from your material instance and then apply DMI to your mesh. This way you will have individual copy of “parent” material on each mesh.

Static mesh have an array of materials, you should be able to add materials to this array.

I unfortunately haven’t had any time to update the wiki with contributions proposed by other people. Maybe these posts can help?

set UV’s for the custom meshes

UVs For GeneratedMesh

improve the rendering quality of the Generatedmesh

Dynamic mesh crashes related to material indices


EDIT: Something like GeneratedMeshComponent->SetMaterial(i, Material); (where i is a material index) doesn’t work?

Thanks for your response!

I tried that one, but it failed, maybe due to my first problem. I created an instance of the material and added it via SetMaterial(i, material), afterwards edited it and added it another time, therefore I probably added the same instance twice, which is why I didn’t see that there are two materials.

But I switched back to Unity anyway. I have the feeling that I don’t understand what I’m doing in UE, once because UE is more low-level and second because I learned C++ alongise UE and therefore my understanding of that language isn’t that well yet. And since Unity fits most of my needs (although UE has much more possibilities) and I already have a stable version of my game running over there (60FPS) it’s better for me to stay with Unity at the moment.