Dynamically modifying emissive color in a blueprint without pre-declared vector parameter in material editor

Hey there,

I am trying to create a dynamic parameter for material emissive color (toggleable glow effect) in such a way that it is scalable. However, dynamically obtained materials cannot have their emissive color modified if a vector parameter was not declared prior to runtime.

Is there a way to plug a vector created in a blueprint into the emissive color input node that doesn’t have a param waiting?

The process would look like this:

get static mesh > get material > create dynamic material instance > set static mesh material to dynamic material > create vec3/vec4 > plug vec3/vec4 into emissive color input node > oscillating glow according to timelined sine function

According to the KismetMaterialLibrary.h, the only blueprint exposed functions (under that header, anyways), are Get/SetVectorParameterValue, Get/SetScalarParameterValue, and CreateDynamicMaterialInstance.

Is this too much to ask for? Is it a poorly constructed solution? Should the developer manually add vector params for each material expected to glow (ideally no, as it would defeat the purpose of creating a scalable solution)? Or is there a way to force this behavior in C++?

Thanks in advance!

You could add a master material with a glow parameter and generate instances of it. I feel it being inefficient to spend runtime generating material objects where you could easily load a pool of instances.

Unreal shaders need to be compiled before they can be displayed in engine. Because of this the material graph and any material parameters must be defined in advance. There really is no way around this, and is unlikely to change.

's suggestion of using a master material containing a glow parameter and whatever other parameters you need is the correct solution. Alternatively you could look into the new material layers system and make a “glow layer” with the necessary parameters that could be applied to a layered material.

Depending on your goal, you may find that a post process material effect is suitable for your needs. Then you can have your glow appear according to custom depth stencil, which can be handled and adjusted via blueprints. Refer to this tutorial for more info if this solution suites you.

All great answers! I decided to try out the material layering but couldn’t figure out how to access the Layer Parameter/Material Layer object to input the dynamically obtained texture parameter, as I have a Material Layer object exposing its base color in “SetMaterialAttributes.”

Instead I am now creating a separate static mesh that copies the original static mesh but applies a translucent glow material upon toggle. Luckily there seems to be no depth fighting (as I was intending to create a scaled up glowing mesh) so there is no extra work regarding that issue. I am unsure how this is affect performance and I may need to find an elegant way of destroying the cloned meshes, if necessary, once they are not in use.