Getting Spring Arm Component from Input Component

Hello all,

I am currently trying to get the spring arm component from a pawn using an input controller. I get the actor using:

//Get the pawn
APawn* Pawn = Cast<APawn>(this->GetPawn());

Which appears to work fine, but upon trying to get the spring arm, a child of the pawn, I tried using these two methods of getting it.

//Method 1
TArray<class USpringArmComponent> SpringArm;
SpringArm = Pawn->GetComponents<USpringArmComponent>();

//Method 2 as there is only 1 spring arm
class USpringArmComponent* BoomArm = FindComponentByClass<USpringArmComponent>();  

Method 1 returns an error of “pointer to incomplete class type is not allowed”, and method 2 returns a statement from the engine saying it may only be called from an actor.

I’m doing this to try and create a pinch to zoom function for touch screen computers.

You can cast your Pawn to be the Type you have made that has the spring arm then access it directly.

Casting the pawn to the player controller made no difference in finding the spring arm component. Evidently I cant use FindComponentByClass because USpringArmComponent doesnt derive from actor.

The problem was I was trying to access the camera from a bp pawn, which i did because it was faster to throw a camera and spring arm on that instead of writing the code. After writing the pawn in c++ i had no further issue.