How to get a widget blueprint communicate to pawn
I have a NPC character who's parent class is a pawn. Attached to this character is a 3D Widget component that has a widget blueprint with two buttons. When I click on one of the buttons I want to reference the NPC character and fire off an event.
What I'm struggling to figure out is how do I reference the NPC from the blueprint graph in the UI? Attached is an image of what I'm trying to sort out. Should I make a reference to the NPC in the level blueprint? It's possible I'm going about this completely backwards, so if there's a better way to handle this I'd love some help.
asked Feb 28 '17 at 05:17 PM in Blueprint Scripting
So I managed to solve my own question (that happens when you finally ask for help...) When a button is clicked I do a "get all actors of a class" and look for my NPC's class. I know he's the only one so I can just grab the first item in a 1 item array then assign it to a variable of type reference to pawn.
Not sure if there's a better way to do this but it works. I think I will optimize somewhat by setting that pawn reference when the Widget is created.
Blueprint of what I did attached in case that helps anyone.
answered Feb 28 '17 at 11:18 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here