Choose class to play as from Main Menu?

Hello all, now that I think most people are back from Holidays I wanted to go ahead and ask how to approach this problem I’m having.

I have a Main Menu with a New Game button. Press the New Game button and it leads you to a screen where you can choose 1 of 4 different character pawns to play as. Once you choose a class and then press Start, it loads a different level.

What I want is when you choose a class, it sets the default pawn class that the player plays as in the game mode, this game mode is then used throughout the rest of the game. I thought this would be the best solution to use for character selection, but I haven’t been able to get it working yet.

Here’s what I have so far:


The problem is that this doesn’t select the character to play as when the next level loads like I thought it would. I was experimenting and I thought you could just change the default pawn class used in the game mode and that will determine what class the player plays as (in this case it’s the Fighter, Cleric, Mage, or Ranger).

Any help or ideas would be quite nice :slight_smile: Thank you.

i have a class system that i setup in code but its a little different from yours, the only time the default pawn determines the class is at the start, after that your selected class is stored in your player controller and whenever the map changes or a player dies the playercontroller checks if it has a body if not it asks the gamemode to spawn it a body matching its class then the gamemode tells the playercontroller to posses it

I think I know what you’re saying, well in that case changing default pawn will not work - I wish it would because it seems intuitive to me but there must be a different way. So how to tell player controller to possess a different character?

to take control of a different character you have to use the “Possess” node in blueprint, to give a example on what i did it rigged up a decent copy of how i was doing it as an example.

this image is only an example to branch from im short on time so i put it together pretty fast and it has an error but it shows off the key nodes and the order of operations i used


switch reads playerclass string from the playercontroller, and based on what is stored in it spawns the appropriate actor. Once the actor is spawned i verify that it is valid then i tell the player controller to possess the new body.

Ok great, I understand this. There still is one more issue though. How can I communicate from my widget blueprint to my level blueprint? When the player chooses a class by clicking the button I need to tell the next level to spawn the appropriate class and then possess. The blueprint stuff you have above is in my level blueprint (the destination level after the player presses start on the character selection screen).

In my widget blueprint I have an integer public variable called Class Chooser. This is the variable that determines which class the player wants to play as when the player clicks on a class button very similar to your switch on string…im just switching on int instead. I need to send the value of this variable to the level blueprint when play begins for the level.

I’m thinking there are two ways, both of which I can’t quite get working:

  1. Casting to Widget Blueprint from Level Blueprint. Problem is that I don’t have an instance of my widget. The widget gets spawned in the main menu level blueprint by the way…

  2. Get all actors of class. Problem here is that I can’t seem to find my widget blueprint class in the available classes to choose from. So it won’t let me search for it.

Just need this last piece to bring it all together :slight_smile:

Hey admiral, the level blueprint doesnt persist when changing levels. You will have to store any information you want to transfer across levels in a persistant class, such as gameinstance, or the playercontroller (assuming it doesn’t change)

Hahaha…admiral that is pretty funny. Do even admirals face severe problems everyday in development? They probably do :stuck_out_tongue: :stuck_out_tongue:

What you said was very helpful, game instance makes sense. Will I need to create my own custom game instance blueprint for that? This challenge is forcing me into new areas that I haven’t worked with before.

Yup you will need to make a gameinstance blueprint, but it is super easy to work with. Make sure you go into your project settings and set it to use your created gameinstance. (edit, project settings, maps and modes, gameinstance; and pick your created one)

You can use the gameinstance you make as a place to just store variables. You can leave the event graph of it completely empty if you want. Right before you open a new level, use a cast to gameinstance node, sling any variables you want into it real fast (make sure you set them public, click the closed eye to the right of the variable name), and set them in whatever blueprint you want. (level bp, character, pawn, whatever). When you open up up a level, you can have that level’s blueprint on event begin play, cast again to the gameinstance, and this time get any variables you need.

Heres an example. The stuff in the top comment box would go in the level where you save the variables, and the bottom one would go in the level you open up. In this case I called my gameinstance class TESTgameinstance, you have to cast to the name of your custom one, and not the default.


The gameinstance and all its variables live as long as the game stays running.

Yes!!! I got it working now Thank you!!! :smiley: :smiley:

That is the solution. Thank you all.