Timeline in c++

How to use Timeline in c++

This example maybe gives you an idea about how to use Timelines in c++.

It was tested on 4.10, but it should also work on other version in a similar way.

Disclaimer: This wiki combines previous examples from Answerhub and Forum and adds on top of it, that you dont need the actors tick component where u place the timeline.


YourClass(const FObjectInitializer& ObjectInitializer);
UTimelineComponent* ScoreTimeline;
UCurveFloat* fCurve;
FOnTimelineFloat InterpFunction{};
void TimelineFloatReturn(float val);


// Constructor
AYourClass::AYourClass(const FObjectInitializer& ObjectInitializer)
	: Super(ObjectInitializer)
static ConstructorHelpers::FObjectFinder<UCurveFloat> Curvy(TEXT("Reference Path to your Float Curve"));
 if (Curvy.Object) {
     fCurve = Curvy.Object;
ScoreTimeline = ObjectInitializer.CreateDefaultSubobject<UTimelineComponent>(this, TEXT("TimelineScore"));
//Bind the Callbackfuntion for the float return value
 InterpFunction.BindUFunction(this, FName{ TEXT("TimelineFloatReturn") });
void AYourClass::BeginPlay()
//Add the float curve to the timeline and connect it to your timelines's interpolation function
ScoreTimeline->AddInterpFloat(fCurve, InterpFunction, FName{ TEXT("Floaty") });
 // Start your Timeline or PlayFromStart() etc, can be called anywhere in this class
//Your Callback Function for the timeline float value
void AYourClass::TimelineFloatReturn(float val)
 //Your float val from curve returns here

If at the same time you would like to get the return value from another float or vector curve in your return function, then just get the playback position of your timeline and and get the corresponding return value from your curve.


spaceharry (talk)

Rate this Page:
(2 votes)

Approved for Versions:4.12