Download

Get keyframe value from sequencer track section - how?

Hi all,

Feel like I’m missing something here. I’m working with sequencer and want to get and set the keyframe values in a track. I’ll worry about setting the value later, for now I just want to get it. Using UE 4.17.2 and the code below.

From my understanding, I need to get the KeyFrameStruct, which has a value, for the UMovieSceneFloatSection but my GetKeyStruct().IsValid() is always false. What am I missing?



if (SequencePlayer)
    {
        TArray<UMovieSceneSection*> Sections = SequenceAsset->GetMovieScene()->GetAllSections();
        for (UMovieSceneSection* Section : Sections)
        {
             TSet<FKeyHandle> KeyHandles;
             Section->GetKeyHandles(KeyHandles, Section->GetRange());

            TArray<FKeyHandle> FirstKeyHandleArray;
            FirstKeyHandleArray.Add(KeyHandles.Array()[0]);

            UMovieSceneFloatSection* FloatSection = (UMovieSceneFloatSection*)Section;

            if (FloatSection)
            {
                TSharedPtr<FStructOnScope> FloatPtr = FloatSection->GetKeyStruct(FirstKeyHandleArray);

                if (FloatPtr.IsValid())
                {
                    UE_LOG(LogTemp, Warning, TEXT("Valid float ptr"));
                }
                else
                { 
                    UE_LOG(LogTemp, Warning, TEXT("Invalid float ptr"));
                }
            }
            else
            {
                UE_LOG(LogTemp, Log, TEXT("Failed to cast to Float section"));
            }
        }

        // SequencePlayer->Play();
    }


You should be able to get the curve from the section.


FRichCurve& Curve = FloatSection->GetFloatCurve();

Then iterate over the keys of the float curve:


for (auto It(Curve.GetKeyIterator()); It; ++It)
{
    float Time = It->Time;
    float Value = It->Value;
    // etc.
}