Help translate this BP graph to C++

I am already struggling 3 days with this, I translated some parts but all is bad, can anyone help me to give me a clean and simple example of this graph in C++, to get the spring arm I am using characterref variable in the class playercotroller, you can take spring arm directly in character class or as you want.


Do you have your timeline set up in cpp?

1 Like


#include "Components/TimelineComponenet.h"
MyCharacter::MyCharacter() //constructor
	static ConstructorHelpers::FObjectFinder<UCurveFloat> Curvy(TEXT("Refference to your float curve"));
	if (Curvy.Object)
		fCurve = Curvy.Object;
	//Timeline components don't need to be attached/connect to anything.
	TL_UpdateCameraHeight = CreateDefaultSubobject<UTimelineComponent>(TEXT("TL_UpdateCameraHeight"));
	//Binging Delegates with UFunctions
	InterpFunction.BindUFunction(this, FName("TL_HeightUpdateFunc"));
	TimelineFinished.BindUFunction(this, FName("TL_HeightUpdateFinished"));
if (_CurrentHeight != _NewHeight) //checking camera height according to the character pose
	 _OriginalHeight = _CurrentHeight; //Sets the value of Current height to Original height

	//check if curve is refference asset is valid
		//Add the float curve named "Percent" to the timeline and connect to the interpfunction's delegate
		TL_UpdateCameraHeight->AddInterpFloat(fCurve, InterpFunction, FName("Percent"));
		//Add timeline finished function
		StartLocation = GetActorLocation();
		EndLocation = FVector(StartLocation.x, StartLocation.y, StartLocation.z = ZOffset);
		//Setting Timeline Settings before we start it
		TL_UpdateCameraHeight->SetLooping = false;
		TL_UpdateCameraHeight->SetIgnoreTimeDilation = true;		
		//Start Timeline
void MyCharacter::TL_HeightUpdateFunc(float Value)
	SetActorLocation(FMath::Lerp(_OriginalHeight, _NewHeight, Value));

void MyCharacter::TL_HeightUpdateFinished(float Value)
	if(TL_UpdateCameraHeight->GetPlaybackPosition() == 0.0f)

I can send you .h file setup too if you want

I have mistakes in my code, I need to pass floats instead of vectors to lerp.

Something like this:

void MyCharacter::TL_HeightUpdateFunc(float Value)
    FVector CurrentLocation = MyCharacterRef->SpringArm->GetRelativeLocation();
    float NewHeight = FMath::Lerp(_OriginalHeight, _NewHeight, Value);
    MyCharacterRef->SpringArm->SetRelativeLocation(FVector(CurrentLocation.X, CurrentLocation.Y, NewHeight));

Or maybe a shorter version:

void MyCharacter::TL_HeightUpdateFunc(float Value)
    FVector NewLocation = MyCharacterRef->SpringArm->GetRelativeLocation();
    NewLocation.Z = FMath::Lerp(_OriginalHeight, _NewHeight, Value);
1 Like

Thank You very very much, I was struggling with this for 3 days and SpringArm->GetRelativeLocation(); USpringArmComponent has no member GetRelativeLocation()


But does it compile?
USpringArmComponent derives from USceneComponent, and the latter does have GetRelativeLocation(), so it should work just fine.

1 Like

I am now trying to compile it, will see what it does, I will let You know.

IDE will show you a lot of red underlinings when you code. Intellisense often doesn’t really catch up with the engine classes. So try and compile things first, then look for errors =)


Error while compiling: use of undefined type USpringArmComponent

#include “GameFramework/SpringArmComponent.h”


its already included, and I have a working springarm and camera attached to it.

The full error log:


Restarted IDE , now getting this error.

Just checked to be sure, SpringArm->GetRelativeLocation() compiles fine.
use of undefined type USpringArmComponent shows up if there’s no respective #include
There must be something else you’re missing.
How it’s setup in my project:


class USpringArmComponent* SpringArm;


#include "GameFramework/SpringArmComponent.h"

// In constructor:
SpringArm = CreateDefaultSubobject<USpringArmComponent>(TEXT("Spring Arm"));

//In a function:

Mine setup:


UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Spring Arm Components")
	class USpringArmComponent* SpringArm;//Create Spring Arm Component


SpringArm = CreateDefaultSubobject<USpringArmComponent>(TEXT("SpringArmComponent"));
	SpringArm->bUsePawnControlRotation = true;
	SpringArm->SetRelativeLocation(FVector(0.0f, 25.0f, 100.0f));
	SpringArm->SetRelativeRotation(FRotator(0.0f, 0.0f, 0.0f));
	SpringArm->TargetArmLength = 200.0f;

maybe this is because of I am using old version of the engine 4.20

Naah, this wasn’t changed. That’s the basic setup, USpringArmComponent is a USceneComponent, and it can’t be any other way.


and in Blueprint I am able to call this function , don’t know why on C++ side this is not compiling.

This in fact might have changed. I believe CapsuleComponent was public, then at some point it was moved to private, and public GetCapsuleCompoent() was added. You can try simply something like SetupAttachment(CapsuleComponent)

1 Like