How to get camera position in Simulate Mode?

Hi! I am currently writing debug functionality with the help of the UDebugDrawService so I can see on-screen text output during simulate mode. Since I want to display the distance between actors and the spectator pawn, I need the camera position. I tried several things:

APlayerController* Controller = World->GetFirstPlayerController();
FVector CamLocation = Controller->PlayerCameraManager->GetCameraLocation();
//FVector CamLocation = Controller->GetFocalLocation();
APlayerController* Controller = World->GetFirstPlayerController();
FVector ViewLocation;
FRotator ViewRotation;
Controller->GetPlayerViewPoint(ViewLocation, ViewRotation);

The location vector is always 0,0,0.
Then I tried to get the SpectatorPawn that was spawned when starting simulate mode. But when I retrieve its location via GetActorLocation() it is also 0,0,0.
Anyone got this working?

Hello, HCK!

I believe that the viewport in simulate mode is not controlled by any game object, which means you can’t query it for location data. The SpectatorPawn doesn’t move when the viewport does (which is why you’re getting 0,0,0 for its location). There is a CameraActor that exists during simulate mode, but its location isn’t related to the position of the viewport - that’s why its location keeps returning as 0,0,0.

Regards,

Thank you for the quick reply. OK, that makes sense. The camera location data has to be there somewhere, though. But it’s not that crucial, I was just wondering if there is some easy way or if I came across a bug.

I know I’m late to the party, but maybe someone visiting this thread will find my post useful.

Camera position in Simulate In Editor can be found at:
GCurrentLevelEditingViewportClient->ViewTransformPerspective.GetLocation()

Additionally you can check if the editor is in SIE mode:
GEditor->bIsSimulatingInEditor

6 Likes

You are the best!! I spent 10,000 thousand hours looking for a way to get viewport camera coordinates, the poor ChatGpt has already refused to help me and said that it is impossible. And then I came across your message and the solution was so simple. Thank you)