UMG widget button, click expand, click again collapse?

Hi, I’m making a simple interface, I added a button that onClick plays an animation, and I want it to play the animation in reverse the next click, and loop between these two behaviours forever? how do I do so?

Hi there,

One simple way is you can add a boolean variable to your widget blueprint to keep track of the state of the button click and then depending on that value either play the animation forward or reverse. Here’s an image showing a quick example of how you’d set it up in your widget blueprint.

It’s important that ‘Button Clicked’ is set to false by default so your animation will play forward the first time with this setup.

I hope that helps!

In addition to that, you can add a check to see if the animation is currently playing so you can reverse it’s playback mid-play. This will help with making the animation play smoothly even if the user is rapidly pressing the button (without that step it will jump to the end position of its current playback before reversing, which imo doesn’t look as polished).

Try this out and see how you like it once you get the prior bit of code working. Again, I hope this helps you achieve what you’re trying to do.

wow, that was really helpful. from that I managed to expand it to create branch menus from that button, gonna have some fun making this interface. thanks a lot!

I have the same problem, I want to create a UI widget, with a button when I click this button a new UI widget will appear ( in other words, this button will expand and give me ability to select different options).
for example, the main button called camera, when I click I want 3 buttons to appear ( cam 1 - cam 2 - cam 3 ) . could you please help with this. I searched for it but I couldn’t find it.
Thank you