How can I create a TimelineComponent in C++?

Like the title says I am looking for a way to create a timeline in C++. I want a float curve which plays and updates my value in C++. Does someone have an idea how to do that?

I haven’t used it, but this is probably what you’re looking for:

It looks like the “FRichCurve” class looks like it has methods for adding keys, and evaluating the curve at specific times. This API documentation sometimes doesn’t have a lot of detail, but with a bit of experimenting you should be able to figure it out.

Ah thanks, yep it helped me. I had to use UCurveFloat instead of the FRichCurve and for the timeline I used FTimeline (FTimeline | Unreal Engine Documentation).

Yep, FTimeline is your friend in C++. The only reason that UTimelineComponent exists really is to get a Tick function (and expose its API easily to Blueprints).

Hello friend, you could build a timeline in c ++
could post an example of code ???

Does anyone on this thread have an example? I’m hoping to create a timeline with C+ calculated curves - where the Timeline can be used in BP

Timeline C++ Sample

Here’s what I’ve got, I don’t know about the used in BP part because I don’t use Blueprints much, but this does work in C++:

.h



UCLASS()
class STAINEDGLASS_API ATestTimelineActor : public AStaticMeshActor
{
	GENERATED_BODY()
	
public:	
	ATestTimelineActor(const FObjectInitializer &pInit);
	virtual void BeginPlay() override;
	virtual void Tick( float DeltaSeconds ) override;

	UFUNCTION()
	void ColorInterp(float pValue);

	UPROPERTY(EditAnywhere)
	UCurveFloat *TestFloatCurve;

	FTimeline TestTimeline;
};


.cpp



ATestTimelineActor::ATestTimelineActor(const FObjectInitializer &pInit) : Super(pInit)
{
	PrimaryActorTick.bCanEverTick = true;
	
        //Setup a simple curve
	TestFloatCurve = pInit.CreateDefaultSubobject<UCurveFloat>(this, TEXT("Test Float Curve"));
	TestFloatCurve->FloatCurve.AddKey(0.0f, 0.0f);
	TestFloatCurve->FloatCurve.AddKey(1.0f, 1.0f);

        //Setup the timelinefunction
	FOnTimelineFloat floatStaticFunc{};
	floatStaticFunc.BindUFunction(this, "ColorInterp");
	
        //Create the timeline
	TestTimeline = FTimeline();
	TestTimeline.AddInterpFloat(TestFloatCurve, floatStaticFunc, TEXT("Float Function"));
}

// Called when the game starts or when spawned
void ATestTimelineActor::BeginPlay()
{
	Super::BeginPlay();
	TestTimeline.PlayFromStart();
	GEngine->AddOnScreenDebugMessage(-1, 1.0f, FColor::Green, TEXT("Tick Component"));
}

// Called every frame
void ATestTimelineActor::Tick( float DeltaTime )
{
	Super::Tick( DeltaTime );
	if (TestTimeline.IsPlaying())
		TestTimeline.TickTimeline(DeltaTime);
}

void ATestTimelineActor::ColorInterp(float pValue)
{
	GEngine->AddOnScreenDebugMessage(-1, 1.0f, FColor::Black, TEXT("Interp Value: ") + FString::SanitizeFloat(pValue));
}


After a little bit of noodling around, I don’t recommend doing it this way, as this creates some interesting issues, most notably, when you place this actor in a level, you’ll notice the yellow “Reset To Default” icon next to your curve property. If you attempt to save your level, you’ll get the “Graph is linked to private objects…” save error. If you click “Reset To Default”, you can save the map, but now the editor will crash if you try and play the timeline that references the curve. Not sure how to log that, or if anyone else is seeing it, but I can verify you don’t have this issue if you create and set the curve from the editor.

Ok, I think I’ve got it

Sorry if this is a dead horse, but seems like people have been asking and I hate to leave it at my last answer, esp considering i’ve learned a ton in the last two or three days, apologies if this is redundant and I’m the only person who hasn’t figured it out yet :confused:

So here’s what I’ve come up with that seems to work under every case. Not claiming this is the definitive solution, but it doesn’t crash on startup and it doesn’t crash a few minutes in (which was happening), please feel free to fill in the gaps or correct anything I’ve posted in error:

.h



UCLASS()
class STAINEDGLASS_API ATestMouseOverActor : public AStaticMeshActor
{
	GENERATED_BODY()
public:
	ATestMouseOverActor(const FObjectInitializer &pInit);
	virtual void BeginPlay() override;
	virtual void Tick(float DeltaSeconds) override;

	UFUNCTION()
	void MyCursorOnFunc(UPrimitiveComponent *pComponent);

	UFUNCTION()
	void ColorInterp(float pValue);

	UPROPERTY(Transient)
	UCurveFloat *MyFloatCurve;

	UPROPERTY(Transient) //This doesn't seem to be necessary
	FTimeline MyTimeline;


.cpp



ATestMouseOverActor::ATestMouseOverActor(const FObjectInitializer &pInit) : Super(pInit)
{
	PrimaryActorTick.bCanEverTick = true;

	MyFloatCurve = NewObject<UCurveFloat>();
	MyFloatCurve->FloatCurve.AddKey(0.0f, 0.0f);
	MyFloatCurve->FloatCurve.AddKey(1.0f, 1.0f);

	FOnTimelineFloat floatFunc{};
	floatFunc.BindUFunction(this, "ColorInterp");

	MyTimeline.AddInterpFloat(MyFloatCurve, floatFunc, TEXT("Float Function"));

	GetStaticMeshComponent()->OnBeginCursorOver.AddDynamic(this, &ATestMouseOverActor::MyCursorOnFunc);

}

void ATestMouseOverActor::BeginPlay()
{

}

void ATestMouseOverActor::Tick(float DeltaSeconds)
{
	if (MyTimeline.IsPlaying())
		MyTimeline.TickTimeline(DeltaSeconds);
}

void ATestMouseOverActor::MyCursorOnFunc(UPrimitiveComponent *pComponent)
{
        //Start the timeline if we mouse over an object
	MyTimeline.PlayFromStart();
}

void ATestMouseOverActor::ColorInterp(float pValue)
{
// Do some cool stuff when we step the timeline
}


I can see you are using a TimeLine function, but not a TimeLine Component, how can i use it?
I tried to do it by myself and i good this: UCurveFloat does not exist in binded function - Character & Animation - Unreal Engine Forums