Change Skeletal Mesh based on Player selection

Rather simple task, but having trouble wrapping my head around it:
I want the player to be able to select the the vehicle they want before a race.
the idea so far is to:

  • save the selection to their gameinstance,
  • load the level
  • change the skeletal mesh and animation of the pawn once the level loads.
    my problem is this:

AFESPawn::AFESPawn(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
// Car mesh
static ConstructorHelpers::FObjectFinder CarMesh(TEXT("/Game/Vehicle/Sedan/Sedan_SkelMesh.Sedan_SkelMesh"));
GetMesh()->SetSkeletalMesh(CarMesh.Object);

static ConstructorHelpers::FClassFinder<UObject> AnimBPClass(TEXT("/Game/Vehicle/Sedan/Sedan_AnimBP"));
GetMesh()->SetAnimInstanceClass(AnimBPClass.Class);

(Pulled from the Vehicle C++ starter project pawn code)

When it does the FClassFinder and then loads the mesh from a string, how would i go about generating that string at run time? My first guess is to make a enum to represent all possible vehicles, then load the respective string paths of all possible vehicles and pass that in…

Note: I trying to make a multiplayer project, so if this would break a networked game, maybe you could point me in the right direction?

Hey zlz_showtime,

I’d create a base class vehicle pawn and base blueprint vehicle pawns upon it trying to get as much done in c++ as possible. In the base class you might want to have things like the vehicle name etc.

In the GameMode class I’d add a function for registering a new vehicle. On game start (you probably wanna start out in a menu, otherwise it won’t be doable or you have some default configured anywhere) you configure in the blueprint of each vehicle to register itself. you can also put that in the parent class but remember to call the registration of the superclass in the derived BP’s. Then you place all those vehicle pawns in the menu and let the player choose. When transitioning to the GameMode where the player actually plays you just initialize that game mode with that parameter.

I hope that helps or at least gives you some ideas.

Regards

Lukas Wagner