How to get TimelineComponent direction?

Is there a way to get ETimelineDirection from a UTimelineComponent instance?

Yes, you can use

/** Helper function to get to the timeline direction enum */
ENGINE_API static UEnum* GetTimelineDirectionEnum();

Thank you for your quick answer.
Unfortunately you can’t call this specific static function on a UTimelineComponent instance.
I thought IsPlaying() or IsReversing() functions would solve the problem but these functions can’t tell whether the direction is Forward or Backward.

You are completely right, my bad.
I looked into it a bit more, and here is the code determining the Enum - UE4 Github Link

Since bReversePlayback is private, you need to use IsReversing() function. BUT IsReversing() will return false (not matter what) if the timeline is not currently playing, which is probably why your code might have not worked. Can you work around that limitation?

Basically yes: I’ve created a ETimelineDirection::Type Direction member variable. When timeline is playing (Play()) Direction is set to Forward, when Reverse() is called, it is set to Backward. Anyway, thanks for your research!

I believe the most clean alternative would be to create a GetReversePlayback() method, returning only bReversePlayback and recompile the engine. That way no workarounds would be needed.

Sorry to revive this but could someone tell me what that node is at the top because I’ve been struggling to find it for the last 2 hours

Utilities → Enum → Equal (Enum) or just type ==

Hello,
Add this variable into your .h file:

UPROPERTY()
TEnumAsByte<ETimelineDirection::Type> MyTimelineDirection;

Then use this function on your timeline you just need call this once, for example after binding the timeline or finished callbacks:

MyTimeline->SetDirectionPropertyName(FName(TEXT("MyTimelineDirection")));

The timeline automatically sets the direction property on a provided object given the following:

Timeline.SetPropertySetObject(UObject); // Object to set the property on
Timeline.SetDirectionPropertyName(FName); // Name of the UPROPERTY

So a final setup would look somethnig like this:
MyActor.h

FTimeline Timeline;

UPROPERTY()
TEnumAsByte<ETimelineDirection::Type> TimelineDirection;

MyActor.cpp

Timeline.SetPropertySetObject(this);
Timeline.SetDirectionPropertyName(FName("TimelineDirection"));

Then you can use the following variable and it will tell you the direction

TimelineDirection == ETimelineDirection::Forward

or

TimelineDirection == ETimelineDirection::Backward

good luck

1 Like