Reset a UMG widget

Hello,

I have a umg widget with the main menu for my game. When you open it, you’ll see options: Continue, Exit (yes, that simple). When you hover over an item - it slightly increases its width, and when you hover out - decreases. All it’s done by means of animations.

Now, when you click on Continue - the widget disappears and you continue to play the game. BUT, when you summon the menu back - it will show up with Continue button with increased width. This is due to the fact, that reverse animation hasn’t played back and the button in its hover state.
You can see the behavior on the gif here:

[Gif with the menu in action][2]

Now the question: how do I reset the widget, so when I open it again, the buttons would be in their initial states?
For now, I think I can create a widget each time, a user pressed Esc - but that is definitely not a solution.

Thanks!

1 Like

First what i thinking - get your animation variable, and play it reverse with start time of full length of animation (or zero, i dunno from where it counts time). Set time to 0 posted by anonymous | blueprintUE | PasteBin For Unreal Engine 4

1 Like

how about doing this when player closes widget? As far as i can tell you storing your widget somewhere, not destroying it - this why it happens, then you can make this animation play when player doesn’t see it. Also, this blueprint above should immediatly set it to start, equals to “Set animation time to 0”, have you tried exactly it?

Thanks!
Yes, I tried similar to that.
The issue here is that the reverse animation is still visible when you open the widget. You see how the button is getting back to its initial state. And I would prefer that the button should be in the initial state right away w/o any animations

I don’t think this is going to work. When you close a widget it does not play animations.

What kind of animation are you doing? If you animate the render transform scale, maybe you can set this value to the default value with clicking on continue (or at reopening the menue)

I animate the value of SizeX (Canvas Slot IIRC). I will try that. Thanks

I actually thought that there are some more straightforward solutions like for instance: Widget->ResetWidget

That’s what I do in my workaround - but I am afraid that it affects the performance, because who knows how many times a user will bring up the main menu. All these widgets are going to stay in memory, no?

what about playing it before closing widget? I don’t know your code, but something like:
Esc → Play animation above → remove from parent, is that gonna work?

also, why you wouldn’t create new copy of widget, instead of opening old one?

Hello,
I think it’s better to keep them hidden rather then destroy and creating them all the time. That way you can still run things in the background if you need to.

I just tried to do this and I had a problem when my button would be stretched when creating a widget but I got it fixed quick time, just had to double check the offset values on my animation. Anyways you should keep your widget hidden and just play the animation backwards behind the screen if nothing else works.

Select your animation and then button and double check offset values at the start and end of the animation.

I can make some screenshots if needed.

I recreated that logic i described and it worked:
Widget logic: Widget logic posted by anonymous | blueprintUE | PasteBin For Unreal Engine 4
Widget switcher: Switcher posted by anonymous | blueprintUE | PasteBin For Unreal Engine 4
(sorry for the mess)

Pretty much the same thing as @SpynderYT just less messy. :stuck_out_tongue:

Thanks, will try that!

Just tried that. It does not work, unfortunately :frowning: the animation does not play when the widget is not displayed. It sort of postponed. When I bring up the widget back - it finishes the animation
This is the code for the widget continue button click event

This, sort of, works. Don’t really like it - offset is hardcoded.

Thanks! Seems like it is working now!
These 2 notes are important

  1. Call the “Play Animation” node with “Reverse” parameter, and set time to End time of animation.

  2. Call the “Play Animation” node BEFORE everything else, so it’ll fire before closing.

I know I’m years late to this, but my solution was to play in reverse with an enormous value for the playback speed so that it effectively only took one frame to jump back.