Hello all,
i’m trying to automatize the animation of (a lot of) pawns and would like not to have to define ~100 blendspaces and animblueprint by hand in the editor.
If i can get it to work, i’ll just have to create blueprints inheriting from this class and set the skeletal mesh and animations.
This subject seems to pop up every now and then, there are a few post on the answerhub, and even a wiki by Rama, but all of them seem to assume that the BlendSpace is created in the editor.
As you can see, i’m trying several methods (via the skeletal mesh component and the anim instance) to animate the mesh with the blendspace, none of them works so far.
I tried everything i could find related to animation and blendspace in the api documentation.
I can spawn the blueprint, but the mesh remains static so obviously i miss something.
I tried to set this in the blueprint, and i can see the debuging flow correctly going through everything.
I can’t check visually the blendspace, so i’m a bit lost and dry now.
Here’s the code:
void AYagPawn::BeginPlay()
{
Super::BeginPlay();
...]
// creating the BS (SMC_00 is a USkeletalMeshComponent)
ThisBlendSpace1D = NewObject<UBlendSpace1D>(this, UBlendSpace1D::StaticClass());
ThisBlendSpace1D->SetSkeleton(SMC_00->SkeletalMesh->Skeleton);
// setting a parameter for the BS
FBlendParameter BP_Speed;
BP_Speed.DisplayName = "Speed";
BP_Speed.GridNum = 4;
BP_Speed.Min = 0.f;
BP_Speed.Max = 100.f;
ThisBlendSpace1D->UpdateParameter(0, BP_Speed);
// adding two sample (at 0 and 100)
// IdleSequence and MoveSequence are UAnimSequence to be set in the BP inheriting this pawn class
FBlendSample IdleSample = FBlendSample(IdleSequence, FVector(0.f, 0.f, 0.f), false);
FBlendSample MoveSample = FBlendSample(MoveSequence, FVector(100.f, 0.f, 0.f), false);
ThisBlendSpace1D->AddSample(IdleSample);
ThisBlendSpace1D->AddSample(MoveSample);
// first method
SMC_00->PlayAnimation(ThisBlendSpace1D, true);
// second method
SMC_00->SetAnimation(ThisBlendSpace1D);
SMC_00->Play(true);
// third method
SMC_00->OverrideAnimationData(ThisBlendSpace1D, true, true, 0.f, 1.f);
// fourth method
BS_AnimInstance = Cast<UAnimSingleNodeInstance>(SMC_00->GetAnimInstance());
BS_AnimInstance->SetAnimationAsset(ThisBlendSpace1D);
BS_AnimInstance->PlayAnim(true, 1.f, 0.f);
}
void AYagPawn::Tick( float DeltaSeconds)
{
Super::Tick(DeltaSeconds);
...]
// update BS with Speed (a float)
BS_AnimInstance->SetBlendSpaceInput(FVector(Speed, 0.f, 0.f));
// useless in principle but i tried
SMC_00->OverrideAnimationData(ThisBlendSpace1D, true, true, 0.f, 1.f);
}
And here is the variables section in the BP:
As you can see, the BS is still empty (normal, it will be created in the begin play function at runtime) and both animations have default values.
Any idea ?
Thanks
Cedric
EDIT: i realized i wasn’t setting the animation mode, so i added this in the constructor:
SMC_00->SetAnimationMode(EAnimationMode::AnimationSingleNode);
But it still doesn’t work.