How to update mesh after clear it's override materials?

Hi,

I override a mesh’s materials at runtime, sometime I need to restore it’s original materials.

I inherited StaticMesh component in c++, then just empty OverrideMaterials.

I can see it work on detail panel, but the viewport does not update it’s material.

How to fix it? Or is there any other way to achieve it?

Thanks

I solved it: just call MarkRenderStateDirty method.

But, I still want to know is there any other way to achieve this in blueprint?

I’m doign in C++ but in Blueprint (4.9) it will be the same.

To reset to the original material, you just have to read the default value of your object on the object and SetMaterial with it in parameter.
To read default object, you need to wait for 4.9 as defaultvalue has just been promoted to Blueprint in 4.9

For anyone else looking for a way to set the mesh materials back to default, just set all material elements to None.

3 Likes

Sorry if I reopen this old thread: I need a help for Flip Flop a bounch of static meshes with world outline materials ovverride.

What I obtain is that the materials are taken from original Asset from content browser and not from World actor state, they are reset at initial state and it doesn’t work.
I lose all materials.

There’s my BP


Here the sequence.

Have you ever solved this problem? I am currently in the same situation.

Yes, we solved one year ago, hopefully.
Save all materials and associated meshes to a struct at the beginning of runtime, then you will have the opportunity to reapply the correct indexed materials.
That’s the result:

https://youtube.com/watch?v=_5mtkptqArw](https://www.youtube.com/watch?v=_5mtkptqArw)

我爱死你了