# How to avoid using \`Tick()\` with \`FTimelines\` or \`UTimelineComponent\`?

**URL:** <https://forums.unrealengine.com/t/how-to-avoid-using-tick-with-ftimelines-or-utimelinecomponent/1144832>\
**Category:** C++\
**Tags:** timeline, unreal-engine, CPP, question\
**Created:** [April 26, 2023, 9:24am UTC](https://forums.unrealengine.com/t/how-to-avoid-using-tick-with-ftimelines-or-utimelinecomponent/1144832 "2023-04-26T09:24:05Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![DevKaiUnreal](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/devkaiunreal/32/935713_2.png) [@DevKaiUnreal](https://forums.unrealengine.com/u/DevKaiUnreal)\
**Post date:** [April 26, 2023, 9:24am UTC](https://forums.unrealengine.com/t/how-to-avoid-using-tick-with-ftimelines-or-utimelinecomponent/1144832/1 "2023-04-26T09:24:05Z")

</div>

Hi,

I’d like to use Timelines, here, to continously log a float value from a UCurveFloat. I see 3 options here and would like to know, what would be the most elegant solution.

**TestActor.cpp** :

```auto
UCLASS()
class THETHIRDPERSONGAME_API ATestActor : public AActor
{
	GENERATED_BODY()

public:
	ATestActor();
	virtual void Tick(float DeltaTime) override;
	UPROPERTY()
	UTimelineComponent* TimelineComponent;
	UPROPERTY()
	FTimeline Timeline;

	UPROPERTY(EditDefaultsOnly, BlueprintReadOnly)
	UCurveFloat* CurveFloat;

	FOnTimelineFloat OnTimelineFloat{};

	UFUNCTION()
	void TimelineFloatReturn(float Value);

protected:
	virtual void BeginPlay() override;

private:
	UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, meta = (AllowPrivateAccess = "true"))
	TObjectPtr<UStaticMeshComponent> Mesh;
};

```

**TestActor.cpp** :

```auto
#include "TestActor.h"

ATestActor::ATestActor()
{
	PrimaryActorTick.bCanEverTick = true;
	Mesh = CreateDefaultSubobject<UStaticMeshComponent>("Mesh");
	SetRootComponent(Mesh);
	TimelineComponent = CreateDefaultSubobject<UTimelineComponent>("TimelineScore");
}

void ATestActor::TimelineFloatReturn(float Value)
{
	UE_LOG(LogTemp, Warning, TEXT("%s - %f"), *FString( __FUNCTION__ ), Value);
}

```

**A) Using FTimeline with Tick**  
Great, that I don’t need an ActorComponent.  
Bad, that there is going to be a function call (or a condition check) for each Tick.

```auto
void ATestActor::BeginPlay()
{
	Super::BeginPlay();

	OnTimelineFloat.BindUFunction(this, "TimelineFloatReturn");
	Timeline.AddInterpFloat(FCurve, InterpFunction, "Floaty");
	Timeline.Play();
}

// Called every frame
void ATestActor::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);
	Timeline.TickTimeline(DeltaTime);
}

```

**B) Using UTimelineComponent**  
Great, that Tick is kept free.  
Bad, that I need an ActorComponent.

```auto
void ATestActor::BeginPlay()
{
	Super::BeginPlay();

	OnTimelineFloat.BindUFunction(this, "TimelineFloatReturn");
	TimelineComponent->AddInterpFloat(CurveFloat, OnTimelineFloat);
	TimelineComponent->Play();
}

```

**C) Using FTimeline with SetTimer()**  
I actually didn’t managed to make this work but it should l look something like this. There is a thread were someone made it work ([How to create a Timeline in C++?](https://forums.unrealengine.com/t/how-to-create-a-timeline-in-c/296029)), however I can’t compile that code. Any suggestions how to make this approach work?

```auto
GetWorld()->GetTimerManager().SetTimer(CameraExtension.TimerHandle,
    FTimerDelegate::CreateLambda([this(){ 
        TimeLine.TickTimeline(GetWorld()->GetDeltaSeconds());}), 0.f, false);

```

I’m a bit confused why the Blueprints provide such intuitive (at least in my opinion) interface to Timelines and C++ not.

What’s the most elegant / performant solution?

Thanks in advance.
