How to get a camera manager from another script? c++

Hello! I was wondering how it would be possible to get a player camera manager into a script so that I can edit the cameras rotation. Thanks!

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();
   }
}

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().