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));
}