How to get active Camera object?

How to get an object of current (active) camera? Maybe is there something like Get Player Pawn, but for camera? I know that i can get a camera component e.g. from my player character, but what if current camera view would be e.g. from some security camera? That’s why I’m searching for something like “Get Active Camera”…

You can store your active camera using a variable of type Camera Actor and use this variable later to get access to your active camera.

1 Like

Yeah, but i’m looking for “universal” solution for other users, as i’m making a future marketplace item - so no matter what camera user have and how it was set up, it would detect it, without need to setting variables… But i see that there is no node like that, so probably I’ll put it into a variable and tell user to save his camera into this var :stuck_out_tongue: Thanks for the tip though, +1

Camera system in UE4 is actor based, you say what actor is viewed called view target and camera menager asks view target (actor, by calling CalcCamera) about camera position, so actor decides on camera position. By default actor search camera component in itself and sends position of first one it finds, so camera component is quite dummy. Each playercontroller has camera mangager and it means each had its own view target. So theres “Get view target” node which let you get current view target actor, from there you can get camera component, but actor should be the one should operate it.

2 Likes

Thanks, so now I have Get Player Controller —> Get View Target, but there is no “Get Camera Component”, only “Add Camera Component”. Am I missing something? I’ve also tried Get Components by Class (CameraComponent) and getting the first one (index 0), but it doesn’t find anything.

You might have to write a wrapper function yourself

// Look for the first active camera component and use that for the view
TInlineComponentArray<UCameraComponent*> Cameras;
GetComponents<UCameraComponent>(/*out*/ Cameras);

for (UCameraComponent* CameraComponent : Cameras)
{
	if (CameraComponent->bIsActive)
	{
		CameraComponent->GetCameraView(DeltaTime, OutResult);
		return;
	}
}

I found this in Actor.h under CalcCamera function. You can use this help to write your wrapper function

1 Like

My solutions in BP was to get all actors of class, the camera blueprints that is, loop through them with a ForEachLoop, checking each one with isActive = true. So if i had 4 camera blueprints in a level i could locate the one that was active

I found this thread while looking for a solution to my problem, but solved it in a different way, so I’m tossing this up here in case it helps anyone in the future.

There is a node called Get Player Camera Manager, which returns a Camera Manager reference. This allows you to get and set certain values of the Active Camera tied to the Player Index, regardless of whether or not the Active Camera is part of the player referenced.

For example; I have a camera which is in the world, and was able to get it’s location using this node. I’m sure you can use this node for much more than that though.

8 Likes