I want to be able to press a Widget button(HUD) and that buttons plays an animation to a static character, I know how to play the animation on Keybind, which is easy, but for some reason I cant replicate it to widget…
Hi, widget communication can be a bit tricky. I’m assuming you have a separate blueprint for your widget and a blueprint one for animating your character? You could use an event dispatcher or if you want to keep it very simple you could set a variable in your widget blueprint on button press. You can then check whether that variable changes in your animation blueprint at which point you can execute your animation.
Thanks for the replies I figured out a solution!
My approach is usually either event dispatcher or find the character.
The widget doesnt know about your character until you tell it which object is your character.
You can do this several ways:
- If the character is the player then simply use GetPlayerPawn at index 0
- if the character is not a player then you need to determine which character is the one the button should affect. Ome way is to have the one it should affect create the button widget and the pawn assign itself as the owner. Then the widget can get its owner and cast to the right.blueprint class and play the animation.
- another way is to specify which character by line trace for example to see which one is being looked at by the player.
- instance editable can select an actor placed in the level and widget refers to that actor to play animation on
Use of blueprint interfaces can avoid having to cast to specific BP class
Great! I’m curious; what did you decide to do?
What I did was quite simple, I just got all actors of class into the HUD and used the static character and had an array or so to link it to the play animation, so when I hit the button on the HUD widget it just plays the animation where the static character was placed. I basically just played around as I am not good at blueprinting or creating custom events and so on, but basically what I needed was really simple.
Cool So how does it know to make that specific character play the animation and not all the other ones returned in the array from the [Get All Actors of Class] node?
I don’t know really, I got the character “blueprint actor” referenced into widget somehow which I had problems with before just changing on stuff I dont remember
Is “blueprint actor” the name of your character?
How did you solve this, been trying for awhile?