void AController::Possess(APawn* InPawn) { REDIRECT_ACTOR_TO_VLOG(InPawn, this); if (InPawn != NULL) { if (GetPawn() && GetPawn() != InPawn) { UnPossess(); } if (InPawn->Controller != NULL) { InPawn->Controller->UnPossess(); } InPawn->PossessedBy(this); SetPawn(InPawn); // update rotation to match possessed pawn's rotation SetControlRotation( Pawn->GetActorRotation() ); Pawn->Restart(); } }
void AInGame_PlayerController::Respawn() { UnPossess(); AGameMode * Gamemode = GetWorld()->GetAuthGameMode(); if (Gamemode) { switch(SelectedChampionClass) { case Champion::DashSwordsman: { Gamemode->DefaultPawnClass = DashSwordsmanClass; break; } case Champion::Risputa: { Gamemode->DefaultPawnClass = RisputaClass; break; } } APawn * NewPawn = Gamemode->SpawnDefaultPawnFor(this, Gamemode->ChoosePlayerStart_Implementation(this)); Possess(NewPawn); } }
void AController::Possess(APawn* InPawn) { if (!HasAuthority()) { FMessageLog("PIE").Warning(FText::Format( LOCTEXT("ControllerPossessAuthorityOnly", "Possess function should only be used by the network authority for {0}"), FText::FromName(GetFName()) )); return; } REDIRECT_OBJECT_TO_VLOG(InPawn, this); if (InPawn != NULL) { if (GetPawn() && GetPawn() != InPawn) { UnPossess(); } if (InPawn->Controller != NULL) { InPawn->Controller->UnPossess(); } InPawn->PossessedBy(this); SetPawn(InPawn); // update rotation to match possessed pawn's rotation SetControlRotation( Pawn->GetActorRotation() ); Pawn->Restart(); } }
void AController::Destroyed() { if (Role == ROLE_Authority && PlayerState != NULL) { // if we are a player, log out AGameMode* const GameMode = GetWorld()->GetAuthGameMode(); if (GameMode) { GameMode->Logout(this); } CleanupPlayerState(); } UnPossess(); GetWorld()->RemoveController( this ); Super::Destroyed(); }
void AController::PawnPendingDestroy(APawn* inPawn) { if ( IsInState(NAME_Inactive) ) { UE_LOG(LogPath, Log, TEXT("PawnPendingDestroy while inactive %s"), *GetName()); } if ( inPawn != Pawn ) { return; } UnPossess(); ChangeState(NAME_Inactive); if (PlayerState == NULL) { Destroy(); } }
// Event when controlled pawn has died void AMurphysLawAIController::OnKilled(const float TimeToRespawn) { // Disable movement task branch from BT and current Move task SetBlackboardCanMove(false); StopMovement(); SetBlackboardTarget(nullptr); // Stop looking at target // Note : Calling ClearFocus changes the current rotation. // Saving the rotation avoid instant turn upon death const FRotator CurrentRotation = GetPawn()->GetActorRotation(); ClearFocus(EAIFocusPriority::Gameplay); ClearFocus(EAIFocusPriority::Default); ClearFocus(EAIFocusPriority::LastFocusPriority); ClearFocus(EAIFocusPriority::Move); GetPawn()->SetActorRotation(CurrentRotation); // Respawn logic MyCharacter = Cast<AMurphysLawCharacter>(this->GetPawn()); UnPossess(); GetWorldTimerManager().SetTimer(TimerHandle_Respawn, this, &AMurphysLawAIController::Respawn, TimeToRespawn); }
void AInGame_PlayerController::OnDeath() { GetPawn()->bCanBeDamaged = false; UnPossess(); GetWorldTimerManager().SetTimer(DeathHandle, this, &AInGame_PlayerController::AdvanceRespawnTimer, true, 1.0f); }