Stuck Trying to Display a Variable to the Player's HUD / Widget
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.
Follow this question
Once you sign in you will be able to subscribe for any updates here