add grab sucess/fail checks with error messages

This commit is contained in:
Mamadou Babaei
2023-05-19 18:14:00 +02:00
parent f5f35e48b6
commit a29cba310e
@@ -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,13 +1234,19 @@ 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,13 +1268,19 @@ 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()