diff --git a/Source/SenseGlove/Private/SenseGlove/Animation/SGVirtualHandAnimInstanceProxy.cpp b/Source/SenseGlove/Private/SenseGlove/Animation/SGVirtualHandAnimInstanceProxy.cpp index b9f13fd5..2d3dfc80 100644 --- a/Source/SenseGlove/Private/SenseGlove/Animation/SGVirtualHandAnimInstanceProxy.cpp +++ b/Source/SenseGlove/Private/SenseGlove/Animation/SGVirtualHandAnimInstanceProxy.cpp @@ -43,6 +43,7 @@ #include "Containers/UnrealString.h" #include "Engine/SkeletalMesh.h" #include "Math/Rotator.h" +#include "SGLog/SGLog.h" #include "SenseGlove/Components/SGVirtualHandComponent.h" @@ -71,24 +72,25 @@ void FSGVirtualHandAnimInstanceProxy::PreEvaluateAnimation(UAnimInstance* InAnim return; } + BonesRotations.Empty(); + if (!VirtualHand->IsGloveConnected()) { return; } - BonesRotations.Empty(); BonesRotations = VirtualHand->GetFingersBonesRotations(); } bool FSGVirtualHandAnimInstanceProxy::Evaluate(FPoseContext& Output) { - USkeletalMeshComponent* HandMeshComponent{GetSkelMeshComponent()}; - if (!IsValid(HandMeshComponent)) + USGVirtualHandComponent* VirtualHand{Cast(GetSkelMeshComponent())}; + if (!IsValid(VirtualHand) && !VirtualHand->IsGloveConnected()) { return FAnimInstanceProxy::Evaluate(Output); } - const USkeletalMesh* HandMesh{HandMeshComponent-> + const USkeletalMesh* HandMesh{VirtualHand-> #if ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 1 GetSkeletalMeshAsset() #else @@ -115,7 +117,12 @@ bool FSGVirtualHandAnimInstanceProxy::Evaluate(FPoseContext& Output) FRotator BoneRotation(Bone.Value); const int32 BoneIndex = GetRequiredBones().GetPoseBoneIndexForBoneName(BoneName); - ensureAlwaysMsgf(BoneIndex != INDEX_NONE, TEXT("Invalid finger bone index!")); + if (BoneIndex == INDEX_NONE) + { + SGLOG_WARNING(FString::Printf(TEXT("Could not find a bone index for '%s' finger bone!"), + *BoneName.ToString())); + continue; + } FBoneReference BoneReference; BoneReference.BoneName = MoveTemp(BoneName); @@ -141,7 +148,7 @@ bool FSGVirtualHandAnimInstanceProxy::Evaluate(FPoseContext& Output) PoseContext.Pose.LocalBlendCSBoneTransforms(BoneTransforms, 1.0f); PoseContext.Pose.ConvertComponentPosesToLocalPoses(PoseContext.Pose, Output.Pose); - HandMeshComponent->MarkRenderStateDirty(); + VirtualHand->MarkRenderStateDirty(); } } } diff --git a/Source/SenseGlove/Private/SenseGlove/Components/SGVirtualHandComponent.cpp b/Source/SenseGlove/Private/SenseGlove/Components/SGVirtualHandComponent.cpp index 889bd209..883ad26e 100644 --- a/Source/SenseGlove/Private/SenseGlove/Components/SGVirtualHandComponent.cpp +++ b/Source/SenseGlove/Private/SenseGlove/Components/SGVirtualHandComponent.cpp @@ -318,8 +318,12 @@ const FTransform& USGVirtualHandComponent::GetFingerBoneRefTransform(const int32 const FReferenceSkeleton& ReferenceSkeleton{Pimpl->GetRefSkeleton()}; const int32 BoneIndex = ReferenceSkeleton.FindBoneIndex(BoneName); - ensureAlwaysMsgf(BoneIndex != INDEX_NONE, TEXT("Invalid virtual hand bone name '%s' or index!"), - *BoneName.ToString()); + if (BoneIndex == INDEX_NONE) + { + SGLOG_WARNING(FString::Printf(TEXT("Could not find a bone index for '%s' finger bone!"), + *BoneName.ToString())); + return FTransform::Identity; + } const FTransform& BoneTransform{ReferenceSkeleton.GetRefBonePose()[BoneIndex]}; return BoneTransform; @@ -491,7 +495,7 @@ bool USGVirtualHandComponent::FImpl::CheckGlove() const if (!bFoundGlove && bGloveWasPresent) { - SGLOG_ERROR(FString::Printf(TEXT("Could not find a %s glove"), + SGLOG_ERROR(FString::Printf(TEXT("Could not find a %s glove!"), (Owner->bRight ? TEXT("right-handed") : TEXT("left-handed")))); }