Hello. How can i make anything to replace Timeline in Actor Components. Timeline isn’t available for components. I had ideas with a macro which will take values from Curves; Creating Construct, but the macro requires curves, object which can be used in constructs can’t have delay. Is there any way to emulate Timeline inside Actor Components without all the issues and difficulties?
You could use FTimerManager to start a timer (with ->setTimer) and then fire off a function once it ends.
You could theoretically:
- loop it and keep firing the function
- inside the function increment an update float;
-then try to access a UCurveFloat at a set percentage (current increment) to get the passed value
It all depends on the accuracy needed
1 Like
You can use a curve, and a “current position” member variable which is updated in “tick” if some “currently playing” flag is set. This requires no delay.
1 Like
Ok got a timeline in the component working
UMySceneComponent.h
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "Components/TimelineComponent.h"
#include "MySceneComponent.generated.h"
UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) , Blueprintable )
class DGP_API UMySceneComponent : public UActorComponent
{
GENERATED_BODY()
public:
// Sets default values for this component's properties
UMySceneComponent();
protected:
// Called when the game starts
virtual void BeginPlay() override;
public:
// Called every frame
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
float passedTime;
UPROPERTY(editAnywhere, BlueprintReadWrite)
UCurveFloat* TimelineCurve;
UPROPERTY(editAnywhere, BlueprintReadWrite)
UTimelineComponent* MyTimeline;
FOnTimelineFloat InterpFunction{};
UFUNCTION()
void TimelineUpdate(float val);
};
UMySceneComponent.cpp
// Fill out your copyright notice in the Description page of Project Settings.
#include "MySceneComponent.h"
#include "TimerManager.h"
#include "Curves/CurveFloat.h"
// Sets default values for this component's properties
UMySceneComponent::UMySceneComponent()
{
PrimaryComponentTick.bCanEverTick = false;
TimelineCurve = CreateDefaultSubobject<UCurveFloat>(TEXT("Timeline Curve"));
MyTimeline = CreateDefaultSubobject<UTimelineComponent>(TEXT("Timeline"));
}
// Called when the game starts
void UMySceneComponent::BeginPlay()
{
Super::BeginPlay();
if (TimelineCurve != nullptr) {
InterpFunction.BindUFunction(this, FName{ TEXT("TimelineUpdate") });
MyTimeline->AddInterpFloat(TimelineCurve, InterpFunction, FName{ TEXT("doUpdate") });
}
MyTimeline->SetLooping(true);
MyTimeline->SetPlayRate(1);
MyTimeline->SetTimelineLengthMode(TL_LastKeyFrame);
MyTimeline->PlayFromStart();
}
// Called every frame
void UMySceneComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
// ...
}
void UMySceneComponent::TimelineUpdate(float val) {
if (TimelineCurve != nullptr) {
bool isplay = MyTimeline->IsPlaying();
if (isplay == true) {
if (GEngine) {
GEngine->AddOnScreenDebugMessage(-1, 2, FColor::Green, GetName() + " Progress:" + FString::SanitizeFloat(val));
}
}
}
}
3 Likes