Assuming this is for single player game, you can get the camera manager like this:
if (GetWorld())
{
AYourCustomCameraManager* CameraManager = Cast<AYourCustomCameraManager>(UGameplayStatics::GetPlayerCameraManager(GetWorld(), 0));
if (CameraManager )
{
// CameraManager->DoStuff();
}
}
1 Like
No, this is for a multiplayer fps game. It uses the shooter game example.
For a multiplayer game, you can iterate through all the player controllers and get the player camera manager class and cast it to your custom type by using below code:
for (FConstPlayerControllerIterator ControllerIterator = GetWorld()->GetPlayerControllerIterator(); ControllerIterator; ++ControllerIterator)
{
const APlayerController* PlayerController = *ControllerIterator;
if (PlayerController && PlayerController->IsLocalController())
{
const AYourCustomCameraManager* CameraManager = Cast<AYourCustomCameraManager>(PlayerController->PlayerCameraManager);
if (CameraManager)
{
// CameraManager->DoStuff();
}
}
}
Just remember that in a multiplayer game, clients are ONLY aware of their own PlayerController and Server has access to ALL player controllers. When the above code is executed on client, it will return only one controller but when executed on server it will get all the controllers and therefore we make sure it will run only on the server player by using IsLocalController()
.
1 Like