在 Pawn 的骨架网格物体上播放动画

Playing an Animation on the SkeletalMesh of a Pawn

在 Unreal 4 中,我正在尝试从我们通过虚拟现实控制的 Pawn 播放 Gun 的动画。我尝试在具有骨架网格物体的角色上制作相同的动画,一切顺利。现在我在一个具有相同骨架网格物体的 Pawn 中,但没有播放动画。

SlickBoyMotionControllerPawn.cpp

// Function where I trigger the animation
void ASlickBoyMotionControllerPawn::Fire(ASlickBoyMotionController *Current)
{
        // Rest of the code that handle the fire of the gun

        // Current is the gun that fires (motion control)
        USkeletalMeshComponent* currentMesh = Current->GetHandMesh();
        if (currentMesh) {
            currentMesh->PlayAnimation(knockBack, false);
            currentMesh->PlayAnimation(trigger, false);
        }
}

SlickBoyMotionControllerPawn.h

UCLASS()
class SLICKBOY_API ASlickBoyMotionControllerPawn : public APawn, public IAttackable
{
    GENERATED_BODY()
public:
    // other stuff

    // Gun Anim
    UAnimSequence *knockBack;
    UAnimSequence *trigger;

    UFUNCTION()
    void Fire(class ASlickBoyMotionController* Hand);
}

请注意,所有内容都可以编译,我在执行代码时没有任何错误

knockback 序列将不会播放,因为您将立即用 trigger 覆盖动画。

currentMesh->PlayAnimation(knockBack, false);
currentMesh->PlayAnimation(trigger, false);

PlayAnimation是一个非阻塞调用,代码不会等到knockback播放完才开始trigger.

如果你想连续播放两个动画,使用Animation Composite