How to use APlayerCameraManager::StartCameraFade

Hello Everyone,

I am trying to fade my camera in at the start of the game.
I took a look at the documentation and came across the function:
APlayerCameraManager::StartCameraFade();

However, I have no Idea how I call this function within a script.

I want to do this on the player from the FirstPersonTemplate

I added a C++ Component to this player and so far I tried:
void UTestingTransform::BeginPlay()
{
Super::BeginPlay();

            //This didnt work
    	if (GetWorld())
    	{
    		cameraManager = Cast<APlayerCameraManager>(GetClass());
    
    		if (cameraManager)
    		{
    			UE_LOG(LogTemp, Error, TEXT("SUCCES"));
    		}
    		else
    		{
    			UE_LOG(LogTemp, Error, TEXT("FAILURE"));
    		}
    	}
    
            //Neither did this
            GetOwner()->FindComponentByClass<APlayerCameraManager>();
    }

I understand that the class is childclass of AActor.
However, I can’t figure it out.

Perhaps someone can put me on the right track or provide me with an exampe?

Greetings,

Kyle

1 Like

APlayerCameraManager * a = UGameplayStatics::GetPlayerCameraManager(GetWorld(), 0);

if (a) {
a->StartCameraFade(1, 0, 0.5, FLinearColor::Black, false, true);
}

Your PlayerController creates an instance of the PlayerCameraManager class on play.
You can access the PlayerCameraManager through your PlayerController.

From the PlayerController:

if(PlayerCameraManager != nullptr)
{
    PlayerCameraManager->StartCameraFade(1.f, 0.f, 1.f, FLinearColor::Black, true, true);
}

Or from the Pawn/ Character

if(APlayerController* PC = Cast<APlayerController>(GetController()))
{
    if(PC->PlayerCameraManager)
    {
        PC->PlayerCameraManager->StartCameraFade(1.f, 0.f, 1.f, FLinearColor::Black, true, true);
    }
}

If you want to fade the camera in on start, then do this in the BeginPlay function.

1 Like