0
\$\begingroup\$

I'm accessing my FollowCamera https://imgur.com/a/vbFagxg from my BluePrintCharacter class in my C++ code, with this following line :

FollowCamera = GetOwner()->FindComponentByClass<UCameraComponent>();
FVector WorldLocationV = FollowCamera->GetWorldLocation();

But when I run my game, I get this error : GetWorldLocation is not a member of UCameraComponent

Why is this, and how can I get GetWorldLocation from FollowCamera in C++?

In BluePrint this seems to work fine : http://i.imgur.com/8m9TWUW.png

\$\endgroup\$
1
  • \$\begingroup\$ I think you should be casting your found component --- `FollowCamera = Cast<UCameraComponent>(FindComponentByClass<UCameraComponent>()); \$\endgroup\$
    – Natalo77
    Mar 27, 2020 at 10:11

1 Answer 1

0
\$\begingroup\$

According to the Unreal docs UCameraComponent you are correct, GetWorldLocation isn't part of UCameraComponent.

Attached to the camera is a camera manager and to get the world location and rotation of the camera, you need to get this.

APlayerCameraManager *CameraManager = GetWorld()->GetFirstPlayerController()->PlayerCameraManager;

FVector CameraLocation = CameraManager->GetCameraLocation();
FVector CameraForwardVector  = CameraManager->GetCameraRotation().Vector();

In case you need it, the #include is #include "Camera/PlayerCameraManager.h"

\$\endgroup\$
1
  • \$\begingroup\$ This is incorrect - GetWorldLocation is a member function of USceneComponent, which UCameraComponent derives from. Your approach for getting OP's desired output would work however \$\endgroup\$
    – Natalo77
    Mar 27, 2020 at 10:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .