Download

Possess a pawn with widget button

Hi,

I know this is very simple but I can’t figure out how to do this…

I have a widget menu with buttons. I want one button to let me possess another pawn in the level.

How to make the widget bp to ‘communicate’ with the level bp ?

I’m sure there’s a way to do this. Hope you can help!

Hi @eetukasperi

Just use your widget
The node possess need a pawn and a player controller
Get a reference to the pawn using , get all actor of class, or triggerboxes, or pass it to the widdget and set the player you want to possess it

Level bluprint is not made for “communicate” easy.
Is planned to be used with level behaviour , or stuff like that.

Yes, the most important thing is to get a good understanding of references. Getting them can be tricky at times, but what I like to do as soon as I spawn anything(actors, widget and so on) is to store it as a referennce variable inside of the blueprint that spawns it. That way you can reach out from another BP to get that reference. And also - use “Is valid”-checks alot to see if the reference is solid otherwise you will get warnings and weird behavior.

If you are gonna be switching characters alot while having the pawns in the level, consider making a character switching bp that you can drop in the level that stores references to the different pawns. If you make the references instance editable then you can use the eye-dropper tool to select them.

If you give more information on what you have in mind we can help you further :slight_smile:

Thank you guys for responding!

Still trying to get it to work though…

I tried this, but the button doesn’t do anything. Am I missing something ? (Widget BP)

847b13043e9d4a73c0e49de9c470acb09509a4ed.png
https://forums.unrealengine.com/core/image/gif;base64

I made a Player Controller BP (PlayerSwapper) to store the Object References of the Pawns ( Player_1 & Player_2 ). (Widget BP) - No effect.

7f5620294324d022e07f698ef430be66713a88f6.png

Here are the object references:

2a7092ba75e705172351439ed7b3f48a3bee2212.png

I think you just need to pin out the Array of the node “get all actor of class” and use the node “Get” to get the reference to just 1 and plug it in the “Possess” node. at the inPawn.
If you have like 10 pawn in game, the get all actor of class will give you a list of 10.
Using Get 0, will give you always the first found , if you want to possess specific pawn you have to choose how.
For randomize you can pin out the array and select “lenght” this will give you the number of pawn in the list,
add a “Random integer from range” and plug the lenght result in to the max.
Now everytime you hit posses, he will cast a randdom number and try to possess that pawn in the list

Get actor of class will release you a list of actor (see the icon of the 8 squared dots in blue?)
you have to pick up one from the list, and use it , to posssess it.

Okay, now it works! Thank you!