How to get a Timeline component, adding in Blueprint, in C++?

I have a C++ class that extends USceneComponent. On it, I have a property for a UTimelineComponent like so:


UPROPERTY(EditAnywhere, BlueprintReadWrite)
        UTimelineComponent* TransitionTimeline;

I am then creating a Blueprint version of this class, and I want to be able to create the actual Timeline component in the Blueprint class, and for the above property to point to it. I can do this manually by doing something like this on the BP BeginPlay():

https://i.imgur.com/ImJn679.png

But I would much rather have this set up in C++. The issue is, I don’t know how to get hold of this BP-created timeline and point to it in C++.

UTimelineComponent is an UActorComponent, but my USceneComponent-derived class doesn’t seem to be able to get hold of ActorComponents attached to it. There is a GetChildrenComponents method, but it only returns attached USceneComponents so it doesn’t find the UTimelineComponent.

How can I do this?

Why don’t you create the timeline in C++ instead of creating it in BP? Then you can pass a curve from the BP for the timeline to use.

Instead of using a UTimelineComponent you have to use a FTimeline. UTimelineComponent is the blueprints implementation for FTimeline.

FTimeline is a struct, in your header just declare a variable: FTimeline MyTimeline;
Then in your cpp you can set a curve using MyTimeline.AddInterpFloat().

Just bind the delegates you need to get your timeline events and remember to tick the timeline calling MyTimeline.TickTimeline().

Let me know if you need help implementing this.