Adding a Material Slot to a Mesh during runtime

Hi guys,

Is it possible to add a Material Slot to a mesh (In blueprints or C++) during runtime? I would like to add an emissive Material to create a Highlight on an object.

I know I can do it with Blendables in a PostProcess, but with that technique I cannot highlight 2 objects with different colors.

Thanks!

Hello FG707,

From what I understand, adding a slot at runtime isn’t possible. The best idea would be to have this extra material already applied with a few scalar parameters set up to control the values. One way would be to have the alpha of said material controlled by a Scalar and then have it default to 0. When you want the material to appear, you can set the alpha to anything above 0 to make it appear. You’ll need to use a Material Instance Dynamic instead of a base material to be able to edit it at runtime as well.

I’m sorry, I don’t think I understand correctly.

So if I want 100 materials that could be highlighted, I need to add the scalar parameters in each of them? Or can this extra material be applied at runtime on any material?

Thanks for your reply !

To start with a basic example, make a new project with the Third Person template.

This will be easier to follow/explain in blueprint, and then you can set it up in C++. If you need help with that afterwards, please feel free to ask questions.

Create a new Material in the content browser and open it for editing. Hold V and left click to create a Vector Parameter and plug the white pin into the Base Color pin for the Material. Give the parameter you just made a name (In this example, I named it “MyTint”)

After that, open up the blueprint for the ThirdPersonCharacter and set the Mesh’s first material to your newly created material. After that, you can add the nodes to create a dynamic material instance and set that as the new material on BeginPlay.

After this, you can set up any action you want to change the material’s tint at runtime. For my example, I bound it to the jump functionality.

For this particular setup we’re just changing the base color but you could change anything like opacity to get the desired highlight effect.

With the marvelous help of **** I was able to create the exact effect I wanted which is to Highlight objects dynamically with different colors depending on the nature of the object (by example good , neutral or bad ). The Highlight blend in and blend out with the Timeline (set the Highlight ScalarParameter from 0 to 1 and 1 to 0 each seconds) when I press the ‘8’ key.

Here is the exact Blueprints used and the effect (in pictures).

Thanks .

LevelBlueprint

Actor Blueprint

Highlight Material

Normal Cube

68328-normalcube.png

Highlighted Cube

68329-highlightedcube.png

This is exactly what I needed thanks. I posted the solution to my exact problem so that people can use it.