Pause Button Editing Health Bar? (Beginner!)

Hello!
I’m having some issues with having my pause button and health widget work separately?

I have gameplay UI onscreen during gameplay. This game will ideally be an Android mobile game so the pause button is a widget in the top right, when this is clicked the game would ideally pause then have a ‘continue’ button to resume. The game has a health bar in the middle of the screen and, currently, I have the gameplay UI widget displaying on ‘Event Begin Play’ and the Health bar update happening on ‘Event Tick’:

This is the logic for displaying the Gameplay Widget:

And this is the logic for updating the health bar:

Although, there is a strange issue where, after pausing, the health bar will look half empty (it actually isn’t, the player still has maximum health and can take the same amount of damage)?

As a beginner I’m really stumpted about why this is happening? I’ve played around with the blueprints and even followed 2 other pause menu tutorials but it doesn’t change it? (This is the pause logic I’m using in case it’s the problem):

(And this is the pause widget continue logic):

I tried having the UI Gameplay widget creation and the update health function both being on event tick, however this had very strange results, it made the pause menu constantly pressable even in the puase menu so it kept spawning them on top of each other?


(And for some reason in this video the health bar is also still broken?? :weary:)

I’d really appreciate any help/ advise about this issue if anyone has any ideas! Thanks so much for taking the time to read this! :heart:

I finally found the issue. You’re not actually showing the original that the player owns- you’re constantly creating new widgets.

In here, in your player, you create the gameplay widget, record it, and add it to the screen.
Then throughout your tick, you update that variable.

As a side note, you should definitely not have these be dedicated functions- they’re way too simple. UpdateHealthWidget is literally just UpdateHealth. Making them dedicated functions clutters up your blueprint and makes it hard to tell which functions are wrappers and which make up the backbone of your blueprint.


Whenever you press the pause button, you remove the gameplay widget from the screen, and create the pause menu widget.

Then whenever you click the continue button, you remove the pause menu and create an entirely new gameplay UI inside the pause menu. This is terrible since you’ll be creating possibly hundreds of widgets over the course of the game. But this variable is only stored in the pause menu- not in the player. The player is still happily updating the original gameplay widget without any knowledge of there being a new one.

Instead of this creating and deleting, I highly recommend you just keep the pause menu and gameplay menu in one widget- no removing or adding widgets, just hiding. You can do this by adding two canvas panels as children to your main canvas. Name them something like GameplayCanvas and PauseCanvas:
image
You can then add children to them to make them look how you’d like. You can easily hide the other while you work on one by clicking the eye icon:
image
Now the entirety of the pause menu is hidden.

You’ll want to make sure that the canvas’s are variable and they anchor to fill:


And make sure their offsets are all 0


To pause/play, simply use the buttons and change the visibility of the canvas panels:

This worked perfectly! Thank you so much for your help! :v: :revolving_hearts:

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.