How do I script "Remaining Battery Power" From flashlight into my HUD?

I’ve been looking online for tutorials and asking friends and I’m getting no results. I need to be able to show the remaining battery power for my flashlight in the corner of the screen. Example “Battery: 94%” And it would count down as t’s being used. But stops when counting when turned off. Any suggestions?

Also on a side note, one other thing I can’t figure out is I want to be able to pull up a phone out of the corner of the screen (Like in a GTA game) Just to be able to check a time on it. This is probably way out of the ballpark, but any clues towards this as well? Thanks!

I can only answer the Battery Power question. The GTA Handy is way to much time consuming for me right now (it isn’t that easy).

You should have some kind of a Flashlight class, where you store the power as an float value.

Now you create a second variable that you use to setup the speed with which the power should be drained.
You can use the “Event Tick” function of your Flashlight blueprint. Get your CurrentPower Variable and do something like this:

The “AmountOfPowerDrain” should be a value that you want to be subtracted EACH SECOND.

The delta seconds is just to always have the same value subtracted, even if the game lags for 10 seconds.
If the tick ticks every second, delta seconds will be 1. If the tick ticks twice a second, deltaseconds will be 0.5.
If the tick ticks only every 2 seconds (due to an fps lag) the delta seconds will be 2. And so on.

For only decreasing the value if it is not 0, you can add a check:

So as long as CurrentPower is > 0, it will drain, and if it is less or equal to 0, you can turn off the flashlight.

Make sure to set the default values of these 2 variable to something different than 0.0!

When you want to add power to the flashlight, you just need to add a value to the “CurrentPower” variable, and it will start draining again.

To display this, you only need to get the reference of this flashlight into a UMG widget somehow.

For example spawning the flashlight and saving it in a Reference variable insight of your PlayerCharacter.
Then you can create a HUD Widget and call “GetPlayerCharacter0”, cast it to your CharacterBP and get the Flashlight reference. Then you can just display “CurrentPower”.

Also i would set CurrentPower to 0, as soon as it is lower or equal to 0, because otherwise you could run into a negative number.