Change Multiple Material Textures Blueprint based on Health Total

I have 2 materials assigned to my character (head/body), the materials are instances. The main global material used has two 2 textures for the base color, one for a healthy body and one for a damaged bloody body. I managed to create a blueprint that changes texture based on a float for health total. It works, however, not perfectly. It only changes the body or head textures to the damage texture. How can I edit the blueprint to make it change all textures to damage texture?

1 Like

Make two Dynamic Material Instances, one for each Element Index. It sounds like you have two (head and body) so do the same thing in your constructor but use the 2nd index for the other MDI.

Some of my characters have more than 2 materials. How can I set up an array that checks for the number of materials then changes them all to the damaged textures? This is what I got so far.

That I don’t know how to do.

I fixed it! What you have to do is create a private integer variable called “MaterialIndex”. So since most of my characters have 2 materials (head/body), a few also have 3 or 4 materials as well. So if you want the blueprint construction script to check how many materials the mesh have first before swapping out the textures in the materials. (The global material got a lerp node with a parameter node that changes one texture to the other for the base color/roughness). Connect the “MaterialIndex” variable to a Make Array node, since most of the characters have 2 materials but some have 3 or 4, add 3 more pins to the Make Array node, if the mesh does not have a 3rd or 4th material, it will automatically return nothing (NULL) and ignore the 3rd or 4th pin. Connect the Make Array node to a ForEachLoop then connect the Script to the ForEachLoop to the Create Dynamic Material Instance. Compile and try sliding the DamageTotal (public variable float) from 0.0 to 1.0 and you will see all the textures being swapped out to the “dead/damaged” one.

1 Like