From c2f67fce2d831233e5076e02ed19916e1adf4db7 Mon Sep 17 00:00:00 2001 From: Mamadou Babaei Date: Fri, 12 May 2023 16:14:45 +0200 Subject: [PATCH] add grab sucess/fail checks with error messages --- .../SenseGlove/GameFramework/SGPawn.cpp | 29 ++++++++++++++----- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/Source/SenseGlove/Private/SenseGlove/GameFramework/SGPawn.cpp b/Source/SenseGlove/Private/SenseGlove/GameFramework/SGPawn.cpp index 441f1ed3..83256f10 100644 --- a/Source/SenseGlove/Private/SenseGlove/GameFramework/SGPawn.cpp +++ b/Source/SenseGlove/Private/SenseGlove/GameFramework/SGPawn.cpp @@ -42,6 +42,7 @@ #include "SenseGlove/Components/SGTouchComponent.h" #include "SenseGlove/Components/SGVirtualHandComponent.h" #include "SenseGlove/Components/SGWristTrackerComponent.h" +#include "SGLog/SGLog.h" struct ASGPawn::FImpl { @@ -1233,13 +1234,19 @@ void ASGPawn::GrabLeft(AActor* Actor) GrabComponent->GetAttachmentScaleRule(), GrabComponent->GetAttachmentWeldSimulatedBodies()) }; - FName SocketName{GrabComponent->GetAttachmentSocketName()}; + const FName SocketName{GrabComponent->GetAttachmentSocketName()}; ensureAlwaysMsgf(SocketName != NAME_None, TEXT("invalid attachment socket name!")); - Actor->AttachToComponent(HandLeft, MoveTemp(AttachmentRules), MoveTemp(SocketName)); - - ActorLeftHandGrabbing = Actor; + const bool bAttached = Actor->AttachToComponent(HandLeft, MoveTemp(AttachmentRules), SocketName); + if (bAttached) + { + ActorLeftHandGrabbing = Actor; + } + else + { + SGLOG_ERROR("Failed to grab the actor with the left hand!", Actor, SocketName); + } } void ASGPawn::GrabRight(AActor* Actor) @@ -1261,13 +1268,19 @@ void ASGPawn::GrabRight(AActor* Actor) GrabComponent->GetAttachmentScaleRule(), GrabComponent->GetAttachmentWeldSimulatedBodies()) }; - FName SocketName{GrabComponent->GetAttachmentSocketName()}; + const FName SocketName{GrabComponent->GetAttachmentSocketName()}; ensureAlwaysMsgf(SocketName != NAME_None, TEXT("invalid attachment socket name!")); - Actor->AttachToComponent(HandRight, MoveTemp(AttachmentRules), MoveTemp(SocketName)); - - ActorRightHandGrabbing = Actor; + const bool bAttached = Actor->AttachToComponent(HandRight, MoveTemp(AttachmentRules), SocketName); + if (bAttached) + { + ActorRightHandGrabbing = Actor; + } + else + { + SGLOG_ERROR("Failed to grab the actor with the right hand!", Actor, SocketName); + } } void ASGPawn::ReleaseLeft()