GameHasEnded Question


void AKillEmAllGameMode::EndGame(bool bIsPlayerWinner) 
{
    for (AController* Controller : TActorRange<AController>(GetWorld()))
    {
        bool bIsWinner = Controller->IsPlayerController() == bIsPlayerWinner;
        Controller->GameHasEnded(Controller->GetPawn(), bIsWinner);
    }
}

I have a question about the EndGame here. It is mentioned that we need to notify all the controllers that the game is ended instead of just telling the player controller. I wonder why we need to also call GameHasEnded of the AI controller? It seems we are not doing anything to the AI controllers when the game ended.

This is how I understand it:
When the player is dead, we call EndGame(false). It loops for all the controllers and call GameHasEnded serveral times depends on how many controllers are left. So player controller will call GameHasEnded(player pawn, false), while AI controller will call GameHasEnded(AI pawn, true).
What about the EndGameFocus? Since both player controller and AI controller call GameHasEnded, what should be the view target?

I don’t know if I understand it correctly… this is quite confusing to me…
Thanks for help in advance.

After looking at the code. It doesn’t do anything, this is literally it

void AController::GameHasEnded(AActor* EndGameFocus, bool bIsWinner)
{
}

APlayerController overrides it do

void APlayerController::GameHasEnded(AActor* EndGameFocus, bool bIsWinner)
{
	// and transition to the game ended state
	SetViewTarget(EndGameFocus);
	ClientGameEnded(EndGameFocus, bIsWinner);
}

AAIController does not override it. @sampattuzzi, maybe you should add a note about this?

I’m more for future proofing. We may well want to do something with the AI at this point.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms