So basically, I’ve got one pawn blueprint that I have duplicated 12 times and placed through out my level. I’ve got a general idea for possessing at least one of them, but so far that’s it. My thought was to give it an editable variable, like an integer or an enumeration that could be assigned either in the world or when the player interacts with one of them individually, but I cannot for the life of me figure out how to make a cast specific to the pawn I want with something like a button press in a widget. I would like to know if there is perhaps a node or something that I could use to reference them for other purposes as well, like checking if they are available to be possessed based on an a boolean I gave to the pawn already.
the pawn I want with something like a
button press in a widget
How will it look in from the player’s perspective? 12 Pawns and 12 buttons? How do I know which button is hooked to which Pawn? Each pawn has a separate button?
12 pawns and 12 buttons, yes. The umg basically has 12 small buttons to the bottom right of the screen and each are labeled based on where the pawn is located (I.E. Back Yard, Upstairs, etc) Each time a button is clicked would be when I want to cast the possession to whichever pawn is in that location (if it succeeds its boolean check as “active” based on previous player input.)
Makes sense.
And the Pawns themselves? Are they manually placed in the level? You spawn them dynamically? Are there always going to be 12?
And the widget that holds the buttons? Created in the Level Blueprint, Player Controller or?
Asking questions so I can tailor a specific answer.
Thank you so much for taking the time to help me, this might work perfectly for what I need. I’m going to try to implement it now and come back if I run into any issues, but so far it looks like this will work.
Here’s a solution that may work for you:
The pawn has an instance editable int ID (as suggested) and a custom event:
Do ensure that each Pawn instance has a unique number.
The widget keeps the buttons in an array:
In the blueprint that creates the widget:
Okay I’m messing with this a little bit and I think this is exactly what I was missing, I can’t thank you enough. For future reference, is there a way to run a check for that ID variable individually? Im not sure if I worded that right but basically, I want to add a boolean at the beginning of the possession event that checks if the player has essentially walked up and interacted with a specific pawn (based on a custom interaction event already in place) so if the player hasn’t interacted with that pawn, the text for it’s specific button would return differently and say something like “Inactive” or perhaps toggle the visibility of that specific button all together?
For future reference
Tbh, I’d approach the whole thing slightly differently. I’d make it less rigid, more modular.
Consider the following:
- create a new widget that has a button and text inside
- each pawn creates and stores a reference to its own button widget
- when the game starts, pawns add their buttons to a panel (bottom right corner)
The reasoning behind this appraoch:
- this way each Pawn has direct access to its own button and each button can talk back directly to the Pawn
- if you ever want to modify the way the buttons look or behave, you do not need to do it 12 times (since the button is a separate widget now)
- you can have as many or as few Pawns as you want
- each button can have a fancy animation / additional functionality if needed
On the other hand, if I needed to script something along the lines you’ve described, I’d do it like so:
In the Pawn:
ButtonSetup is a custom event that grants the Pawn a direct access to the button (so the Pawn can talk back to the button and updated its text, for example).
The wMyButton is of Button type - a new variable currently pointing at nothing, it’s fed the appropriate reference in the second screenshot.
You mentioned you have Active / Inactive mechanic already in place; the UpdatePawnAvailability is how you could ask the Pawn to update a button. I here assumed that your buttons have nothing but a single text block inside. You can use it to enable / disable button instead.
And at Begin Play:
While a wee bit clunky, it should actually work ok.
Interesting. So this in particular didn’t end up working for me specifically, but it definitely put me on the right track. I’ve currently got the system working more or less how I wanted it. Basically I created a binding for the text in the widget that checked for the buttons corresponding pawn ID followed by its boolean. It could probably stand to be cleaned up, but I’m at least on the right track now thanks to you. You’re right though, something modular would probably benefit me in the future, but for right now I’m kinda just trying to throw a proof of concept together so that’ll be a problem for future me haha. I cannot thank you enough for taking the time to give me such thought out responses, especially considering I wasn’t entirely sure I was communicating what I wanted properly. I was stuck for quite some time trying to figure out how to make all of this communicate properly, so your suggestion of making an array for the buttons and linking it to the ID variable was essentially exactly what I needed. I think I’ve got a little bit better understanding now of how to handle arrays and loop nodes, which was something I needed. Something about how you put it together and worded it just clicked with me.