# Niagara use SetVariableMaterial set MID doesn't work

**URL:** <https://forums.unrealengine.com/t/niagara-use-setvariablematerial-set-mid-doesnt-work/571425>\
**Category:** FX\
**Tags:** unreal-engine, UE4, question\
**Created:** [June 1, 2022, 9:01am UTC](https://forums.unrealengine.com/t/niagara-use-setvariablematerial-set-mid-doesnt-work/571425 "2022-06-01T09:01:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![H\_Quann](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@H\_Quann](https://forums.unrealengine.com/u/H_Quann)\
**Post date:** [June 1, 2022, 9:01am UTC](https://forums.unrealengine.com/t/niagara-use-setvariablematerial-set-mid-doesnt-work/571425/1 "2022-06-01T09:01:37Z")

</div>

Hi,  
I want to set a MID to my render mesh niagara at runtime. So I use MeshRendering.OverrideMaterials.UserParamBinding  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/5/a/85abc4ea7a87546f99b9c7b5b90bdcea53abad90.png)  
I can use `SetVariableMaterial("BrokenWallMat", MID)` to control the niagara emitter mesh.

But I also need Bindings.MaterialParameterBindings to change material.

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/b/f/fbf19e34f833a9d85b33554512795c640549acb6.png)

Fin, I found that SetVariableMaterial doesn’t work.

In SourceCode I find：  
`SetVariableMaterial` will call `UpdateEmitterMaterials(true)` in UE4.27 or `UpdateEmitterMaterials()` in UE5.

UE4：UpdateEmitterMaterials(bool bForceUpdateEmitterMaterials)

```cpp
//....
Emitter->ForEachEnabledRenderer(
    [&](UNiagaraRendererProperties* Properties)
    {
        // Nothing to do if we don't create MIDs for this material
        if ( !Properties->NeedsMIDsForMaterials() )
        {
            return;
        }

        TArray<UMaterialInterface*> UsedMaterials;
        Properties->GetUsedMaterials(EmitterInst, UsedMaterials);

        uint32 MaterialIndex = 0;
        for (UMaterialInterface*& ExistingMaterial : UsedMaterials)
        {
            if (ExistingMaterial)
            {
                bool bCreateMID = true;

                if ( ExistingMaterial->IsA<UMaterialInstanceDynamic>() )
                {
                    if ( EmitterMaterials.FindByPredicate([&](const FNiagaraMaterialOverride& ExistingOverride) -> bool { return (ExistingOverride.Material == ExistingMaterial) && (ExistingOverride.EmitterRendererProperty == Properties) && (ExistingOverride.MaterialSubIndex == MaterialIndex); }) )
                    {
                        if ( bForceUpdateEmitterMaterials )
                        {
                            // Forcing an update means create a new MID so grab the parent from the existing one
                            ExistingMaterial = CastChecked<UMaterialInstanceDynamic>(ExistingMaterial)->Parent;
                        }
                        else
                        {
                            // We found one so no need to create but make sure we keep it for tracking
                            FNiagaraMaterialOverride& NewOverride = NewEmitterMaterials.AddDefaulted_GetRef();
                            NewOverride.Material = ExistingMaterial;
                            NewOverride.EmitterRendererProperty = Properties;
                            NewOverride.MaterialSubIndex = MaterialIndex;

                            bCreateMID = false;
                        }
                    }
                }

                // Create a new MID
                if ( bCreateMID )
                {
                    //UE_LOG(LogNiagara, Log, TEXT("Create Dynamic Material for component %s"), *GetPathName());
                    ExistingMaterial = UMaterialInstanceDynamic::Create(ExistingMaterial, this);
                    FNiagaraMaterialOverride Override;
                    Override.Material = ExistingMaterial;
                    Override.EmitterRendererProperty = Properties;
                    Override.MaterialSubIndex = MaterialIndex;

                    NewEmitterMaterials.Add(Override);
                }
            }
            ++MaterialIndex;
        }
    }
);	

//...

```

UE5 is same excepet `UMaterialInstanceDynamic::Create` part

because all my emitter is mesh render emitter. so `!Properties->NeedsMIDsForMaterials()` is:

```cpp
virtual bool NeedsMIDsForMaterials() const override { return MaterialParameterBindings.Num() > 0; }	

```

so each enable renderer will create MIDs which MaterialParameterBindings was set.  
but UsedMaterials are the MIDs which I use `SetVariableMaterial` set.

fin, It will run to UMaterialInstanceDynamic::Create, but the ExistingMaterial is a MID I set. But ParentMaterial is a MID, so the MID which were create Parent is null and have som Warning

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/d/1/6d19e7e4e099461191d877ce210f38edacb24525.png)

At last, the niagara won’t render my `SetVariableMaterial` MID.

It is same in UE5.0.2

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/1/0/9101a6a2262bdb9b7004afa30af5debb60c82940.png)

both of them, do nothing **if ExistingMaterial is a MID and not found in EmitterMaterial**.

I check the `Properties`, the MaterialParameterBindings is in it.

if I set ExistingMaterial to Override.Material not create, it also have the MaterialParameterBindings Parameter.

Are there we need to recreate a MID when we SetVariableMaterial ?

Or How can I set MID to niagara when niagara have MaterialParameterBindings ，and my MID will work ?

---

<div class="post-metadata">

**Author:** ![ImYourBeast](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/imyourbeast/32/1220194_2.png) [@ImYourBeast](https://forums.unrealengine.com/u/ImYourBeast)\
**Post date:** [November 26, 2026, 11:46am UTC](https://forums.unrealengine.com/t/niagara-use-setvariablematerial-set-mid-doesnt-work/571425/2 "2026-11-26T11:46:22Z")

</div>

Create the MID first, assign it through the override binding, and do the binding before the emitter activates so the renderer picks it up on spawn. Reading the binding back after you set it shows whether it stuck. You can also try Expose Niagara Variables C++ & Blueprints, it adds Blueprint getters for material and texture bindings with namespace control so you can verify what the renderer actually holds at runtime: [Expose Niagara Variables to Blueprint & C++ — Set Niagara Parameters at Runtime | Fab](https://www.fab.com/listings/284908d3-8f3a-4430-bece-12ca313608f7)
