How do you set the PlayerCameraManager on a PlayerController?

I have looked at loads of information about how camera systems are set up in UE4 and have settled on the camera system I want in my game.

I want to be able to switch pawns so I am going to have a custom PlayerController that possesses the pawns. I want a third person camera over that pawn which has some movement constraints. To get started I created a custom PlayerControllerClass and a custom PlayerCameraManager.

How do I set the player controller to use the custom PlayerCameraManager?

I tried:

.h

//ForwardDeclaration
class SWCameraManager;
class UCapsuleComponent;

UCLASS()
class MYPROJECT_API ASWPlayerController : public APlayerController
{
	GENERATED_BODY()
	
protected:

//CameraManager    
    UPROPERTY(VisibleAnywhere, Category = "Camera")
    SWPlayerCameraManager * CameraManager; 
};

.cpp

ASWPlayerCameraManager::ASWPlayerCameraManager()
{
    PlayerCameraManagerClass = CameraManager;
};

This is throwing an error that SWPlayerClass is not of type UCLASS(), which I kind of expected. I have seen in the docs the PlayerController exposes both PlayerCameraManager and PlayerCameraManagerClass. I am under the impression from hearsay and conjecture that I need to set the latter by casting my custom SWPlayerCameraManager as a PlayerCameraManager, but I have no basis to back that up.

Do I do this in the CPP file without declaring a class varible? Can I just set PlayerCameraManagerClass = Cast<SWPlayerControllerManager>(); or is there a Setter method I have missed?

I am rather confused by this.

TL;DR: What code goes where when assigning a custom PlayerCameraManager to a custom PlayerController?

Hey there, to set the Player Camera Manager i do this:

ABasePlayerController::ABasePlayerController(const class FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
{
	PlayerCameraManagerClass = ABasePlayerCameraManager::StaticClass();
}
1 Like

Thank-you so much. I didn’t realise that there was StaticClass() method.

On a separate note, while I’m learning… your constructor is taking an argument that looks like it is a reference to a generic “ObjectInitializer”. What is the purpose of that?

You don’t need it anymore, this is the old way of doing constructors in UE 4.

Thanks for the clarification