I’m using UE4.27
Hi! In my project I have a timeline component that I want to reuse for different purposes instead of creating a bunch of different timeline components which seems unnecessary. The problem I’m having though is that there doesn’t seem to be a way to clear the curves of the timeline once you’ve added one like so:
MyTimeLine->AddInterpFloat(MyCurve, TimelineUpdate);
Now, if I add a new InterpFloat, say, something like:
MyTimeLine->AddInterpFloat(MyCurve, AnotherTimelineUpdate);
From what I understand, now this value inside the timeline component:
TArray<struct FTimelineFloatTrack> InterpFloats;
Has two elements. And when I run the timeline it will run the function attached to the FOnTimelineFloat InterpFunc;
that’s inside each struct, that is, I’m running two different InterpFuncs at the same time.
How come I can’t clear this array, or remove one of its elements? It’s entirely possible I might be missing something obvious though.
Thanks!
Quick update: I tried to do something different but now I have a different problem:
I AddInterpFloat
to the BeginPlay function. Which only adds one element to the array.
Then my idea is to rebind the delegate instead:
Have these in my header:
FOnTimelineFloat TimelineUpdate;
FOnTimelineEvent TimelineFinished;
And in my .cpp BeginPlay I have:
MyTimeLine->AddInterpFloat(MyCurve, TimelineUpdate);
MyTimeLine->SetTimelineFinishedFunc(TimelineFinished);
And I have this one in a later place in my code:
TimelineUpdate.BindDynamic(this, &AEntity::Callback_TimelineUpdate);
TimelineFinished.BindDynamic(this, &AEntity::Callback_TimelineFinished);
And in another place I have:
TimelineUpdate.BindDynamic(this, &AEntity::Callback_AnotherTimelineUpdate);
TimelineFinished.BindDynamic(this, &AEntity::Callback_AnotherTimelineFinished);
Now the problem I’m having is that the delegate doesn’t seem to bind, not even on the first one. Nothing happens when the timeline is called. I’m confused. I have tried calling unbind to see if it makes a difference, it doesn’t.
EDIT: Ok, just did a test and the delegates are bound but they are not being run when the timeline is playing.
Another update: I noticed that if I bind the delegates before the AddInterpFloat (in the BeginPlay), then it works for that binding. But the timeline doesn’t respond to rebinding the delegates later. Is this a bug?
EDIT: In fact, even when the delegate is unbound after being set, the timeline still runs the function that should not be bound anymore.
1 Like
I managed to work around the problem by using a seperate delegate.
Like this:
Put these in the header:
// Timeline Variables
FOnTimelineFloat TimelineFloat;
FOnTimelineEvent TimelineFinished;
Then create these:
DECLARE_DYNAMIC_DELEGATE_OneParam(FOnTimeLineUpdate, float, PAlpha);
....
FOnTimeLineUpdate OnTimeLineUpdate;
In BeginPlay, do this:
TimelineFloat.BindDynamic(this, &AEntity::Callback_OnTimeLineUpdate);
TimelineFinished.BindDynamic(this, &AEntity::Callback_OnTimelineFinished);
MyTimeLine->AddInterpFloat(MyCurve, TimelineFloat);
MyTimeLine->SetTimelineFinishedFunc(TimelineFinished);
Then, you hook up the new seperate delegate like this:
OnTimeLineUpdate.BindDynamic(this, &AEntity::Callback_OneTimelineUpdate);
Then when the timeline runs, it calls the original delegate, which reroutes like this:
void AEntity::Callback_OnTimeLineUpdate(float PAlpha)
{
if (OnTimeLineUpdate.IsBound())
{
OnTimeLineUpdate.Execute(PAlpha);
}
}
It’s a very roundabout way of doing it but it seems to work.