I am starting out with a fresh Third Person project with Starter Content. I created two custom Game Modes (one BP, one C++) that spawn each player at different Player Starts. Sample C++ (BP does the exact same thing):
DeathMatch.h:
UCLASS()
class BALLOONO_API ADeathMatch : public AGameMode
{
GENERATED_BODY()
ADeathMatch(const FObjectInitializer& ObjectInitializer);
virtual AActor* ChoosePlayerStart_Implementation(AController* Player) override;
};
DeathMatch.cpp:
ADeathMatch::ADeathMatch(const FObjectInitializer& ObjectInitializer)
{
TSubclassOf<class APawn> defaultPawn;
static ConstructorHelpers::FObjectFinder<UBlueprint> PawnBlueprint(TEXT("Blueprint'/Game/Game/Bomber.Bomber'"));
if (PawnBlueprint.Object)
{
defaultPawn = (UClass*)PawnBlueprint.Object->GeneratedClass;
}
if(defaultPawn)
DefaultPawnClass = defaultPawn;
}
AActor* ADeathMatch::ChoosePlayerStart_Implementation(AController* Player)
{
for (TActorIterator<APlayerStart> ActorItr(GetWorld()); ActorItr; ++ActorItr)
{
auto playerStart = *ActorItr;
if (!playerStart->ActorHasTag("Taken"))
{
playerStart->Tags.Add("Taken");
return playerStart;
}
}
return nullptr;
}
With the default Third Person level, I deleted the player and added several Player Start Actors. Testing the level shows each player spawning at each Player Start, awesome.
However this breaks on a new Level. After creating the new level, I setup 4 Player Start Actors. I set my Game Mode, and my Default Pawn Class. When the Default Pawn Class is one that I created or ThirdPersonCharacter, it spawns the camera at 0,0,0 (or uses a Camera that I place) but no Actor. This was additionally tested with a BP equivalent, using the Blueprint version of ThirdPersonCharacter.
Selecting SpectatorPawn does work, and the players can fly around. Additionally, the same Game Mode applied to a default Side Scroller project (with 4 Player Starts) creates 1 visible Pawn and 3 invisible Pawns, although the invisible ones can still play, collide, etc…
How can I get my Pawns to properly spawn?