Download

How to get the meshes' original materials for later use?

Hi, I want to add a script in my character to override materials of static meshes,
so that when the performance is getting lower I can replace the materials temporary,

the objects were imported from datasmith so I’d like to keep its properties
instead of adding them into a new BP actor.

the first section for overriding materials works fine,
but I don’t know how to write the second scripts.

Please help me to keep the original materials from beginning so that I can reset them later.

Thanks.

The B exec in your flip-flop is getting the current material which is the one you just replaced the original with. You need to store the original material in a variable and retrieve it when you want to set the material back to the original.

You’re also looping through all your materials and setting the first material on your mesh to the current index of the loop. When you loop through your material array, you need to set the material at the current index, and not just set index 0 every time.

Here’s what it looks like:

1 Like

@LXStudios Hi, Thank you for the reply,

I just added the variables for the meshes and its materials as you said,

now I can switch the materials back and forth,

but now I got a new problem…

image

if each meshes contains only one material,

I want them to reset to their [0] material,

but the script I wrote cannot do the task,

can you help me to solve this problem?

Thank you for your kindly help.

You only need one for-each loop going through your “Mesh Array 1”. Get each material from “Origin Mat 1” using the Array Index of the mesh loop.

The end result of what you have now is just setting each mesh to the last saved material.

1 Like

You don’t need an “original material array.” Just get the material from the mesh itself. MeshComponent → GetStaticMesh → GetMaterial.
image

1 Like

That works if you’re getting the hard copy, but ignores the construct script and previous changes.
Looks like it suffices for OP’s needs though.

1 Like

@LXStudios @midgunner66

Hi, Thanks for your help, I changed the material array variable to the single one and now it works!

Thank you!

1 Like