Swapping Default Pawn based on a variable

Hello!

I seem to be having a bit of trouble with some gamemode related things.

I am attempting to set something up where the player will be met with a class selection screen where they can pick their class. (Lets say its Wizard, Barbarian, and Assassin for now)
That class will then be saved into the Game Instance and into their save slot so that every time they open that save they will still be playing the same class.
(ex: Save 1 i picked wizard so when I boot up save 1 again I am still playing wizard)

The saving within the slots/instance works fine. Loading those actual variables works fine, etc

However I am running into a very specific issue:
I built a parent class with all of the core stuff I want to have on each of my classes, and then I made children classes that are unique and do their own thing.
The children classes work fine, but I cannot figure out how to make the game spawn the appropriate class for that save. For the current development phase Ive just been swapping out the default pawn within the GameMode settings manually, but of course that doesnt work for an actual player.
I have tried adding stuff into the GameMode blueprint that basically says:
On begin play, swap the default pawn to “Wizard”
But it keeps just spawning the class I have as the default

How can I make it so when the player spawns into their save it spawns the appropriate class instead of just the default parent class?
I know its possible in blueprints, I just am not sure how

At a glance, just in case you missed it…

When you spawn a new pawn that you want to use as your player character you need to “Possess” it with your controller.

In the past, when doing this almost exact thing I have not set a default player pawn but instead on game begin spawn the pawn class you want and then using the possess function to assign it to your controller has worked fine for me.

If the problem persists beyond that show us a little bit of your script and we might be able get a better understanding of what is happening.

Awesome! I will look into this and see if I can’t find a fix this way. If not I’ll pile in whatever code I believe is relevant to it so you guys can get a good idea of what’s happening so far.

Thank you so much! Ill update you in a moment!

Okay so I tinkered with your suggestion and that honestly works great.

I just set it up inside the GameMode so that it will spawn in one of the classes, and then it will possess that class using the controller.

SUPER simple, and I love it.
My second class seems to be working as intended as well.

Thank you SO much, that was a massive help. Ive been banging my head against this for forever. I had no idea possessing even existed.

Heres the code I made per your suggestion, let me know if you have any additional suggestions to improve it:

1 Like

From a high level, that’s it really as the basis for what you were after and the basis for any multi character system, sometimes it’s easy to miss the simple things.

From there you can then get as fancy as you want even being able to swap characters mid game and turn the others into A.I. companions, the world is yours to “Possess”!