Download

Local Multiplayer Class Spawner

I apologize if this has already been answered, I did a bit of searching and couldn’t find a working solution.

I have a class called AJGeneric that derives from BasePony. Right now, in my gamemode stg_battle.cpp, I have:


DefaultPawnClass = AAJGeneric::StaticClass();

This works for spawning 1 player. However, default isn’t going to work in this case, as we need to spawn up to 4 players. I tried this:


GEngine->GameViewport->CreateLocalPlayer(0, FString("Error."), true);

Obviously, I have no idea what that bit of code does. I also tried:


void Astg_battle::BeginPlay() {
	Super::BeginPlay();
	UWorld* const World = GetWorld();

	if (World){
		World->SpawnActor<AAJGeneric>(AAJGeneric::StaticClass());
	}
}

Which did nothing but spawn a broken AJGeneric class.

What is the best way to spawn in players by code?