Stuck Trying to Display a Variable to the Player's HUD / Widget

Hello Everyone,

I’m having trouble trying to get a variable to display on the Player’s HUD. The Variable is an Integer that holds the value of “Time” remaining. Counting down, I am trying to display this variable to the player’s HUD. The Timer is a placeable actor into the level, which allows me to change the “time” to complete each level.

What I’m trying to achieve: The timer counts down from 60 seconds, Displaying the time remaining to the player on their HUD. If the time hits “0”, then a game over widget pops up.

I’m not primarily a programmer as a developer, So I’m getting stuck every now and again with BPs.

Any help would be greatly appreciated!

For clarification, If you look at the attached images: I’m trying to get the variable called “TestTimer1” to display to the Widget where the “999” is being presented. I am not primarily a programmer, So I’m not sure on how to make this work.

Hmm since you are not a programmer im going to try to explain it easier, since the time remaining is something that will be visible to the player, it could be inside the player character blueprint instead of stay on a random actor or on your level blueprint.

1 - So you can create the variable “timeremaining” inside your char blueprint, set its value to what you want.

2- Compile and save your blueprint

3- inside your widget, click on the text you want to show your counter and on details panel you will have the propriety “text” on right side you have a button “bind”, click on that and create a bind function (give the name you want for that). This function basically will get a value from some place and put this value on your text.

4- Go to your event graph (still inside the widget), there you have the event construct, plug that to a “cast to (player)” - if you are using the default player on the third person example, it should be: cast to thirdpersoncharacter. It will have an object, this you will plug on a “get player character”, then you can get that result and promote to a variable(im gonna call it “playerdata”). so you will have now the reference of your player character and can manipulate variables inside that for example.

5- back to the function you have created. There you will get the variable that you created to reference your player blueprint (“playerdata”), from that you will get the variable “timeremaining” and plug that to return node. You will notice it will automatically convert your integer value to a text value, its ok. Just compile and save.

6- On your level blueprint: event begin play - create widget(choose the one you created) - add to viewport, so now you will notice that the value that is on your timeremaining variable will be on your widget. To manipulate that you can use the tick event and decrement your variable, just remember its a variable inside the player, so you need to cast your player blueprint there too, to have access to that variable.

Here are some screenshots, if the text is too confuse to understand, hope it helps.
The update thing could be made on your own widget or even inside player character.

@iorek01 Thank you for such a detailed response! This is quite different, I’m just wondering how the “Game Over” state fits into it. When and If the timer hits “0”, It’s supposed to be game over. :slight_smile:

Would a “compare int” fit in just the same after the “set timeremaining”. Also, just for clarification, does the timer logic actually have to be kept within the Level Blueprint?

Perhaps a timer function could work entirely within the character blueprint?

yes you are right, you can have a “compare int” right after the "set time remaining"and make the game over there. Yes, the timer logic can stay inside the character blueprint, it will work.

Thank you so much for your help. It’s saved me some serious headaching. :smiley: Is there any way I can contact you if I run into issues? Twitter or something?

you can send me a private msg on unreal forum, so i will be able to answer you as soon as i check it =) i dont have twitter =s

Fair enough, I should really be more active on the Forums anyway. :slight_smile: