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\$
  • \$\begingroup\$ I think you should be casting your found component --- `FollowCamera = Cast<UCameraComponent>(FindComponentByClass<UCameraComponent>()); \$\endgroup\$ – Natalo77 Mar 27 '20 at 10:11
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\$
  • \$\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 '20 at 10:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.