Use a pawn as a camera

Hi!

I’ve just started to develop with Unreal and C++ and I’m curious about one thing:

I’ve tested the third person and the first person template and both has a camera. But, if I want to use a custom class than inherits from APawn, can I use it as a “camera”?

In other words, I want to use a custom pawn as a camera and the player will see what this custom pawn is facing on its X axis.

I think it is something related to possess that custom pawn and/or setting the custom pawn as a Default Pawn in the GameMode.

How can I use a custom pawn as a camera?

Thanks.

But, if I want to use a custom class than inherits from APawn, can I use it as a “camera”?

Yes.

And it does not even need to be a Pawn (it helps if it is, though). It can be any actor, and it does not need a camera.

When you possess (a pawn) or set view target (any actor), the Camera Manager will first check if there are any active camera components on said actor. If there are none, the Camera Manager will use its default camera.

Having a dedicated camera component can simplify things in the long run.


This is the default pawn you use to move around in the editor. All controls are defined on the C++ level. It has no camera but if you possess it, you get to look through this actor.

image

Thanks but, what do I have to do to posses the custom pawn?

I am not too versed in UE4’s C++ side of things but I imagine it would look like:

PlayerController->Possess(Pawn);

In BPs:

image

Pawns also carry AutoPossessPlayer flag. And, as you mentioned above, the Game Mode can define the default pawn to use. Whether the target has a camera or not matters little.