Hi.
I want to generate the Sequencer timeline from the code. That’s, I need to add tracks and keyframes in C++ in runtime.
I have found several similar questions like these:
But it doesn’t work for me.
Here is what I do:
- Create an actor in C++ and pass it reference to an existing in the scene empty ULevelSequence
(AnimGenerator.h)
UPROPERTY(EditAnywhere, BlueprintReadWrite)
ULevelSequence* SequenceAsset;
(AnimGenerator.cpp)
AnimGenerator::AnimGenerator()
{
Mesh1 = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("PlaneMesh1"));
RootComponent = Mesh1;
}
void AnimGenerator::BeginPlay()
{
Super::BeginPlay();
FGuid MyGuid = FUniqueObjectGuid::GetOrCreateIDForObject(this).GetGuid();
//doesn't work
//t1 = SequenceAsset->GetMovieScene()->AddTrack(UMovieScene3DTransformTrack::StaticClass(), MyGuid);
//doesn't work.
t1 = SequenceAsset->MovieScene->AddTrack(UMovieSceneAudioTrack::StaticClass(), MyGuid);
}
I tried to add different types of tracks. AddTrack() always returns nullptr. No crashes, no warnings. What am I missing?