How do I cast to a NPC to Make It Perform An Animation?

Good evening. I was wondering how to cast to a NPC from a widget blueprint in order to have the NPC perform an animation. Specifically, I have a lip sync animation paired with some dialogue audio played through the animation’s animnotify. The widget, based on this tutorial (NPC dialog System | Tutorial | Unreal Engine 4 - YouTube), provides a list of options by which the player can respond to the NPC’s queries after the player presses F to engage with them. After the player answers each question I want to play a specific animation file. Problem is that the skeletal mesh I need to manipulate obviously isn’t in the widget blueprint but rather in a separate blueprint actor called DIAG so from what I gather I need to perform a Cast to DIAG.

And here’s the central problem: I have no idea what to connect to Cast to DIAG’s object field. Up until now I’ve been able to suffice with Get Player Character or Get Game Instance, but obviously neither of these work in regard to manipulating an NPC’s animation. Here’s the widget designer/graph and the NPC viewport/graph, respectively:

Could someone please provide a solution to this problem?

Hey there, you can create a variable in the widget called NPC and set it to type DIAG then enable Instance Editable and Expose on spawn, and compile your widget. You’ll notice that on the Create Widget node you’ll have a new NPC wire, just connect a reference to self (right click and type self) to that. After this you wont need the cast in the widget because you have a direct reference to your NPC.

Many, many thanks. This worked perfectly.

Good to know :slight_smile: