I’m trying to call a function from the player controller blueprint by pressing a button in a widget, but I have no idea how to do this. I have a OnClicked function in the widget blueprint where I want to call the function “LineUp” from the player controller:
Thanks for any help:)
On your widget you would need a reference to the Player Controller. This is usually achieved by using Get Player Controller node.
Then cast the Player Controller to your custom class. After the cast you can call the Line Up function.
Hi LupenWonse, thanks for your answer. I’ve tried your suggestion but it doesn’t work:( the cast fails. If I would reference a blueprint, other than the player controller, what would i put as the Object input?
Well if the cast fails than your current player controller is not using your custom class. See this page under Game Mode which explains how to setup a custom controller for your game,
If, however, you would like to reference another blueprint, you would need to somehow store a reference to the object in question. You can do that by defining a variable in your Widget and manually assigning it. Otherwise it is possible to find actors in your level, here is the docs
oh I forgot to assign the custom player controller, thanks a lot mate you really helped me:)