add grab sucess/fail checks with error messages

This commit is contained in:
Mamadou Babaei
2023-05-12 16:14:45 +02:00
parent b87275ff97
commit 5ae267aff6
@@ -42,6 +42,7 @@
#include "SenseGlove/Components/SGTouchComponent.h" #include "SenseGlove/Components/SGTouchComponent.h"
#include "SenseGlove/Components/SGVirtualHandComponent.h" #include "SenseGlove/Components/SGVirtualHandComponent.h"
#include "SenseGlove/Components/SGWristTrackerComponent.h" #include "SenseGlove/Components/SGWristTrackerComponent.h"
#include "SGLog/SGLog.h"
struct ASGPawn::FImpl struct ASGPawn::FImpl
{ {
@@ -1233,14 +1234,20 @@ void ASGPawn::GrabLeft(AActor* Actor)
GrabComponent->GetAttachmentScaleRule(), GrabComponent->GetAttachmentScaleRule(),
GrabComponent->GetAttachmentWeldSimulatedBodies()) GrabComponent->GetAttachmentWeldSimulatedBodies())
}; };
FName SocketName{GrabComponent->GetAttachmentSocketName()};
const FName SocketName{GrabComponent->GetAttachmentSocketName()};
ensureAlwaysMsgf(SocketName != NAME_None, TEXT("invalid attachment socket name!")); ensureAlwaysMsgf(SocketName != NAME_None, TEXT("invalid attachment socket name!"));
Actor->AttachToComponent(HandLeft, MoveTemp(AttachmentRules), MoveTemp(SocketName)); const bool bAttached = Actor->AttachToComponent(HandLeft, MoveTemp(AttachmentRules), SocketName);
if (bAttached)
{
ActorLeftHandGrabbing = Actor; ActorLeftHandGrabbing = Actor;
} }
else
{
SGLOG_ERROR("Failed to grab the actor with the left hand!", Actor, SocketName);
}
}
void ASGPawn::GrabRight(AActor* Actor) void ASGPawn::GrabRight(AActor* Actor)
{ {
@@ -1261,14 +1268,20 @@ void ASGPawn::GrabRight(AActor* Actor)
GrabComponent->GetAttachmentScaleRule(), GrabComponent->GetAttachmentScaleRule(),
GrabComponent->GetAttachmentWeldSimulatedBodies()) GrabComponent->GetAttachmentWeldSimulatedBodies())
}; };
FName SocketName{GrabComponent->GetAttachmentSocketName()};
const FName SocketName{GrabComponent->GetAttachmentSocketName()};
ensureAlwaysMsgf(SocketName != NAME_None, TEXT("invalid attachment socket name!")); ensureAlwaysMsgf(SocketName != NAME_None, TEXT("invalid attachment socket name!"));
Actor->AttachToComponent(HandRight, MoveTemp(AttachmentRules), MoveTemp(SocketName)); const bool bAttached = Actor->AttachToComponent(HandRight, MoveTemp(AttachmentRules), SocketName);
if (bAttached)
{
ActorRightHandGrabbing = Actor; ActorRightHandGrabbing = Actor;
} }
else
{
SGLOG_ERROR("Failed to grab the actor with the right hand!", Actor, SocketName);
}
}
void ASGPawn::ReleaseLeft() void ASGPawn::ReleaseLeft()
{ {