Files
UnrealEngineUWP/Engine/Source/Runtime/AnimGraphRuntime/Private/AnimCustomInstance.cpp
max chen bc8433e46c Sequencer: Correctly clear the active anim instance on a skeletal animation component when stopping a sequence.
This will stop any active anim-notifies when reverting to pre-animated state.

#jira UE-82283
#rb mike.zyracki
[FYI] ludovic.chabant

#ROBOMERGE-SOURCE: CL 9765069 in //UE4/Release-4.24/...
#ROBOMERGE-BOT: RELEASE (Release-4.24 -> Main) (v545-9751379)

[CL 9765071 by max chen in Main branch]
2019-10-23 17:51:03 -04:00

64 lines
2.3 KiB
C++

// Copyright 1998-2019 Epic Games, Inc. All Rights Reserved.
/*=============================================================================
UAnimCustomInstance.cpp: Single Node Tree Instance
Only plays one animation at a time.
=============================================================================*/
#include "AnimCustomInstance.h"
/////////////////////////////////////////////////////
// UAnimCustomInstance
/////////////////////////////////////////////////////
UAnimCustomInstance::UAnimCustomInstance(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
}
void UAnimCustomInstance::UnbindFromSkeletalMeshComponent(USkeletalMeshComponent* InSkeletalMeshComponent)
{
#if WITH_EDITOR
InSkeletalMeshComponent->SetUpdateAnimationInEditor(false);
#endif
if (InSkeletalMeshComponent->GetAnimationMode() == EAnimationMode::Type::AnimationCustomMode)
{
UAnimCustomInstance* SequencerInstance = Cast<UAnimCustomInstance>(InSkeletalMeshComponent->GetAnimInstance());
if (SequencerInstance)
{
InSkeletalMeshComponent->ClearAnimScriptInstance();
}
}
else if (InSkeletalMeshComponent->GetAnimationMode() == EAnimationMode::Type::AnimationBlueprint)
{
UAnimInstance* AnimInstance = InSkeletalMeshComponent->GetAnimInstance();
if (AnimInstance)
{
AnimInstance->Montage_Stop(0.0f);
AnimInstance->UpdateAnimation(0.0f, false);
}
// Update space bases to reset it back to ref pose
InSkeletalMeshComponent->RefreshBoneTransforms();
InSkeletalMeshComponent->RefreshSlaveComponents();
InSkeletalMeshComponent->UpdateComponentToWorld();
}
// if not game world, don't clean this up
if (InSkeletalMeshComponent->GetWorld() != nullptr && InSkeletalMeshComponent->GetWorld()->IsGameWorld() == false)
{
InSkeletalMeshComponent->ClearMotionVector();
}
}
bool UAnimCustomInstance::ShouldUseSequenceInstancePlayer(const USkeletalMeshComponent* SkeletalMeshComponent)
{
const USkeletalMesh* SkeletalMesh = SkeletalMeshComponent->SkeletalMesh;
// create proper anim instance to animate
UAnimInstance* AnimInstance = SkeletalMeshComponent->GetAnimInstance();
return (AnimInstance == nullptr || SkeletalMeshComponent->GetAnimationMode() != EAnimationMode::AnimationBlueprint ||
AnimInstance->GetClass() != SkeletalMeshComponent->AnimClass || !SkeletalMesh->Skeleton->IsCompatible(AnimInstance->CurrentSkeleton));
}