Download

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

Hi there.

I’m having some trouble getting this to work. I’ve checked some other people doing this, 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.

989bd1dfa676bb61c7475e3a6588e87a79b99bc9.jpeg

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.

270d1246cb3e02e56fc9c4eb94aba7aec240dc33.jpeg

Is there anything wrong in this 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.

bp2.jpg

sorry delete the instance created in your character, in your hud bp
2fb0400f6b3c3f431a83807ba0fca35d5ac133df.png
f69b4d3a0c9ae7591e4e7bdf75f839a429f1b516.png

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:

73cb9c5ddf8df0627923d3f11387bd316079cb52.png

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 this 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.

This is my current setup:
5191c4701176f54f51dcd87ee6dfe2260945f045.jpeg

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:
bp5.jpg

Sorry for the double attachment.

then you have to do it in your umg widget bp not in hud bp class

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 this 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 this 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.
42c7548a4c08a4da0ab05b02f583f7ab8d166f33.jpeg

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 this in UMG for you from here:

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 this as well).

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

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

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

You probably won’t be able to change the title of this thread (I am not sure if forum users are able to do this, 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: