Struggling to make a "character selection" option work

Hi, pretty new to actually trying out game development. After about 2 months I’ve decided to take a “course guided” game that I followed in making and use what I’ve learned to try to expand and add more features. The game is a simple isometric viewed shooter where you shoot waves of enemies until overrun. It only has one class (Machine gun) and I wanted to add the option to choose different classes (Shotgun & Grenade Launcher). I added 3 buttons on the Menu UI that you click to change your character and set it up so when you click them they will toggle the visibility to make it so the character you pick is visible, and the other 2 options become invisible. Then when you start the game it’ll load into the map with the character you’ve chosen.


I originally started by having the visibility toggling happen in the level blueprint since I could easily reference the character models’ blueprints and wouldn’t need to cast or use interfaces, but came to the conclusion you can’t really send info to the level blueprint, only from. I had a Blueprint Interface setup so depending on which of the 3 you chose, it would fire off a different function with the goal destination being the level blueprint, but couldn’t find a way to successfully set the level blueprint as the target destination. So I decided to try to have this instead end up happening in the game mode blueprint. Since I couldn’t just reference the BP’s I needed, I was simply going to use casts since, while it is more resource intensive, nothing else was really happening in the main menu level and after pressing start it was going to load up a different map. So I figured it would be reasonable to just cast in this case.


But now I’m having the issue of not being able to find what to link in the “object” node on the cast function. I can’t really figure out what I would need to plug in here to get the function to work correctly? I was under the assumption that by casting you would be choosing the destination automatically, and am at a loss as to what I would need to use to make this work. What do I need to plug in here?

Also if you can think of a different way to do this that’s more efficient/less resource intensive let me know. I’m still learning and am open to finding out more efficient/different ways to do things.

Also not sure if it’s important to note but the Blueprints I’m trying to cast to are child Blueprints of another class.

You need to pass an actor reference to the Object parameter in the cast node for it to work, then you have to do something with the As… out parameter:
image

I would try a different approach, one that allows more flexibility in case you want to add / remove characters and specifics.

Something like this, for example:

  1. Might be better to have a data table with a soft reference to the weapon + text to display in the button for that weapon. This data table could be loaded in the widget and assign a row to each button, adding as much buttons as there are rows.

  2. The widget could be split into the main menu with a WrapBox component and another widget with the buttons.

Hope it helps.
Hope it helps.

  • We need a way to know when the button has been clicked. For this we can create a dispatcher to also pass the info that was assigned from the data table:

  • For the parent menu widget we need to create a button for every data table row and assign each the data from the corresponding row; bind the button distable to an event, this event will tell the selected pawn to spawn the weapon.

  1. We use an interface to pass data to our pawn in case we want different pawns and not have to cast to each. The interface needs a input parameter to pass the weapon soft reference… and that is all there is to it:


    You can add as many functions as you need.

  2. On our pawn, after adding the interface we implement the logic that sets the weapon:

This is the result:
WeaponSelector


I know this is not what you asked for specifically and it does not directly address your issue, but…