I have several animation asset pointers and I want to blend between two of them in C++.
I’ve tried using BlendSpace but it’s not working…
What I wanted to do was :
- Set old animation asset as first sample at
0.f,0.f,0.f
. - Set new animation asset as second sample at
1.f,0.f,0.f
- Set blend space value to
1.f,0.f,0.f
with interpolation set to0.3f
However, I’m facing two problems :
-
DeleteSample(const int32 Index)
makes my AnimationAsset pointer invalid (Seems like it deletes the reference to asset…). - Can’t edit BlendSamples.
GetBlendSamples()
returns a copy of samples andGetBlendSample(const int32 Index)
returns a const reference.
Because of TArray<struct FBlendSample> SampleData;
being protected
in BlendSpaceBase.h I can’t edit a sample once added and create a sample each time I want to change animation is really a bad idea because I will end up with thousand of useless samples…
#Has someone a better solution to blend animations ? Using blendspace or not but all in C++ ?
My current code, it is called at runtime to change animation :
UBlendSpace1D* const BlendSpace = NewObject<UBlendSpace1D>();
BlendSpace->SetSkeleton(Mesh->SkeletalMesh->Skeleton);
BlendSpace->AddSample(From, {0.f, 0.f, 0.f});
BlendSpace->AddSample(To, {1.f, 0.f, 0.f});
FInterpolationParameter AxisParams;
AxisParams.InterpolationTime = 0.3f;
AxisParams.InterpolationType = EFilterInterpolationType::BSIT_Linear;
BlendSpace->InterpolationParam[0] = AxisParams;
BlendSpace->InterpolationParam[1] = AxisParams;
BlendSpace->InterpolationParam[2] = AxisParams;
Mesh->PlayAnimation(BlendSpace, bLoop);
Mesh->GetSingleNodeInstance()->SetBlendSpaceInput({ 1.f,0.f,0.f });
But the blend space doesn’t start and my character stay in the default position.