2D camera behaves oddly in packaged game to standalone - SOLVED


This is a post for anyone looking into writing a Paper2D game. It relates to an issue I had with the camera and how I resolved it.

I am using UE4 4.23 and have a simple Paper2d C++ project in progress.

My default pawn class fired from my gamemode class is my camera class. The camera is set up as follows in the constructor:

UCameraComponent* Camera = CreateDefaultSubobject<UCameraComponent>(TEXT(“Camera”));
Camera->bUsePawnControlRotation = false;
Camera->ProjectionMode = ECameraProjectionMode::Orthographic;
Camera->OrthoWidth = 1280.0f;
Camera->AspectRatio = 9.0f / 16.0f;
Camera->SetRelativeLocationAndRotation(FVector(0.0f, 0.0f, 100.0f), FRotator(-90.0f, 0.0f, -90.0f));
Camera->AttachToComponent(RootComponent, FAttachmentTransformRules::KeepRelativeTransform);

Actually, for simplicity in this post, I have not attached it to a spring arm. Even though it is, the following problem still applies.

Then in the gamemode I spawn two sprites, both centre at location x=0, y=0. One is a white background that covers the whole screen. The other is a spaceship that sits in the middle of the screen on top of the background.

The game runs exactly as I expect when I play it from the editor in standalone mode. Both sprites are centred on the screen. Yipeee!

The bad news is that when I package the game to Windows 64-bit, the sprites appear well off centre and the worse thing is that there is a big square black block in the centre of the screen where nothing can be rendered, hence I can’t see my spaceship, just a big black block. If I move my spaceship away from this block, then the spaceship appears.

I would have thought my setup correctly centres the camera at 0,0, or is there something I’m missing that just happens to be defaulted correctly running from inside the editor?

Here is the answer. Just add:

Camera->bAbsoluteLocation = true;