{ }Blueprint → C++

Unreal Engine 5 · Blueprint → C++

Set Material on a Mesh Component in Unreal Engine 5 C++UE Docs

The Set Material node maps to UMeshComponent::SetMaterial, which assigns a material to a specific element index (material slot) on a mesh component.

Blueprint node & C++ equivalent

C++
MyMesh->SetMaterial(/*ElementIndex=*/0, MyMaterial);

The C++ equivalent

Call MyMesh->SetMaterial(0, MyMaterial), where the first argument is the element index, also called the material slot, and the second is the UMaterialInterface* to apply. Index 0 targets the first material slot; a multi-material mesh exposes higher indices.

MyMaterial can be either a base UMaterial or a UMaterialInstance, since both derive from UMaterialInterface.

Setting a dynamic material instance

To change material parameters at runtime, create a dynamic instance with CreateDynamicMaterialInstance, which both applies and returns a UMaterialInstanceDynamic you can edit with SetScalarParameterValue or SetVectorParameterValue. Use plain SetMaterial when you simply want to swap one finished material for another.

Element indices that exceed the mesh's slot count are ignored, so confirm the slot exists.

Frequently asked questions

How do I change a material in UE5 C++?+

Call MeshComponent->SetMaterial(ElementIndex, MaterialInterface). The element index selects which material slot to overwrite.

What is the element index in SetMaterial?+

It is the material slot on the mesh. A mesh with several materials has indices 0, 1, 2 and so on; index 0 is the first slot.

Related Components nodes

View all Components nodes →