Dynamic Material Instance changes in editor but not at runtime

I am trying to get a pawn to change its color at runtime depending on controller axis input, all in Blueprints. It works in the editor (through the construction script of the pawn) but not at runtime (through the event graph of the pawn).

Here is the material:

The Charge scalar controls the color (1 is red, 0 is white, -1 is blue).

Next I have a custom Actor Component that works as an interface to this material and can be reused on different actors. It has a Charge float variable that maps to that of the material.

It has one event that gets the static mesh of its owner and applies a dynamic material instance of the previous material to it. I always call it in the construction script of the owner. Here it is:

So this part seems to work, because if I change the Charge variable on the owner in the editor, I see the color update.

The Actor Component also has an event to update the charge and the material, intended to be used at runtime. Here it is:

So this is how my material and my Actor Component are done. Finally I have a Pawn, and it has the Component attached. Here is its Construction Script:


Just a reminder that this part works. Now if I change the Charge variable of the component, I see the color of the mesh of the pawn change in the viewport.

In the event graph of the pawn, I am getting an axis input that calls the event of the component supposed to update the Charge and the color:

This does update the value of Charge correctly, but the color doesn’t change. It remains white corresponding to a Charge value of 0, its default value. Can you help me figure out why?

I tried making the color a parameter and changing it in the Actor Component instead of in the Material, but the result is the same.

UPDATE: This is now solved. It actually always worked, so if anyone wants this behavior just look at what I did above. My problem was that I had a player start in the level out of the field of view of the fixed camera, so at runtime it spawned another pawn that I was controlling, instead of the one in the camera’s field of view. It’s the right time for a facepalm. Everyone starts somewhere! :smiley:

Thanks for your reply. I figured my problem thanks to Neil C on the Discord server, and it turns out that it is not the material itself. It is how I set up my inputs. I’m gonna comment my question with details inside.

You could use a vector parameter and just edit that to blue or red depending on your conditions.

If you’re in your character blueprint you could just drag out the static mesh components and branch out a create dynamic instance material. If your static mesh have different materials just edit out element index (0 = first material).

My characters color if charge = 1

My characters color if charge = -1