Download

How does GameMode::RestartPlayer(AController* NewPlayer) work?

I saw this code in project EpicSurvivalGameSeries

https://github.com/tomlooman/EpicSurvivalGameSeries/blob/master/SurvivalGame/Source/SurvivalGame/Private/World/SGameMode.cpp#L281


void ASGameMode::SpawnNewBot()
{
	FActorSpawnParameters SpawnInfo;
	SpawnInfo.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AdjustIfPossibleButAlwaysSpawn;

	ASZombieAIController* AIC = GetWorld()->SpawnActor<ASZombieAIController>(SpawnInfo);
	RestartPlayer(AIC);
}

https://github.com/tomlooman/EpicSurvivalGameSeries/blob/master/SurvivalGame/Source/SurvivalGame/Private/AI/SZombieAIController.cpp#L30


void ASZombieAIController::Possess(class APawn* InPawn)
{
	Super::Possess(InPawn);

	ASZombieCharacter* ZombieBot = Cast<ASZombieCharacter>(InPawn);
	if (ZombieBot)
	{
		if (ZombieBot->BehaviorTree->BlackboardAsset)
		{
			BlackboardComp->InitializeBlackboard(*ZombieBot->BehaviorTree->BlackboardAsset);

			/* Make sure the Blackboard has the type of bot we possessed */
			SetBlackboardBotType(ZombieBot->BotType);
		}

		BehaviorComp->StartTree(*ZombieBot->BehaviorTree);
	}
}

I debug with these code, I found that when invoke RestartPlayer(AIC);, it will trigger function ASZombieAIController::Possess(class APawn InPawn)*, I can understand this, but what I can’t understand is that an Pawn ASZombieCharacter assign to InPawn which is parameter of ASZombieAIController::Possess(), and I didn’t find any handle about this assigning in project.