Course contentsShow
← Unreal Engine Game Development
Lesson 513 of 8807. Visual Fidelity and RenderingFree lesson

Creating Dynamic Material Instances

Develop systems to modify material parameters at runtime through Blueprints, enabling interactive visual changes based on gameplay events.

In this lesson, you will learn how to bypass the rigidity of static materials by creating Dynamic Material Instances (DMIs) to modify visual properties like color, glow, or transparency during gameplay.

The Problem with Static Materials

When you assign a Material to an Actor in the editor, that Material is shared across every instance of that object in the world. If you change a parameter on one, it changes on all of them. To gain individual control—like changing a lightbulb's color only when a player flips a switch—you must create a Dynamic Material Instance. This essentially creates a unique, runtime-only copy of the material that you can manipulate via Blueprints.

Implementing Dynamic Material Instances

The process requires two steps: initializing the instance and setting its parameters.

  1. Creation: In your Actor’s BeginPlay event, use the node Create Dynamic Material Instance. Target the specific component (like a StaticMeshComponent) and select your Master Material.
  2. Storage: Promote the return value of this node to a variable. This allows you to reference this specific instance later in your logic.
  3. Modification: Use the Set Vector Parameter Value or Set Scalar Parameter Value nodes. Ensure the "Parameter Name" matches exactly what you defined in your Master Material graph (e.g., "EmissiveColor").

Example Logic:

// Within the Actor Blueprint
// 1. Initialize
DynamicMat = MeshComponent->CreateDynamicMaterialInstance(0, MasterMaterial);

// 2. Modify based on a gameplay event
DynamicMat->SetVectorParameterValue(FName("GlowColor"), FLinearColor::Red);

Why This Matters

By using parameters in your Master Material (via Scalar Parameter or Vector Parameter nodes), you decouple your visual logic from your gameplay code. Instead of swapping entire materials, you are simply updating values on the GPU. This is significantly more performant and allows for smooth transitions, such as fading an object's opacity or pulsing an emissive surface to indicate an interactive item.

Key Takeaway: Creating a Dynamic Material Instance allows you to manipulate specific material properties at runtime for individual actors without affecting the global material asset.