In-Game Squad Selection Menu

Hi, tried for the past few days but just going round in circles so thought it’s time to ask for help :slight_smile:

I’m trying to implement an in-game squad menu. Basically click on a 1 to 4 button to select member 1 to 4 and take control of that character.

I’m basically trying to set the character to selected (active) if the user clicks on the squad button. I’ve binded the button to the selected variable via a TargetBlueprint but the button is no longer selectable. I’ve tried putting the variable in both controller and character BP.

What am I doing wrong? (apart from everything ha)

EDIT: Tried with possessing pawns but can’t see where I can assign each character to a button as each character links to the same BP

Hmm, I’m not sure that I fully understand your current setup, but I think I understand your problem. Just to make sure, it sounds like your problem is that you don’t know how to implement the logic of “If I click this button, I want it to possess this character”. I would store all of the pawns in an array then just have each button set their own index that returns the pawn from the array. So, an example would be:

  1. Click the first button.

  2. Set Index variable to 0.

  3. Get Pawn array with Index variable

  4. Run your possess function.

Does that make sense? If not, I’m happy to provide a screenshot or answer the question again if I answered the wrong part. Oh, and as for how to setup the array, I would just have it accessible from the Player Controller for now (it’s easiest to access if you are just beginning). Once you have more experience, you can always move it to another blueprint that makes more sense. Either way, I would just have an Event Begin Play function in each pawn that has it store a reference of Self to the array.

Good luck!

Yeah you understood the gist :slight_smile: What you suggest makes sense to me, I’ll give it a whirl. Thank you.

I also had a brain freeze about pawns/chars so you’ve also knocked that back online

I’ll keep this question open for the moment just in case I need more help but you’ve put me on the right track.

Back again. Sadly I can’t get my head around it.

I’ve got my Top Down Controller BP and 4 Character BPs (1-4). I’ve tried to make an array in the Controller BP but I can’t access it in the UMG Widget BP even when I set the controller BP to target. Though I’m not too sure if I’ve set the array up right anyway.

If you could you provide me with a screenshot that would be great.

Not a problem! It sounds like you are having the same problem I had when I first started, which is that you don’t know how to access other Blueprints. I nearly pulled my hair out figuring it out 13 months ago. In general, anytime you want to reference another Blueprint, you have to Cast it. If you don’t have to, the compiler will let you know immediately (as of 4.8.0) that it is unnecessary. However, it won’t hurt if you don’t cast it even if you don’t have to.

I’ve included a couple of sample screenshots that should help you out. If you need anymore detail, definitely don’t hesitate to ask. I know it’s difficult to wrap your head around at first. Note, the screenshots are a little simplified version, but it will answer your question. Get that running then you can add that extra logic that will make the data easier to manage. For now, just focus on getting it up and running.

alt text

Thanks for this Element. Will give it a go and report back, hopefully with success this time. I appreciate the time and effort you given this :slight_smile:

Hi, Tafkatfos. Did this end up working for you?

Hi, sadly it’s not. Though I don’t think the problem is your solution, just my lack of understanding. You mentioned Event Begin Play function in each character that has it store a reference of Self to the array. I’m struggling to do even that. I have put what you’ve suggested in, just attempting that event play bit.

No problem! I remember it being difficult for me too at first. So, you’ll want to right-click in the Event Graph of your pawn’s blueprint and type Event Begin Play. It will spawn a red node that you can connect to the nodes I included in my Addingpawnstoarray.png. This will cause your pawns to be added automatically to the Pawns array managed by the controller at the start of each run. This will allow you to use the array like I mentioned in Widget Reference.png.

Element I really appreciate your patience!

Right, story so far…

I’ve added the addpawns to the each of the 2 char BP - can’t ref Self node though
I’ve added the widgetref to the UMG widget, on both buttons (along with GET being 0 and 1)

When I play, the second char is always controlled, clicking the menu buttons has no effect in swapping controller to char 1

Obviously I’m missed something important (self node?) but can’t get my head around it…I had it working GMS engine with selected variables, but trying to convert it into UE4 is scratching my head!

Ah, yep, sounds like you just need that self reference. So, within the pawn’s blueprint, just right-click and type “Self.” Only one item should be listed called “Get a reference to self.” Just attach that to the array and you should be good to go if everything else is setup properly!

Already tried, says “Self Reference is not compatible with Top Down Controller Reference (by ref)”

Actually what variable type should my array be by the way?

Hmm, can you provide a screenshot? Looks like you may be trying to connect it to the wrong thing.

alt text

before and after pics. need anything else let me know.

Looks like your array is not the appropriate variable type. Just go to your Blueprint array and set the Grunt Array variable to either “Pawns” or whatever Blueprint the Grunts are made from.

yeah changed it to characters, all good now. thank you.

edit: noticed that I had to delete the ADD and GET so the new array type worked…now I understand why it didn’t work last time when I changed the type. Lesson learned!

Sadly clicking the menu buttons doesn’t have any affect over which character is controlled. I’ll continue plucking away!

edit2: the array is working as I did print string after the add and 0 & 1 are displaying.

Right got it working, I’ve added the possess function to the menu. Is this setup ok or will it cause problems?

Congrats on getting it up and running! That looks perfect! As you build onto your game you can always add some improvements (such as storing the controlling after casting it and just referencing that new variable, logic if the character should be possessed right now, etc.). Don’t worry about getting it all right and optimized right now though. That stuff will come with time!

Thank you very much for your time, effort and patience! Much appreciated Element :slight_smile: