How do you properly use the blend space AddSample() function?

Taenick
Wed, 26 Oct 2016 23:27:45 +0000
Character & Animation

Hello,

First time posting, so if I am doing this wrong please let me know.

So I currently have a need to dynamically change the samples of a 1d blendspace at run time. Let me explain why. I have a stadium of a few thousand supporters who change between different idle animations. All of a sudden a score is scored and I want to blend from their idle animation to a cheering animation. So instead of having a different blend space for each transition (number of idle animations) x (number of cheering animation), it would be much nicer to just change the samples of a blend space to handle the transition.

So after seeing what I had available to me in C++, a 1d blend space has Add Sample or Edit Sample. So I have the following code samples for trying to change the samples:

if (BlendSpace1dPointer)
{
            BlendSpace1dPointer->ClearAllSamples();

            FBlendSample FirstBlendSample;
            FirstBlendSample.SampleValue.X = 0;
            FirstBlendSample.Animation = StartingAnimSequence;
            FirstBlendSample.bIsValid = true;

            BlendSpace1dPointer->AddSample(FirstBlendSample);

            FBlendSample SecondBlendSample;
            SecondBlendSample.SampleValue.X = 100;
            SecondBlendSample.Animation = EndingAnimSequence;
            SecondBlendSample.bIsValid = true;

            BlendSpace1dPointer->AddSample(SecondBlendSample);

            this->PlayAnimation(BlendSpace1dPointer, true);
}

Another example but this time using Edit Sample:

if (BlendSpace1dPointer)
    {

        TArray<FBlendSample> Samples = BlendSpace1dPointer->GetBlendSamples();

        BlendSpace1dPointer->EditSampleAnimation(Samples[0], StartingAnimSequence);
        BlendSpace1dPointer->EditSampleAnimation(Samples[1], EndingAnimSequence);

        this->PlayAnimation(BlendSpace1dPointer, true);
    }

With the provided examples I would expect it to play just the first animation sequence on loop but instead my model just stays in a T pose.

Even more confusing, if I go to the editor version of that 1d blend space, it now shows that it is using the new samples I set in the C++. And those samples stay changed even after I stop execution. Now if I click Apply Parameter Changes on the blend space in the editor and then start executing and just call play without adding or editing the samples, the model animates just as expected. So I tried following the logic that happens after you click Apply Parameter Changes in the editor and after calling some of the same functions after my previous code snippet, nothing works still.

After googling a bit, I saw one other guy had the same question as me but that was posted over 6 months ago and no one has replied. Here is the link to that post: https://answers.unrealengine.com/questions/378777/animation-blendspace-edit-specific-nodes-at-runtim.html

So my question for anyone, does anyone know how to use AddSample() or EditSample() of a 1d blend space at run time and not have your model stuck in a T pose after making said change?

Any help would be very much appreciated.

2 posts - 1 participant