add grab sucess/fail checks with error messages

This commit is contained in:
Mamadou Babaei
2023-05-19 18:15:39 +02:00
parent df529ceacb
commit d1a1e0a9d8
@@ -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()