Here is the best way to fix it, based on @Uno1982’s solution.
- Create class (UMyLocalPlayer) with parent ULocalPlayer
- Put this in the header
public:
UPROPERTY()
bool bBlack = true;
virtual bool CalcSceneViewInitOptions(
struct FSceneViewInitOptions& ViewInitOptions,
FViewport* Viewport,
class FViewElementDrawer* ViewDrawer,
int32 StereoViewIndex) override;
- Fill implementation
bool UMyLocalPlayer::CalcSceneViewInitOptions(FSceneViewInitOptions& ViewInitOptions, FViewport* Viewport, FViewElementDrawer* ViewDrawer, int32 StereoViewIndex)
{
bool bReturn = Super::CalcSceneViewInitOptions(ViewInitOptions, Viewport, ViewDrawer, StereoViewIndex);
if (bBlack && PlayerController && PlayerController->PlayerCameraManager && PlayerController->PlayerCameraManager->bEnableFading)
{
bBlack = false;
}
if (bBlack) {
ViewInitOptions.OverlayColor = FLinearColor::Black;
ViewInitOptions.OverlayColor.A = 1.0f;
}
return bReturn;
}
- Create UUserWidget, override NativeConstruct, call StartCameraFade
protected:
UPROPERTY()
bool bFirstLoad = true;
virtual void NativeConstruct() override;
void UHUDWidget::NativeConstruct()
{
Super::NativeConstruct();
if (bFirstLoad) {
APlayerCameraManager* PlayerCameraManager = GetOwningPlayerCameraManager();
if (PlayerCameraManager) {
PlayerCameraManager->StartCameraFade(1.0f, 0.0f, 5.0f, FLinearColor::Black, true, true);
bFirstLoad = false;
}
}
}
- Load the widget on beginplay of player pawn
In the implementation code, you can see that the condition will disable the black screen if fading is enabled, so you can call a fade in the user widget NativeConstruct (I found that if you call the fade in earlier (e.g playercontroller onpossess), there is still a slight flash. If you don’t want a fade, you can change the conditions above, or set bBlack whenever you want (i.e set bBlack in NativeConstruct).