Link to timelines doc for c++?

After trying this before I thought I give this timeline in c++ another shot. There are still some old answers here on answerhub which show how to use timelines in c++ with the actor’s own tick function. But actually it also works withouth using the tick of the actor. I had to use AddInterpFloat() at runtime to get this to run.

This answer should work for you!

//.h

UPROPERTY()
UTimelineComponent* ScoreTimeline;

UPROPERTY()
UCurveFloat* fCurve;

FOnTimelineFloat InterpFunction{};

//.cpp

//Constructor:

static ConstructorHelpers::FObjectFinder<UCurveFloat> Curvy(TEXT("CurveFloat'/Game/Blueprints/NotSoImportant/CurveFloatBP.CurveFloatBP'"));
if (Curvy.Object) {
	fCurve = Curvy.Object;
}

ScoreTimeline = ObjectInitializer.CreateDefaultSubobject<UTimelineComponent>(this, TEXT("TimelineScore"));

InterpFunction.BindUFunction(this, FName{ TEXT("TimelineFloatReturn") });

//Then inside BeginPlay for example:

ScoreTimeline->AddInterpFloat(fCurve, InterpFunction, FName{ TEXT("Floaty") });
ScoreTimeline->Play(); // or PlayFromStart() etc, can be called anywhere in this class

//And Finally your callback function:

void AYourClass::TimelineFloatReturn(float val)
{
 //Your float val from curve returns here
}

}

I made a wiki page about this here:

3 Likes