Share variable from character to material parameter? + UMG Image update? [SOLVED]

Hi there.

I’m having some trouble getting to work. I’ve checked some other people doing , but the nodes they usually use are different from the ones in UE4.5.

Here’s my problem:
I have a parameter that controls a circular life bar and I need that specific parameter to match the health parameter from my character so it displays his health/magic points or anything else, but I’ve arrived to a point where I don’t know how to proceed.

My parameter is called Current Health, so first I create a Dynamic Material Instance from the Construction Script of my HUD and set the material I want as a variable. Then in the Event Graph I get the player controller to cast to MyCharacter to get his HP points and plug them into the value for the parameter I want to modify, but then it asks me for a “Collection”, but in all of the tutorials I’ve seen, they plug a material instance in there and then change the parameter name to whatever it’s called in the material.

Any pointers or advices? Thanks in advance.

from “MyCharacter cast” get “Hp Dynam Inst” and then set scalar parametre value

I did it, but it still doesn’t seem to be working.

Is there anything wrong in setup?

here your are setting a new variable
from “As My Character C” get " Hp Dynam Inst" then plug it in “Collection”

I can’t do that. MyCharacter isn’t the owner of HP Dynam Inst, MyHUD is, so that’s kinda impossible.
Anyhow, I did that. I created a new material instance in MyCharacter and then I linked HP Dynam Instance to the set scalar value, but it’s still not doing what I want it to.

sorry delete the instance created in your character, in your hud bp


Hi there,

DynamicMaterialInstance’s can be made a couple different ways and it is not always clear which to use, the same goes for setting Vector and Scalar parameters. There are 2 separate nodes to be aware of for each of these:

Make sure you turn OFF the “Context Sensitive” option when you are searching for these nodes, and you will find there are 2 of each with the same name. The ones I have selected in the Black comment box are the ones you will want to use in your situation.

Hope that helps! :slight_smile:

I’m sorry, but that still doesn’t do anything. Plus, why would I need to draw it again? I’m already using material in UMG, so the only thing I want is to update the “Current Health” value within the Material, not to redraw it.
Maybe I explained myself wrong.

is my current setup:

Thanks, I didn’t know that. I tried using the one in the middle but it’s having no effect. I don’t know what I’m doing wrong anymore. Here my setup with the node you recommended me:

Sorry for the double attachment.

You will want to set up the DynamicMaterialInstance within the HUD construction script instead of the character, and only pass the values to update to the HUD.

I already moved the material instance over to the HUD BP when you told me to. Plus, I’m only updating values from the HUD, but I’m casting the character’s BP because he does have the actual “Current HP” I want to use for the material.

EDIT: Actually, if I draw the material it does work, but my UMG HUD isn’t being updated. I know is like something complelety different, but could you tell me how to update the images in my UMG HUD?

Can you try using a DrawMaterialSimple node instead of the DrawMaterial? The simple version should set the UV’s properly, I can’t see any other reason for not to work. Are you seeing anything on screen or is it just not updating?

EDIT: sorry just noticed the edit, let me check

Can you post a screenshot of your current setup in UMG for us, it will be the quickest way to help. :slight_smile:

Thank you. My UMG is very simple. Just an “Image” in the top-right that is using the Material I previously mentioned.

I know I’m double posting but I would like someone to possibly answer my second question so I don’t have to create a whole new topic.
How do I update my widget? My material’s values are being updated but the widget itself isn’t being updated, so the bar stays the same.

Sorry for leaving suddenly yesterday, but I found some info on how to do in UMG for you from here:
.unrealengine.com/latest/INT/Engine/UMG/UserGuide/Styling/index.html#dynamicmaterials

It looks like you do need to update on tick and you will probably want to set up a custom event to notify the UMG widget when there is a change, although you could also just reference the variable since it is updating every tick anyways.

You also need to make sure the material is set up with the “Used with UI” option checked (from the link above, scroll up a bit to see the documentation on ).

Ah! Thank you very much! I didn’t know I had to do it that way. It’s kinda annoying but it’s working.
is my final setup, in case anyone has a problem similar to mine.

I’ll change the title of thread if I manage to know how and add that it has been resolved.
Thanks again, !

Excellent! Great to hear you have it working! :slight_smile:

You probably won’t be able to change the title of thread (I am not sure if forum users are able to do , might only be moderators), but I can do it for you if you’d like? just let me know how you would like it changed and I can fix it up for you!

Thank you. Just change to how the title of the opening post is. I changed the title of the first post since I can’t change the title of the thread.

Done, all changed for you. :slight_smile: