Files
UnrealEngineUWP/Engine/Source/Runtime/AnimGraphRuntime/Private/AnimCustomInstance.cpp
Chris Gagnon 8fc25ea18e Merging //UE4/Dev-Main to Dev-Editor (//UE4/Dev-Editor)
#rb none

[CL 4676797 by Chris Gagnon in Dev-Editor branch]
2019-01-02 14:54:39 -05:00

63 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->AnimScriptInstance = nullptr;
}
}
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));
}