Widget not updating after reopening level?

The widget slider works fine when initially starting the level but for some reason, if the player dies and respawns (the level reopens) the slider no longer updates- even though it till works it’s just not visually updating. Any ideas how to fix this?

This isn’t enough information to go off chief, we’re going to need to see how your slider is actually updating in the first place and what logic it’s using.

If I were to make a guess, I would assume that you’re updating it from some sort of health variable from your character maybe. And when your character is dying, I assume you may be destroying the actor. In which case, if you’re destroying the actor, then if your widget is set to a hard reference, you need to make sure that when your actor is being destroyed and recreated, then you’re resetting the widget’s reference to the character and to get its health variable from it.

otherwise your widget is going to be calling out into the void to try and get the reference to an actor that’s been already destroyed and garbage collected.

if you’re reloading the level as well you need to be careful how you’re setting your variables and what you’re referencing there for your UI to pull on.

I would recommend on your widgets on initialized or on construct or on begin play on your actor you set a reference to the character to the variable or the object that controls the variable that you’re interested in and then reference back from that and try and gracefully handle the potential state whereby your widget doesn’t have a correct updated variable to call from.

1 Like

Hi, so sorry for the lack of info I didn’t realise how brief I was oops :sob:

I’ll do my best to explain!

There’s two characters, each has a different power. The top green slider shows player 1’s power which slows time, this only ticks down when the input key is pressed and stops if the input is stopped.

Player 2’s power is anti gravity, once this is pressed the slider works as a timer and the power stops when the slider is empty after 5 seconds.

On eventbeginplay in the player controller, the widget spawns.

However, if the players are caught in the red lights, the level just reopens- there is no health system just respawn

The powers still work upon a level reopen but the sliders don’t update- that’s why I’m a little confused.

Thanks so much for trying to help, I hope this is enough info this time (sorry for the lack of beforehand ahah)

Hey, just an observation here. Progress bars run in range 0-1, so when you’re setting it to 5 at start, it’s basically 5 times over the limit. This value will be valid. Try holding down your power use key for a while longer, you will see it go down eventually.

So 0 is empty progress bar, 0.5 is half full/empty, 1 is full bar.

1 Like

Hi! The bar does work at first, but just not when the level reopens- I followed a tutorial on YouTube for the logic in which the guy sets the float value as the delta time and makes it a clamp float(?) for working with the slider- with the way it’s set up if I set it to one then it would only last one second I think? I haven’t really worked with floats and timers in widgets before tho so I genuinely appreciate any ideas so thanks so much dude!:person_bowing:

Watch the video again at time index 1:18 onwards. Could this be your problem?

1 Like

Hi sorry I forgot to mention I did normalise the value already- I’m just unsure why reopening the level is only when this issue is caused- it’s very strange :sob:

Hard to say for sure without looking over everything.
Perhaps the widget from previous level is persisting, try adding Remove All Widgets node before Open Level. You can also disconnect the pin options, it doesn’t apply here. All you need is level name for it to work.

Edit: In what mode are you running the game (SelectedViewport / Pie / Standalone). See if this also happens in Standalone, since that’s what matters in the end.

Basics of timers explained here

1 Like

Okay, mini update:

I decided to print string the float amount, and even tho the widget isn’t visually updating it is still working..?

It’s just so bizarre that it works initially when first loading the level but not when reloading the level..? I’ve never had an issue like this before it’s very strange :sob:

And the print string is AFTER the percentage update so I’m not sure how it’s doing it without updating the percentage first- my brain is fried :sob:

Strange indeed.

Only other thing that comes to mind right now would be, when level is restarted, you create two widgets, and the new one sits on top of the old one (working one). Not sure why.

You could try adding a short delay (0.1s) on widget creation too, maybe it’s a race condition.

You can verify it by adding print string after widget creation, or Get all widgets of class (pick either user widget (all widgets), or your specific widget class → WB_Gameplay)

1 Like

Okay! I did that and for some reason it is creating an extra widget each time- it’s a two player game so it spawns two initially (which is weird but it works so it’s not a big deal) but after every reopen, it spawns another for some reason??

I literally have no idea why but I really appreciate you trying to help, I would be so stuck without your help rn :sob:

1 Like

Always happy to help.

It seems like it’s a common thing, and easily overlooked.
I also noticed in the last video you keep creating an extra player controller each time the map is reloaded.
This is most likely the cause of it your issues. But I’m not sure why that would be, everything should get destroyed and re-created.
How does this work, do you manually create an extra controller (local player?). I think these might not get destroyed and if your code has logic to create an extra player each time the map is loaded, maybe that is the problem after all. Just a thought though.

1 Like

Hey dude! I removed player before reopening the level now it works perfectly, you’re such a lifesaver! :star:

Awesome! Happy to help :slight_smile:

1 Like