Dynamically add Material Function to a Dynamic Material

This is my current situation.

I have a Material Function that changes the value of the Emission of a material.
All pickup objects in the game should use this material function.
As of now, what I’m doing is manually modify the base material of each object and add this material function.

Afterwards, this base material is used by a Dynamic Material because it has to do other stuff.

What I’d like to know is if it’s possible to dynamically add this material function as well.
Something like this:

Basically creating the dynamic material instance and then add the MaterialFunction to it.

Right now I have to add the Material Function every time like this

EmissiveMaxStrength and EmissiveDeltaTime are also parameters I have to add to each material

Since your already have EmissiveColor as a parameter on your material you can use “SetVectorParameterValueOnMaterials”. Here is a snippet from my code:

I should’ve pointed out that those 2 parameters are also added for every material every time I want to use that MaterialFunction

Oh so the values you want to change at runtime are EmissiveMaxStrength and EmissiveDeltaTime? Then I would change those from constants to parameters (like EmissiveColor is now) and use SetScalarParameterValueOnMaterials instead.

If the problem is that you have several materials that use those parameters and you only want to change the emissive dynamically on one of them, maybe you can change the parameter name for that one that needs to be changed at runtime.