PlayerCameraManager fading is inconsistent

I’m using the PlayerCameraManager class StartCameraFade function to fade in/out when starting and ending the game. It works flawlessly the first time I play, but when I close my project and reopen, it no longer works. The code is still there, the function is still being called, my debug messages still print to the screen… but the fade just doesn’t happen.

Here is my code:

	APlayerController* pc = GEngine->GetFirstLocalPlayerController(GWorld);
	APlayerCameraManager* cameraMan = pc->PlayerCameraManager;

	float fromAlpha = 1.0;
	float toAlpha = 0.0;
	float duration = 2.0;
	FLinearColor color = FLinearColor::Black;
	bool bShouldFadeAudio = true;
	bool bHoldWhenFinished = true;

	cameraMan->StartCameraFade(fromAlpha, toAlpha, duration, color, bShouldFadeAudio, bHoldWhenFinished);

Why does the StartCameraFade function stop working after the first couple tries?

Hey -

I copied the code you posted into an actor class’ BeginPlay() function. Adding the actor to the level the fade in played as expected even after closing / reopening the project. Are you able to reproduce this error in a new project? Also, where are you calling your code from so that I can try to match the same setup you’re using.

Cheers

Yes, this is occurring for me in multiple brand-new projects (FirstPerson template). The code is being called in the BeginPlay() method of my GameMode. I have included Engine.h and I know that the BeginPlay function is being called, due to the debug output. Here’s the function in its entirely, from FirstPersonGameMode.cpp:

void ACPFirstPersonGameMode::BeginPlay()
{
	Super::BeginPlay(); 

	APlayerController* pc = GEngine->GetFirstLocalPlayerController(GWorld);

	if (!pc) {
		GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("NO PLAYER CONTROLLER!"));
	}

	APlayerCameraManager* cameraMan = pc->PlayerCameraManager;

	if (!cameraMan) {
		GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("NO CAMERA MANAGER"));
	}

	float fromAlpha = 1.0;
	float toAlpha = 0.0;
	float duration = 2.0;
	FLinearColor color = FLinearColor::Black;
	bool bShouldFadeAudio = true;
	bool bHoldWhenFinished = true;

	cameraMan->StartCameraFade(fromAlpha, toAlpha, duration, color, bShouldFadeAudio, bHoldWhenFinished);

	GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("STARTED CAMERA FADE IN!"));
}

Thank you for the fast help!

The fade in still plays for me inside the game mode after restarting the editor. Could you post a sample project where the fade in is not playing correctly?

Sure, here’s the link:

UPDATE: The Audio fade-in IS working, even though the camera does not fade in. This shows that the StartCameraFade() function MUST be getting called, the camera fade portion just isn’t working correctly.

Hey -

If you play in editor you see the camera fade play as intended but closing the editor and reopening causes the fade to not play, correct? Does the fade effect play properly if you PIE multiple times before closing the editor?

Hey -

Exactly. The fade plays properly when I PIE, multiple times. But as soon as I close the editor and reopen, the camera fade no longer works. However, the audio fade continues to work, which indicates that the StartCameraFade() function is being called, but the camera fade portion is just not working correctly.

My project is targeted for Mobile/Tablet and Scalable 3D/2D, if that makes a difference. This is on a Windows 8 machine.

Thank you again for all of your help! I really hope to get this solved :slight_smile:

Small update: In a packaged Win64 game, the same effect can be observed (audio fade-in but NO camera fade-in), even when both audio and camera fade-in are working in PIE.

Hey -

I tested the sample project you sent which did not play the fade in effect as you described. However when I copy/pasted the BeginPlay() function from your project into the GameMode class of a new project I was able to get the fade in effect each time I tried to play in the editor, including after closing/reopening the editor. I also received a number of compile errors when I tried to compile the base code from your project. It’s possible that there is code elsewhere in your project that is affecting your fade in. Do you get the same effect (Fade in not playing after reopening the editor) if you copy the fade in code into a new project?

Cheers

Hey -

I just tried copy/pasting the BeginPlay() function to a brand new FirstPerson template project. Unfortunately, the same thing happens: the fade works fine until I close and reopen the editor, after which point only the audio fade works. I also tried with a brand new ThirdPerson template project, and observed the same thing.

I’m not getting any compile errors on my side, using the binary 4.9.2 release through the Launcher.

Update: I traced the bEnableFading variable to its use in the CalcSceneView function of LocalPlayer.cpp. Adding debug output indicates that things are working as expected: LocalPlayer.cpp detects when the PlayerCameraManager–>bEnableFading flag is turned on/off, and sets ViewInitOptions.OverlayColor and Alpha accordingly. However, again, no fading effect is observed.

Might there be a bug down at the level of the actual shaders? Potentially an interaction with my video card / drivers?

Hey -

It is possible that your video card/drivers could be a contributing factor. Definitely make sure that you’re using the latest available drivers for your card. Also, if you could post your DXDiag that will help determine if the issue is with the video card itself.

I’ve attached my DXDiag and made sure that I’m using the latest Nvidia drivers ( no change). link text

Glad to know I’m not going crazy! Thank you for your help :slight_smile:

Hey -

I was finally able to get a repro for the fade in effect not playing correctly. It appears it is in fact related to the project being set for mobile. I have entered a bug report (UE-21846) for further investigation.

Cheers

,

Not sure if this will be seen. Are there any other methods for camera fading that currently work in Mobile/Tablet projects? Or is there a fix that I can make to the engine code?

There is no workaround at the moment and the bug fix for the engine is still being investigated. You can look at APlayerCameraManager::StartCameraFade() however I’m not sure where exactly to look for how this function interacts with Mobile.

Is it fixed now?

Hey keaukraine-

This issue has not been resolved yet. I updated the original report to show that this is still affecting members of the community and can update here with any pertinent information as it becomes available.