How can I play a widget's animation through a key press?

Hello, i would like to know how to play a widget’s animation through a key press.
Thank you

Easy. Inside your Player Controller blueprint, create/spawn the widget object that contains the animation you want to play, and then do the usual stuff to add it to the viewport. You should promote your widget object to a variable so you can access it when your key is pressed.

Also inside your Player Controller blueprint, set up your key press event. During that event, execute a Play Animation node on your widget variable. You can specify which animation you want to play, adjust playback speed, etc.

Hello, thank you for your reply!
But I cannot add the variable to the play animation node, it won’t let me

From the widget variable drag out a wire and search for “play animation”. Once you have that node go back to the widget variable and drag a second wire out and search for whatever you named your animation. Now connect the animation variable to the play animation node and it should create the link.

Hello, thank you for your reply! But It does not work, if I drag out a wire from the variable and search for play animation nothing comes up

Then first pull the animation out of the widget variable. Then drag from the animation variable and search for play animation. This is just a context issue. If you uncheck the context sensitive box you’d get the node no matter what you pulled from.

What kind of variable are you dealing with? What’s its type? It should be the type of your custom widget blueprint. This should be the variable that you set right after using the Create Widget node.

Otherwise, if that’s not the problem, have you checked to make sure your animation is public? If I recall correctly, it should be public by default, but it can’t hurt to look.

Assuming your animation is public, you should be able to find it from your widget’s pin if you look under Variables → Animations.

If you’re still having trouble, I’ll post a screenshot this evening when I next get a chance to fire up the engine.

Hello, thank you for your reply! The variable type is user interface. In my widget I checked if the animation was public; it said it was public but missing tooltip

Hello, thank you for your reply! I followed the steps and got the variable, now I can create a play animation node from the variable but I still cannot select an animation from the “In Animation” drop down menu

When you create your widget, right click on the return mode and promote to variable this will ensure you have the correct variable type. Then follow my previous comment directions and you should be good.

Until I get a chance to open the engine and show you what I mean with screenshots, please read this article on the UE4 official docs: Creating and Displaying UI

You don’t need to reproduce every detail shown in that article for your project, but you should make sure you completely understand all of it.

The variable you need in your Player Controller blueprint is the one you promote out of the right side of the Create Widget node. This is demonstrated by Step 10 in the linked article.

Once you have your variable, accessing its animations should be a breeze.

You should drag two pins out from your widget variable. The first goes into the Play Animation node, which you already figured out. Use a second pin to access the widget’s animations, which are treated like variables. Look under Variables → Animations

Thank you so much for your help! It worked, thank you!