SetViewTarget On Unpossess

Hi everyone

I am currently writing a game where when the current pawn dies it should select a random camera actor in the level and set it as viewtarget until the player can respawn. Unfortunately I am running into an issue.

#Desired behaviour:#

  1. Player dies
  2. Random Camera is selected as new view target

Easy as that

#Code: #

Here is the relevant code

void APlayerControllerC::OnUnPossess()
{
	Super::OnUnPossess();
    //Need to add guard, if player controller is destroyed
	if (!IsPendingKillPending()) {
		SetViewportToCamera();
	}
}

void APlayerControllerC::SetViewportToCamera(bool blend)
{
    //Has Autority guard
	if (HasAuthority() && GetWorld()) {
		ACameraActor* Camera = GetRandomCamera()
		if (Camera) {
			if (blend) {
				SetViewTargetWithBlend(Camera, 0.5);
			}
			else {
				SetViewTarget(Camera);
			}
		}
	}
}

// Here SetViewportToCamera works
void APlayerControllerC::SetTeam_Implementation(int i)
{
	if (GetWorld()) {
            DoStuff()
		SetViewportToCamera();
	}
}

#Actual behaviour#

All functions are called including SetViewTargetWithBlend in every occasion but there is no effect on screen. The camera stays in place where the pawn was unpossessed.

The function SetViewportToCamera works fine when called from other functions (See Code)

Any Ideas?

I solved the problem

I had to set the bAutoManageActiveCamera in the PlayerController to false. Unfortunately this does not seem to be changeable at runtime. So I have to set the viewtarget manually whenever I possess a pawn.

Not a perfect solution, but still a solution.