Camera Initialization

Hi there.
I currently have a problem with the Camera.
When a Player Controller is created, the View is always 0,0,0 for a short period of time.
No matter where I put my Camera Initialization.

I tried [FONT=courier new]APlayerController:SpawnPlayerCameraManager(), [FONT=courier new]APlayerController:PostInitializeComponents(),[FONT=courier new] APlayerCameraManager::InitializeFor(APlayerController* PC) and [FONT=courier new]APlayerController:BeginPlay()
but NONE of them helped (In the PlayerCameraManager case I even set the ViewTarget directly after spawning the Manager!).

I want to have a black screen when my (Multiplayer)Game starts and fade in when the Game starts.

This is how it is now:

As you can see, the Clients see the Sky before the Game Starts (0,0,0 because ViewTarget is Player Controller)

This is my current code now:

void AARPG_PlayerControllerBase::PostInitializeComponents(){

void AARPG_PlayerControllerBase::createCamera(){
    this->camera = GetWorld()->SpawnActor<AARPG_Camera>();

void AARPG_PlayerControllerBase::BeginPlay(){
    PlayerCameraManager->StartCameraFade(1, 0, 1, FLinearColor(0, 0, 0), false, true);


APlayerController:bAutoManageActiveCameraTarget is set to false in the Constructor!

Does someone have any suggestion regarding that topic?

No one? :frowning:

Im pretty sure its not the camera.
How are you handling player login, and spawning?
If the Player the camera is attached to is at 0,0,0 on the CLIENT, then moving when the camera gets initialized won’t matter.

-There is no GameMode on Clients
-The SERVER will have a Controller for every player, but the CLIENT will only ever have 1(for that local player)
-The same is true for PlayerStates

Since Login/Spawn is replicated from the GameMode(which only exists on the SERVER) it is also is subject to latency.
Unfortunately Im not the greatest at or most familiar with network programming, so Im not sure of how one would mechanically ensure the player view STARTS at the appropriate location without using “smoke and mirrors”.

That said, a simple “smoke and mirrors” solution is to use a custom HUD class that by default starts with a darkened Image over the entire viewport, then remove that Image ONLY when the player is in the appropriate position.

^ this.

Even if you create the new player controller at the desired location, nothing will prevent latency from causing a slight delay that will possibly show them at 0,0,0 :frowning:

As @Erdrik mentions - smoke and mirrors :slight_smile:

For Ground Branch, I rigged it up to keep the the loading & server travel screens up until the player has received all the relevant info they require to actually start properly, then fade in.

What kind of latency are we talking about?
[FONT=courier new]PostInitializeComponents (where I currently assign the new ViewTarget) is executed before [FONT=courier new]BeginPlay. There shouldn’t be any kind of latency.

As I said Im not an expert at network code, but this is how things work as I understand it:

GameMode → GM.Login() → GM.SpawnPlayerController() → PC.PostInitializeComponents() → … → GM.InitNewPlayer() → … → GM.RestartPlayer()

Player will remain at 0,0,0 and will not move to a StartSpot until GM.InitNewPlayer() / GM.RestartPlayer().

No GameMode.
Player is spawned in via Replication → Your Camera is created during PostInitializeComponents() → … → StartSpot location is replicated and Player moves to StartSpot

Because the camera is spawned first locally, you will need to move it manually to a specified location as soon as it is created.
Ive not done much moving of cameras around beyond just rotating with the mouse and attaching it to stuff, but I don’t see anything in the code you’ve provided that would move the camera away from the PlayerController’s initial 0,0,0 location.

Since I do not want to dig around in the Source Code, I’ll do “Smoke and Mirrors”:
I create a inverted Sphere which is completely black at 0,0,0
In PostInitializeComponents I first create the Camera and set a Manual Fade to Black.
In BeginPlay I fade the Camera in like I want it.
It works. But I do not like it :frowning:

Welcome to game development! :stuck_out_tongue:

If you haven’t already, the place you want to try to fix the issues in in AGameModeBase::Login() where the player controller is first created or AGameModeBase::InitNewPlayer() where it is attempts to set the initial location/rotation.

Good luck!


We found how to fix it:

  1. Create GameInstance class

  2. on Event Init call delay with 0.0 for skip one frame

  3. call Set Enable World Rendering and disable it

  4. In your pawn in begin play create branch with IsLocallyControlled

  5. call Set Enable World Rendering and enable it

  6. call Start Camera Fade (From alpha 1, To Alpha 0, Duration 1)