Swapping Playable charcters

Hi all first time posting,

I’m in the middle of a uni project and am looking for some help in swapping playable characters on the fly (think The Lost Vikings on Sega Megadrive)

Want to get a character swap on the 1,2 and 3 keys. Never done anything like this before as all my character select has been done through a select screen at the start, never on the fly.

Any help appreciated and thank you in advance.

#include “World.h”

void yourclass::SwitchCharacter(APawn* NewPawn)
{
 	APlayerController* PC = Cast<APlayerController>(GetWorld()->GetFirstPlayerController()); //Might not work in multiplayer

	if (PC != nullptr)
	{
		PC->Possess(NewPawn); //Pawn is your player character
   }
}

This will let you switch between player characters. And you might need to check for GetWorld() pointer validity.