Download

UMG button pressed fills up progress bar

ue4forumshelp74.PNG

Hey, I’ve created a UMG so that if you click on one of the 5 buttons, it adds that item to your inventory and if you click on the take all button it adds all 5, but I want it so that if you keep the button “take all” pressed, then it fills up a progress bar (that I’ve created below the button) and when it’s full it adds the items to your inventory, otherwise the bar returns to zero and the items stay in the container. Thanks in advance!

Maybe use “islmbdown” or something like that, and then use a tick? When it gets to the required amount it ignores the click event and resets?

Addition, wouldn’t it be better for play purposes to have to hold the button to take all items and ignore a single click on that button?

You can add 3 different events for a button. One handles Click and Release and the other 2 are for pressing and for releasing.

So you could take the Pressed Event to set a bool to true and the Released event to set it back to false.

And then you use a timeline that goes from 0 to 1 in X seconds (that depends on you) and the finished exec will call the TakeAll Function.
If you release the button, and the bool is false, you just revert the TimeLine.

Thanks for the reply, should I do this in the widget blueprint? The event tick won’t go into the input node for is lmb down

Yes that’s what I want, I currently have it so if you click the button then they get added to the inventory but I want to replace that so you hold the button until the bar is full :slight_smile:

Thanks for the reply, I don’t know why but it’s not allowing me to create a timeline in the widget blueprint.

I couldn’t create a timeline in a widget blueprint so I’ve created a custom event that plays the timeline
ue4forumshelp75.PNG

ue4forumshelp76.PNG

When the button is pressed it cats to the player and then the custom event function, that then adds all items to inventory
3418abfa6fa48ca2bdff65e40d883232adf3a69b.png

This is the bar percent function that I binded, which currently doesn’t fill up, but the player stills take all of the items
ue4forumshelp78.PNG

Do you know why this isn’t working? Thanks

Well, if the timeline is not working, then let us just use the tick of that widget.

What this does is, it checks in the tick if we pressed the button or not, if yes, it adds “FillSpeed” to the Percentage of the ProgressBar each second.
Since it is called each tick, we need to multiply “FillSpeed” with DeltaSeconds. Because the Tick does not tick every second. DeltaSeconds compensate this.

Never forget that!

Once the percentage is >= 1.0 (ProgressBar goes from 0.0 to 1.0!), we call a do once (so we only call the function once), set the Percentage to a fixed 1.0,
reset the bool (you don’t need that, but with that the bar automatically decreases again, without the player having to release the button) and call the TakeAll
function. I only put a PrintString there, because i have no TakeAll Function.

On the other side, when the Bool is false, we reset the do once and decrease the Percentage back to 0.0.

You can use 2 different variables for FillSpeed and DecreaseSpeed if you want.

An example for FillSpeed would be 0.5 (like in the screen shot). It adds 0.5 per second, which results in the bar taking 2 seconds to fill.

Working perfectly! Thank you very much eXi :slight_smile: