Okay… first of all… a heads up… this wont just end here guys… It will probably result in another question about a similar related question… ish.
Anyway; So I have created a HUD using the new Blueprint Widget things that comes under the UMG feature. I have followed the tutorial that you guys used on the Twitch channel. But I am having issues. I am hoping someone here has the answer. Anyway I have my health written down. I have a separate text block representing the value. I am doing just 0 to 100, so I would expect to handle the damage and healing by changing the variable as an integer. but thats me.
so my trouble is passing the value to the text block that is on the hud. I have set up a cast to that blueprint widget to the direct value. i am debugging and it tells me it is failing to cast. I have set that text block as a variable.
They are set to public. if it helps, the health and health is stored in the character blueprint and i am trying to cast to the HUD blueprint widget.
I dunno guys… i am lost… i am pretty sure i had it working at one point. maybe i am just losing the plot.
Thanks in advance, and here is an image to help. if need anymore. just request.
I can’t tell from your screen, but is the HUD you speak of the old school HUD blueprint class or the widget. The way I set this up was the sort of opposite. I set the text block in UMG and then next to the text entry field click the Bind link. This will create a function that you can use to get that variable. Depending on where you have it you need to cast or use an interface to get to it and hook it up to the output of the function UMG created for you.
I can see that you are trying to cast to your HUD blueprint. You will need a way of referencing the specific HUD instance that you are using in the game already. Right now, your cast object is essentially looking at HUD Actor, but not anything in particular, so the cast is not sure what instance it should use and then fails.
You can reference the HUD you are using for casting through the Player Controller:
Once you have that set up, you will have access to everything that blueprint holds. In my example, the HUD I use is called “MyHUD”.
this is some helpful information. I will give this a wizz. on my next attempt… as I seemed to have destroyed my current HUD Blueprint widget. I crash the engine now everytime its loaded.
So once I have created it. I will have a go. But I want to update a variable to contain the players health. is this still the right method?
Actually, I am reading this again and I see that what I have answered was for if you were using a HUD Blueprint, not widget.
You will want to get a reference to the UserWidget in you character blueprint so that it can cast. Check out my explanation of using a progress bar here:
In the beginning I start by going to the place that the Create Widget is done, then getting the return value from it to use as a Cast To object to access the widget.
okay so I have taken what you have on board. and as least the cast is kind of successful. it doesn’t ‘Fail’ thats for certain. but the health on my HUD won’t update still. is there a some blueprinting needed in the event graph of the Hud Widget?
Here is an image of what I have so far… its pretty much an exact replica of yours so I don’t see where the problem is there.
You can see in the image that you can drag off of the cast to get a reference to the progress bar (in the example I called mine “Health Bar”) then you can get the “Set Percent” from there.
But I am not using a progress bar. My health is a written value in the form of a text block. do I still need to use this. because I cant use these function ‘Set Percent’
Then go into the Function that it creates by double-clicking it in the functions menu in the graph. Once opened, you can Get your Current Health variable that you are updating and simply plug that into the Return Value of the function. I left some more notes in the image:
so… i don’t understand why it won’t update it is it to do with my cast? or do i need something in the actual HUD widget like a event tick to keep tabs of the value?
Sorry to be a pain… I just really cant get this working
That is really odd, everything looks the same as mine as far as I can tell. Can you show me what it displays when you play? Have you Anchored the TextBlock? Maybe it is outside the screen? I will keep looking into this until we can get it working for you.
definitely not an issue with the way its displayed! I set the 'CurrentHealth value to 50 for default and the player health to 100 so I should in theory see it as 100
but as you can see it still displays the 50 from the standard currenthealth variable.
Ahh, I had a guy helping me on steam at the same time. and he said my problem was that I was creating the widget twice because i was doing it in the Character selection after removing it. and then calling it again. so i separated all of that. and just brought it into my current blueprint and it all works. here is an image of the problem solved.
thanks to your blueprint and him telling me where my problem is… it works… PURR’FECTLY! thanks for the help
I think I know what it is now. How are you adding the Widget to the viewport? You would need to drag from the Create Widget’s return value as the Target to make sure everything is referring to the same instance of the widget.
The “Set Hud Widget” variable technique I did in the other post makes sure that I can always refer to the same Widget UI instance without dragging out a bunch of wires everywhere.
Here is everything I am doing within MyCharacter to give you an idea: