do not reigger OnGrabStateUpdated and OnTouchStateUpdated at all when the hand mesh is not valid or visible and also some other extra measures to make sure even if they are triggered they won't affect anything

This commit is contained in:
Mamadou Babaei
2024-08-16 18:00:56 +02:00
parent 82bf274f3a
commit 9f8d5afca3
4 changed files with 519 additions and 132 deletions
+1 -1
View File
@@ -34,7 +34,7 @@ This is a minor release focusing mainly on bringing OpenXR-compatible hand track
### Fixed ### Fixed
- Fixed a bug when the virtual hand inside the game is not visible but still have collisions with other objects inside the scene. - Fixed a bug when the virtual hand inside the game is not visible but still collides with other objects inside the scene, mistakenly triggering events like OnGrabStateUpdated and OnTouchStateUpdated.
- Fix various wrong Kismet script names and their class exports. - Fix various wrong Kismet script names and their class exports.
### Changed ### Changed
@@ -616,14 +616,14 @@ void USGVirtualHandComponent::FImpl::UpdateVisibility()
bGotMotionControllerData bGotMotionControllerData
&& MotionControllerData.bValid && MotionControllerData.bValid
&& MotionControllerData.DeviceVisualType == EXRVisualType::Hand; && MotionControllerData.DeviceVisualType == EXRVisualType::Hand;
const bool bIsHandVisible = Owner->GetVisibleFlag(); const bool bHandVisible = Owner->IsVisible();
const bool bShouldBeVisibleWhenHandDataUnavailable = Owner->IsVisibleWhenHandDataUnavailable(); const bool bShouldBeVisibleWhenHandDataUnavailable = Owner->IsVisibleWhenHandDataUnavailable();
bool bSetNewVisibility = false; bool bSetNewVisibility = false;
if (bHandDataAvailable) if (bHandDataAvailable)
{ {
if (bIsHandVisible) if (bHandVisible)
{ {
bSetNewVisibility = false; bSetNewVisibility = false;
} }
@@ -634,7 +634,7 @@ void USGVirtualHandComponent::FImpl::UpdateVisibility()
} }
else else
{ {
if (bIsHandVisible) if (bHandVisible)
{ {
if (bShouldBeVisibleWhenHandDataUnavailable) if (bShouldBeVisibleWhenHandDataUnavailable)
{ {
@@ -725,11 +725,24 @@ void ASGPawn::OnLeftThumbFingertipGrabColliderOverlapBegins(
(void) bFromSweep; (void) bFromSweep;
(void) SweepResult; (void) SweepResult;
if (USGGrabComponent::IsGrabbable(OtherActor)) if (!IsValid(LeftHandGrabState.Hand))
{ {
LeftHandGrabState.ActorThumbCanGrab = OtherActor; return;
Pimpl->TriggerGrabStateUpdatedEvent(LeftHandGrabState);
} }
const bool bHandVisible = LeftHandGrabState.Hand->IsVisible();
if (!bHandVisible)
{
return;
}
if (!USGGrabComponent::IsGrabbable(OtherActor))
{
return;
}
LeftHandGrabState.ActorThumbCanGrab = OtherActor;
Pimpl->TriggerGrabStateUpdatedEvent(LeftHandGrabState);
} }
void ASGPawn::OnLeftThumbFingertipGrabColliderOverlapEnds( void ASGPawn::OnLeftThumbFingertipGrabColliderOverlapEnds(
@@ -742,11 +755,18 @@ void ASGPawn::OnLeftThumbFingertipGrabColliderOverlapEnds(
(void) OtherComp; (void) OtherComp;
(void) OtherBodyIndex; (void) OtherBodyIndex;
if (LeftHandGrabState.ActorThumbCanGrab == OtherActor) if (!IsValid(LeftHandGrabState.Hand))
{ {
LeftHandGrabState.ActorThumbCanGrab = nullptr; return;
Pimpl->TriggerGrabStateUpdatedEvent(LeftHandGrabState);
} }
if (LeftHandGrabState.ActorThumbCanGrab != OtherActor)
{
return;
}
LeftHandGrabState.ActorThumbCanGrab = nullptr;
Pimpl->TriggerGrabStateUpdatedEvent(LeftHandGrabState);
} }
void ASGPawn::OnLeftIndexFingertipGrabColliderOverlapBegins( void ASGPawn::OnLeftIndexFingertipGrabColliderOverlapBegins(
@@ -763,11 +783,24 @@ void ASGPawn::OnLeftIndexFingertipGrabColliderOverlapBegins(
(void) bFromSweep; (void) bFromSweep;
(void) SweepResult; (void) SweepResult;
if (USGGrabComponent::IsGrabbable(OtherActor)) if (!IsValid(LeftHandGrabState.Hand))
{ {
LeftHandGrabState.ActorIndexCanGrab = OtherActor; return;
Pimpl->TriggerGrabStateUpdatedEvent(LeftHandGrabState);
} }
const bool bHandVisible = LeftHandGrabState.Hand->IsVisible();
if (!bHandVisible)
{
return;
}
if (!USGGrabComponent::IsGrabbable(OtherActor))
{
return;
}
LeftHandGrabState.ActorIndexCanGrab = OtherActor;
Pimpl->TriggerGrabStateUpdatedEvent(LeftHandGrabState);
} }
void ASGPawn::OnLeftIndexFingertipGrabColliderOverlapEnds( void ASGPawn::OnLeftIndexFingertipGrabColliderOverlapEnds(
@@ -780,11 +813,18 @@ void ASGPawn::OnLeftIndexFingertipGrabColliderOverlapEnds(
(void) OtherComp; (void) OtherComp;
(void) OtherBodyIndex; (void) OtherBodyIndex;
if (LeftHandGrabState.ActorIndexCanGrab == OtherActor) if (!IsValid(LeftHandGrabState.Hand))
{ {
LeftHandGrabState.ActorIndexCanGrab = nullptr; return;
Pimpl->TriggerGrabStateUpdatedEvent(LeftHandGrabState);
} }
if (LeftHandGrabState.ActorIndexCanGrab != OtherActor)
{
return;
}
LeftHandGrabState.ActorIndexCanGrab = nullptr;
Pimpl->TriggerGrabStateUpdatedEvent(LeftHandGrabState);
} }
void ASGPawn::OnLeftMiddleFingertipGrabColliderOverlapBegins( void ASGPawn::OnLeftMiddleFingertipGrabColliderOverlapBegins(
@@ -801,11 +841,24 @@ void ASGPawn::OnLeftMiddleFingertipGrabColliderOverlapBegins(
(void) bFromSweep; (void) bFromSweep;
(void) SweepResult; (void) SweepResult;
if (USGGrabComponent::IsGrabbable(OtherActor)) if (!IsValid(LeftHandGrabState.Hand))
{ {
LeftHandGrabState.ActorMiddleCanGrab = OtherActor; return;
Pimpl->TriggerGrabStateUpdatedEvent(LeftHandGrabState);
} }
const bool bHandVisible = LeftHandGrabState.Hand->IsVisible();
if (!bHandVisible)
{
return;
}
if (!USGGrabComponent::IsGrabbable(OtherActor))
{
return;
}
LeftHandGrabState.ActorMiddleCanGrab = OtherActor;
Pimpl->TriggerGrabStateUpdatedEvent(LeftHandGrabState);
} }
void ASGPawn::OnLeftMiddleFingertipGrabColliderOverlapEnds( void ASGPawn::OnLeftMiddleFingertipGrabColliderOverlapEnds(
@@ -818,11 +871,18 @@ void ASGPawn::OnLeftMiddleFingertipGrabColliderOverlapEnds(
(void) OtherComp; (void) OtherComp;
(void) OtherBodyIndex; (void) OtherBodyIndex;
if (LeftHandGrabState.ActorMiddleCanGrab == OtherActor) if (!IsValid(LeftHandGrabState.Hand))
{ {
LeftHandGrabState.ActorMiddleCanGrab = nullptr; return;
Pimpl->TriggerGrabStateUpdatedEvent(LeftHandGrabState);
} }
if (LeftHandGrabState.ActorMiddleCanGrab != OtherActor)
{
return;
}
LeftHandGrabState.ActorMiddleCanGrab = nullptr;
Pimpl->TriggerGrabStateUpdatedEvent(LeftHandGrabState);
} }
void ASGPawn::OnLeftThumbFingertipTouchColliderOverlapBegins( void ASGPawn::OnLeftThumbFingertipTouchColliderOverlapBegins(
@@ -839,12 +899,25 @@ void ASGPawn::OnLeftThumbFingertipTouchColliderOverlapBegins(
(void) bFromSweep; (void) bFromSweep;
(void) SweepResult; (void) SweepResult;
if (USGTouchComponent::IsTouchable(OtherActor)) if (!IsValid(LeftHandTouchState.Hand))
{ {
LeftHandTouchState.ActorThumbTouching = OtherActor; return;
Pimpl->TriggerTouchStateUpdatedEvent(LeftHandTouchState);
Pimpl->TriggerBeginTouch(LeftHandTouchState.Hand, OtherActor);
} }
const bool bHandVisible = LeftHandTouchState.Hand->IsVisible();
if (!bHandVisible)
{
return;
}
if (!USGTouchComponent::IsTouchable(OtherActor))
{
return;
}
LeftHandTouchState.ActorThumbTouching = OtherActor;
Pimpl->TriggerTouchStateUpdatedEvent(LeftHandTouchState);
Pimpl->TriggerBeginTouch(LeftHandTouchState.Hand, OtherActor);
} }
void ASGPawn::OnLeftThumbFingertipTouchColliderOverlapEnds( void ASGPawn::OnLeftThumbFingertipTouchColliderOverlapEnds(
@@ -857,12 +930,19 @@ void ASGPawn::OnLeftThumbFingertipTouchColliderOverlapEnds(
(void) OtherComp; (void) OtherComp;
(void) OtherBodyIndex; (void) OtherBodyIndex;
if (LeftHandTouchState.ActorThumbTouching == OtherActor) if (!IsValid(LeftHandTouchState.Hand))
{ {
LeftHandTouchState.ActorThumbTouching = nullptr; return;
Pimpl->TriggerTouchStateUpdatedEvent(LeftHandTouchState);
Pimpl->TriggerEndTouch(LeftHandTouchState.Hand, OtherActor);
} }
if (LeftHandTouchState.ActorThumbTouching != OtherActor)
{
return;
}
LeftHandTouchState.ActorThumbTouching = nullptr;
Pimpl->TriggerTouchStateUpdatedEvent(LeftHandTouchState);
Pimpl->TriggerEndTouch(LeftHandTouchState.Hand, OtherActor);
} }
void ASGPawn::OnLeftIndexFingertipTouchColliderOverlapBegins( void ASGPawn::OnLeftIndexFingertipTouchColliderOverlapBegins(
@@ -879,12 +959,25 @@ void ASGPawn::OnLeftIndexFingertipTouchColliderOverlapBegins(
(void) bFromSweep; (void) bFromSweep;
(void) SweepResult; (void) SweepResult;
if (USGTouchComponent::IsTouchable(OtherActor)) if (!IsValid(LeftHandTouchState.Hand))
{ {
LeftHandTouchState.ActorIndexTouching = OtherActor; return;
Pimpl->TriggerTouchStateUpdatedEvent(LeftHandTouchState);
Pimpl->TriggerBeginTouch(LeftHandTouchState.Hand, OtherActor);
} }
const bool bHandVisible = LeftHandTouchState.Hand->IsVisible();
if (!bHandVisible)
{
return;
}
if (!USGTouchComponent::IsTouchable(OtherActor))
{
return;
}
LeftHandTouchState.ActorIndexTouching = OtherActor;
Pimpl->TriggerTouchStateUpdatedEvent(LeftHandTouchState);
Pimpl->TriggerBeginTouch(LeftHandTouchState.Hand, OtherActor);
} }
void ASGPawn::OnLeftIndexFingertipTouchColliderOverlapEnds( void ASGPawn::OnLeftIndexFingertipTouchColliderOverlapEnds(
@@ -897,12 +990,19 @@ void ASGPawn::OnLeftIndexFingertipTouchColliderOverlapEnds(
(void) OtherComp; (void) OtherComp;
(void) OtherBodyIndex; (void) OtherBodyIndex;
if (LeftHandTouchState.ActorIndexTouching == OtherActor) if (!IsValid(LeftHandTouchState.Hand))
{ {
LeftHandTouchState.ActorIndexTouching = nullptr; return;
Pimpl->TriggerTouchStateUpdatedEvent(LeftHandTouchState);
Pimpl->TriggerEndTouch(LeftHandTouchState.Hand, OtherActor);
} }
if (LeftHandTouchState.ActorIndexTouching != OtherActor)
{
return;
}
LeftHandTouchState.ActorIndexTouching = nullptr;
Pimpl->TriggerTouchStateUpdatedEvent(LeftHandTouchState);
Pimpl->TriggerEndTouch(LeftHandTouchState.Hand, OtherActor);
} }
void ASGPawn::OnLeftMiddleFingertipTouchColliderOverlapBegins( void ASGPawn::OnLeftMiddleFingertipTouchColliderOverlapBegins(
@@ -919,12 +1019,25 @@ void ASGPawn::OnLeftMiddleFingertipTouchColliderOverlapBegins(
(void) bFromSweep; (void) bFromSweep;
(void) SweepResult; (void) SweepResult;
if (USGTouchComponent::IsTouchable(OtherActor)) if (!IsValid(LeftHandTouchState.Hand))
{ {
LeftHandTouchState.ActorMiddleTouching = OtherActor; return;
Pimpl->TriggerTouchStateUpdatedEvent(LeftHandTouchState);
Pimpl->TriggerBeginTouch(LeftHandTouchState.Hand, OtherActor);
} }
const bool bHandVisible = LeftHandTouchState.Hand->IsVisible();
if (!bHandVisible)
{
return;
}
if (!USGTouchComponent::IsTouchable(OtherActor))
{
return;
}
LeftHandTouchState.ActorMiddleTouching = OtherActor;
Pimpl->TriggerTouchStateUpdatedEvent(LeftHandTouchState);
Pimpl->TriggerBeginTouch(LeftHandTouchState.Hand, OtherActor);
} }
void ASGPawn::OnLeftMiddleFingertipTouchColliderOverlapEnds( void ASGPawn::OnLeftMiddleFingertipTouchColliderOverlapEnds(
@@ -937,12 +1050,19 @@ void ASGPawn::OnLeftMiddleFingertipTouchColliderOverlapEnds(
(void) OtherComp; (void) OtherComp;
(void) OtherBodyIndex; (void) OtherBodyIndex;
if (LeftHandTouchState.ActorMiddleTouching == OtherActor) if (!IsValid(LeftHandTouchState.Hand))
{ {
LeftHandTouchState.ActorMiddleTouching = nullptr; return;
Pimpl->TriggerTouchStateUpdatedEvent(LeftHandTouchState);
Pimpl->TriggerEndTouch(LeftHandTouchState.Hand, OtherActor);
} }
if (LeftHandTouchState.ActorMiddleTouching != OtherActor)
{
return;
}
LeftHandTouchState.ActorMiddleTouching = nullptr;
Pimpl->TriggerTouchStateUpdatedEvent(LeftHandTouchState);
Pimpl->TriggerEndTouch(LeftHandTouchState.Hand, OtherActor);
} }
void ASGPawn::OnLeftRingFingertipTouchColliderOverlapBegins( void ASGPawn::OnLeftRingFingertipTouchColliderOverlapBegins(
@@ -959,12 +1079,25 @@ void ASGPawn::OnLeftRingFingertipTouchColliderOverlapBegins(
(void) bFromSweep; (void) bFromSweep;
(void) SweepResult; (void) SweepResult;
if (USGTouchComponent::IsTouchable(OtherActor)) if (!IsValid(LeftHandTouchState.Hand))
{ {
LeftHandTouchState.ActorRingTouching = OtherActor; return;
Pimpl->TriggerTouchStateUpdatedEvent(LeftHandTouchState);
Pimpl->TriggerBeginTouch(LeftHandTouchState.Hand, OtherActor);
} }
const bool bHandVisible = LeftHandTouchState.Hand->IsVisible();
if (!bHandVisible)
{
return;
}
if (!USGTouchComponent::IsTouchable(OtherActor))
{
return;
}
LeftHandTouchState.ActorRingTouching = OtherActor;
Pimpl->TriggerTouchStateUpdatedEvent(LeftHandTouchState);
Pimpl->TriggerBeginTouch(LeftHandTouchState.Hand, OtherActor);
} }
void ASGPawn::OnLeftRingFingertipTouchColliderOverlapEnds( void ASGPawn::OnLeftRingFingertipTouchColliderOverlapEnds(
@@ -977,12 +1110,19 @@ void ASGPawn::OnLeftRingFingertipTouchColliderOverlapEnds(
(void) OtherComp; (void) OtherComp;
(void) OtherBodyIndex; (void) OtherBodyIndex;
if (LeftHandTouchState.ActorRingTouching == OtherActor) if (!IsValid(LeftHandTouchState.Hand))
{ {
LeftHandTouchState.ActorRingTouching = nullptr; return;
Pimpl->TriggerTouchStateUpdatedEvent(LeftHandTouchState);
Pimpl->TriggerEndTouch(LeftHandTouchState.Hand, OtherActor);
} }
if (LeftHandTouchState.ActorRingTouching != OtherActor)
{
return;
}
LeftHandTouchState.ActorRingTouching = nullptr;
Pimpl->TriggerTouchStateUpdatedEvent(LeftHandTouchState);
Pimpl->TriggerEndTouch(LeftHandTouchState.Hand, OtherActor);
} }
void ASGPawn::OnLeftPinkyFingertipTouchColliderOverlapBegins( void ASGPawn::OnLeftPinkyFingertipTouchColliderOverlapBegins(
@@ -999,12 +1139,25 @@ void ASGPawn::OnLeftPinkyFingertipTouchColliderOverlapBegins(
(void) bFromSweep; (void) bFromSweep;
(void) SweepResult; (void) SweepResult;
if (USGTouchComponent::IsTouchable(OtherActor)) if (!IsValid(LeftHandTouchState.Hand))
{ {
LeftHandTouchState.ActorPinkyTouching = OtherActor; return;
Pimpl->TriggerTouchStateUpdatedEvent(LeftHandTouchState);
Pimpl->TriggerBeginTouch(LeftHandTouchState.Hand, OtherActor);
} }
const bool bHandVisible = LeftHandTouchState.Hand->IsVisible();
if (!bHandVisible)
{
return;
}
if (!USGTouchComponent::IsTouchable(OtherActor))
{
return;
}
LeftHandTouchState.ActorPinkyTouching = OtherActor;
Pimpl->TriggerTouchStateUpdatedEvent(LeftHandTouchState);
Pimpl->TriggerBeginTouch(LeftHandTouchState.Hand, OtherActor);
} }
void ASGPawn::OnLeftPinkyFingertipTouchColliderOverlapEnds( void ASGPawn::OnLeftPinkyFingertipTouchColliderOverlapEnds(
@@ -1017,12 +1170,19 @@ void ASGPawn::OnLeftPinkyFingertipTouchColliderOverlapEnds(
(void) OtherComp; (void) OtherComp;
(void) OtherBodyIndex; (void) OtherBodyIndex;
if (LeftHandTouchState.ActorPinkyTouching == OtherActor) if (!IsValid(LeftHandTouchState.Hand))
{ {
LeftHandTouchState.ActorPinkyTouching = nullptr; return;
Pimpl->TriggerTouchStateUpdatedEvent(LeftHandTouchState);
Pimpl->TriggerEndTouch(LeftHandTouchState.Hand, OtherActor);
} }
if (LeftHandTouchState.ActorPinkyTouching != OtherActor)
{
return;
}
LeftHandTouchState.ActorPinkyTouching = nullptr;
Pimpl->TriggerTouchStateUpdatedEvent(LeftHandTouchState);
Pimpl->TriggerEndTouch(LeftHandTouchState.Hand, OtherActor);
} }
void ASGPawn::OnRightThumbFingertipGrabColliderOverlapBegins( void ASGPawn::OnRightThumbFingertipGrabColliderOverlapBegins(
@@ -1039,11 +1199,24 @@ void ASGPawn::OnRightThumbFingertipGrabColliderOverlapBegins(
(void) bFromSweep; (void) bFromSweep;
(void) SweepResult; (void) SweepResult;
if (USGGrabComponent::IsGrabbable(OtherActor)) if (!IsValid(RightHandGrabState.Hand))
{ {
RightHandGrabState.ActorThumbCanGrab = OtherActor; return;
Pimpl->TriggerGrabStateUpdatedEvent(RightHandGrabState);
} }
const bool bHandVisible = RightHandGrabState.Hand->IsVisible();
if (!bHandVisible)
{
return;
}
if (!USGGrabComponent::IsGrabbable(OtherActor))
{
return;
}
RightHandGrabState.ActorThumbCanGrab = OtherActor;
Pimpl->TriggerGrabStateUpdatedEvent(RightHandGrabState);
} }
void ASGPawn::OnRightThumbFingertipGrabColliderOverlapEnds( void ASGPawn::OnRightThumbFingertipGrabColliderOverlapEnds(
@@ -1056,11 +1229,18 @@ void ASGPawn::OnRightThumbFingertipGrabColliderOverlapEnds(
(void) OtherComp; (void) OtherComp;
(void) OtherBodyIndex; (void) OtherBodyIndex;
if (RightHandGrabState.ActorThumbCanGrab == OtherActor) if (!IsValid(RightHandGrabState.Hand))
{ {
RightHandGrabState.ActorThumbCanGrab = nullptr; return;
Pimpl->TriggerGrabStateUpdatedEvent(RightHandGrabState);
} }
if (RightHandGrabState.ActorThumbCanGrab != OtherActor)
{
return;
}
RightHandGrabState.ActorThumbCanGrab = nullptr;
Pimpl->TriggerGrabStateUpdatedEvent(RightHandGrabState);
} }
void ASGPawn::OnRightIndexFingertipGrabColliderOverlapBegins( void ASGPawn::OnRightIndexFingertipGrabColliderOverlapBegins(
@@ -1077,11 +1257,24 @@ void ASGPawn::OnRightIndexFingertipGrabColliderOverlapBegins(
(void) bFromSweep; (void) bFromSweep;
(void) SweepResult; (void) SweepResult;
if (USGGrabComponent::IsGrabbable(OtherActor)) if (!IsValid(RightHandGrabState.Hand))
{ {
RightHandGrabState.ActorIndexCanGrab = OtherActor; return;
Pimpl->TriggerGrabStateUpdatedEvent(RightHandGrabState);
} }
const bool bHandVisible = RightHandGrabState.Hand->IsVisible();
if (!bHandVisible)
{
return;
}
if (!USGGrabComponent::IsGrabbable(OtherActor))
{
return;
}
RightHandGrabState.ActorIndexCanGrab = OtherActor;
Pimpl->TriggerGrabStateUpdatedEvent(RightHandGrabState);
} }
void ASGPawn::OnRightIndexFingertipGrabColliderOverlapEnds( void ASGPawn::OnRightIndexFingertipGrabColliderOverlapEnds(
@@ -1094,11 +1287,18 @@ void ASGPawn::OnRightIndexFingertipGrabColliderOverlapEnds(
(void) OtherComp; (void) OtherComp;
(void) OtherBodyIndex; (void) OtherBodyIndex;
if (RightHandGrabState.ActorThumbCanGrab == OtherActor) if (!IsValid(RightHandGrabState.Hand))
{ {
RightHandGrabState.ActorIndexCanGrab = nullptr; return;
Pimpl->TriggerGrabStateUpdatedEvent(RightHandGrabState);
} }
if (RightHandGrabState.ActorThumbCanGrab != OtherActor)
{
return;
}
RightHandGrabState.ActorIndexCanGrab = nullptr;
Pimpl->TriggerGrabStateUpdatedEvent(RightHandGrabState);
} }
void ASGPawn::OnRightMiddleFingertipGrabColliderOverlapBegins( void ASGPawn::OnRightMiddleFingertipGrabColliderOverlapBegins(
@@ -1115,11 +1315,24 @@ void ASGPawn::OnRightMiddleFingertipGrabColliderOverlapBegins(
(void) bFromSweep; (void) bFromSweep;
(void) SweepResult; (void) SweepResult;
if (USGGrabComponent::IsGrabbable(OtherActor)) if (!IsValid(RightHandGrabState.Hand))
{ {
RightHandGrabState.ActorMiddleCanGrab = OtherActor; return;
Pimpl->TriggerGrabStateUpdatedEvent(RightHandGrabState);
} }
const bool bHandVisible = RightHandGrabState.Hand->IsVisible();
if (!bHandVisible)
{
return;
}
if (!USGGrabComponent::IsGrabbable(OtherActor))
{
return;
}
RightHandGrabState.ActorMiddleCanGrab = OtherActor;
Pimpl->TriggerGrabStateUpdatedEvent(RightHandGrabState);
} }
void ASGPawn::OnRightMiddleFingertipGrabColliderOverlapEnds( void ASGPawn::OnRightMiddleFingertipGrabColliderOverlapEnds(
@@ -1132,11 +1345,18 @@ void ASGPawn::OnRightMiddleFingertipGrabColliderOverlapEnds(
(void) OtherComp; (void) OtherComp;
(void) OtherBodyIndex; (void) OtherBodyIndex;
if (RightHandGrabState.ActorMiddleCanGrab == OtherActor) if (!IsValid(RightHandGrabState.Hand))
{ {
RightHandGrabState.ActorMiddleCanGrab = nullptr; return;
Pimpl->TriggerGrabStateUpdatedEvent(RightHandGrabState);
} }
if (RightHandGrabState.ActorMiddleCanGrab != OtherActor)
{
return;
}
RightHandGrabState.ActorMiddleCanGrab = nullptr;
Pimpl->TriggerGrabStateUpdatedEvent(RightHandGrabState);
} }
void ASGPawn::OnRightThumbFingertipTouchColliderOverlapBegins( void ASGPawn::OnRightThumbFingertipTouchColliderOverlapBegins(
@@ -1153,12 +1373,25 @@ void ASGPawn::OnRightThumbFingertipTouchColliderOverlapBegins(
(void) bFromSweep; (void) bFromSweep;
(void) SweepResult; (void) SweepResult;
if (USGTouchComponent::IsTouchable(OtherActor)) if (!IsValid(RightHandTouchState.Hand))
{ {
RightHandTouchState.ActorThumbTouching = OtherActor; return;
Pimpl->TriggerTouchStateUpdatedEvent(RightHandTouchState);
Pimpl->TriggerBeginTouch(RightHandTouchState.Hand, OtherActor);
} }
const bool bHandVisible = RightHandTouchState.Hand->IsVisible();
if (!bHandVisible)
{
return;
}
if (!USGTouchComponent::IsTouchable(OtherActor))
{
return;
}
RightHandTouchState.ActorThumbTouching = OtherActor;
Pimpl->TriggerTouchStateUpdatedEvent(RightHandTouchState);
Pimpl->TriggerBeginTouch(RightHandTouchState.Hand, OtherActor);
} }
void ASGPawn::OnRightThumbFingertipTouchColliderOverlapEnds( void ASGPawn::OnRightThumbFingertipTouchColliderOverlapEnds(
@@ -1171,12 +1404,19 @@ void ASGPawn::OnRightThumbFingertipTouchColliderOverlapEnds(
(void) OtherComp; (void) OtherComp;
(void) OtherBodyIndex; (void) OtherBodyIndex;
if (RightHandTouchState.ActorThumbTouching == OtherActor) if (!IsValid(RightHandTouchState.Hand))
{ {
RightHandTouchState.ActorThumbTouching = nullptr; return;
Pimpl->TriggerTouchStateUpdatedEvent(RightHandTouchState);
Pimpl->TriggerEndTouch(RightHandTouchState.Hand, OtherActor);
} }
if (RightHandTouchState.ActorThumbTouching != OtherActor)
{
return;
}
RightHandTouchState.ActorThumbTouching = nullptr;
Pimpl->TriggerTouchStateUpdatedEvent(RightHandTouchState);
Pimpl->TriggerEndTouch(RightHandTouchState.Hand, OtherActor);
} }
void ASGPawn::OnRightIndexFingertipTouchColliderOverlapBegins( void ASGPawn::OnRightIndexFingertipTouchColliderOverlapBegins(
@@ -1193,12 +1433,25 @@ void ASGPawn::OnRightIndexFingertipTouchColliderOverlapBegins(
(void) bFromSweep; (void) bFromSweep;
(void) SweepResult; (void) SweepResult;
if (USGTouchComponent::IsTouchable(OtherActor)) if (!IsValid(RightHandTouchState.Hand))
{ {
RightHandTouchState.ActorIndexTouching = OtherActor; return;
Pimpl->TriggerTouchStateUpdatedEvent(RightHandTouchState);
Pimpl->TriggerBeginTouch(RightHandTouchState.Hand, OtherActor);
} }
const bool bHandVisible = RightHandTouchState.Hand->IsVisible();
if (!bHandVisible)
{
return;
}
if (!USGTouchComponent::IsTouchable(OtherActor))
{
return;
}
RightHandTouchState.ActorIndexTouching = OtherActor;
Pimpl->TriggerTouchStateUpdatedEvent(RightHandTouchState);
Pimpl->TriggerBeginTouch(RightHandTouchState.Hand, OtherActor);
} }
void ASGPawn::OnRightIndexFingertipTouchColliderOverlapEnds( void ASGPawn::OnRightIndexFingertipTouchColliderOverlapEnds(
@@ -1211,12 +1464,19 @@ void ASGPawn::OnRightIndexFingertipTouchColliderOverlapEnds(
(void) OtherComp; (void) OtherComp;
(void) OtherBodyIndex; (void) OtherBodyIndex;
if (RightHandTouchState.ActorIndexTouching == OtherActor) if (!IsValid(RightHandTouchState.Hand))
{ {
RightHandTouchState.ActorIndexTouching = nullptr; return;
Pimpl->TriggerTouchStateUpdatedEvent(RightHandTouchState);
Pimpl->TriggerEndTouch(RightHandTouchState.Hand, OtherActor);
} }
if (RightHandTouchState.ActorIndexTouching != OtherActor)
{
return;
}
RightHandTouchState.ActorIndexTouching = nullptr;
Pimpl->TriggerTouchStateUpdatedEvent(RightHandTouchState);
Pimpl->TriggerEndTouch(RightHandTouchState.Hand, OtherActor);
} }
void ASGPawn::OnRightMiddleFingertipTouchColliderOverlapBegins( void ASGPawn::OnRightMiddleFingertipTouchColliderOverlapBegins(
@@ -1233,12 +1493,25 @@ void ASGPawn::OnRightMiddleFingertipTouchColliderOverlapBegins(
(void) bFromSweep; (void) bFromSweep;
(void) SweepResult; (void) SweepResult;
if (USGTouchComponent::IsTouchable(OtherActor)) if (!IsValid(RightHandTouchState.Hand))
{ {
RightHandTouchState.ActorMiddleTouching = OtherActor; return;
Pimpl->TriggerTouchStateUpdatedEvent(RightHandTouchState);
Pimpl->TriggerBeginTouch(RightHandTouchState.Hand, OtherActor);
} }
const bool bHandVisible = RightHandTouchState.Hand->IsVisible();
if (!bHandVisible)
{
return;
}
if (!USGTouchComponent::IsTouchable(OtherActor))
{
return;
}
RightHandTouchState.ActorMiddleTouching = OtherActor;
Pimpl->TriggerTouchStateUpdatedEvent(RightHandTouchState);
Pimpl->TriggerBeginTouch(RightHandTouchState.Hand, OtherActor);
} }
void ASGPawn::OnRightMiddleFingertipTouchColliderOverlapEnds( void ASGPawn::OnRightMiddleFingertipTouchColliderOverlapEnds(
@@ -1251,12 +1524,19 @@ void ASGPawn::OnRightMiddleFingertipTouchColliderOverlapEnds(
(void) OtherComp; (void) OtherComp;
(void) OtherBodyIndex; (void) OtherBodyIndex;
if (RightHandTouchState.ActorMiddleTouching == OtherActor) if (!IsValid(RightHandTouchState.Hand))
{ {
RightHandTouchState.ActorMiddleTouching = nullptr; return;
Pimpl->TriggerTouchStateUpdatedEvent(RightHandTouchState);
Pimpl->TriggerEndTouch(RightHandTouchState.Hand, OtherActor);
} }
if (RightHandTouchState.ActorMiddleTouching != OtherActor)
{
return;
}
RightHandTouchState.ActorMiddleTouching = nullptr;
Pimpl->TriggerTouchStateUpdatedEvent(RightHandTouchState);
Pimpl->TriggerEndTouch(RightHandTouchState.Hand, OtherActor);
} }
void ASGPawn::OnRightRingFingertipTouchColliderOverlapBegins( void ASGPawn::OnRightRingFingertipTouchColliderOverlapBegins(
@@ -1273,12 +1553,25 @@ void ASGPawn::OnRightRingFingertipTouchColliderOverlapBegins(
(void) bFromSweep; (void) bFromSweep;
(void) SweepResult; (void) SweepResult;
if (USGTouchComponent::IsTouchable(OtherActor)) if (!IsValid(RightHandTouchState.Hand))
{ {
RightHandTouchState.ActorRingTouching = OtherActor; return;
Pimpl->TriggerTouchStateUpdatedEvent(RightHandTouchState);
Pimpl->TriggerBeginTouch(RightHandTouchState.Hand, OtherActor);
} }
const bool bHandVisible = RightHandTouchState.Hand->IsVisible();
if (!bHandVisible)
{
return;
}
if (!USGTouchComponent::IsTouchable(OtherActor))
{
return;
}
RightHandTouchState.ActorRingTouching = OtherActor;
Pimpl->TriggerTouchStateUpdatedEvent(RightHandTouchState);
Pimpl->TriggerBeginTouch(RightHandTouchState.Hand, OtherActor);
} }
void ASGPawn::OnRightRingFingertipTouchColliderOverlapEnds( void ASGPawn::OnRightRingFingertipTouchColliderOverlapEnds(
@@ -1291,12 +1584,19 @@ void ASGPawn::OnRightRingFingertipTouchColliderOverlapEnds(
(void) OtherComp; (void) OtherComp;
(void) OtherBodyIndex; (void) OtherBodyIndex;
if (RightHandTouchState.ActorRingTouching == OtherActor) if (!IsValid(RightHandTouchState.Hand))
{ {
RightHandTouchState.ActorRingTouching = nullptr; return;
Pimpl->TriggerTouchStateUpdatedEvent(RightHandTouchState);
Pimpl->TriggerEndTouch(RightHandTouchState.Hand, OtherActor);
} }
if (RightHandTouchState.ActorRingTouching != OtherActor)
{
return;
}
RightHandTouchState.ActorRingTouching = nullptr;
Pimpl->TriggerTouchStateUpdatedEvent(RightHandTouchState);
Pimpl->TriggerEndTouch(RightHandTouchState.Hand, OtherActor);
} }
void ASGPawn::OnRightPinkyFingertipTouchColliderOverlapBegins( void ASGPawn::OnRightPinkyFingertipTouchColliderOverlapBegins(
@@ -1313,12 +1613,25 @@ void ASGPawn::OnRightPinkyFingertipTouchColliderOverlapBegins(
(void) bFromSweep; (void) bFromSweep;
(void) SweepResult; (void) SweepResult;
if (USGTouchComponent::IsTouchable(OtherActor)) if (!IsValid(RightHandTouchState.Hand))
{ {
RightHandTouchState.ActorPinkyTouching = OtherActor; return;
Pimpl->TriggerTouchStateUpdatedEvent(RightHandTouchState);
Pimpl->TriggerBeginTouch(RightHandTouchState.Hand, OtherActor);
} }
const bool bHandVisible = RightHandTouchState.Hand->IsVisible();
if (!bHandVisible)
{
return;
}
if (!USGTouchComponent::IsTouchable(OtherActor))
{
return;
}
RightHandTouchState.ActorPinkyTouching = OtherActor;
Pimpl->TriggerTouchStateUpdatedEvent(RightHandTouchState);
Pimpl->TriggerBeginTouch(RightHandTouchState.Hand, OtherActor);
} }
void ASGPawn::OnRightPinkyFingertipTouchColliderOverlapEnds( void ASGPawn::OnRightPinkyFingertipTouchColliderOverlapEnds(
@@ -1331,34 +1644,51 @@ void ASGPawn::OnRightPinkyFingertipTouchColliderOverlapEnds(
(void) OtherComp; (void) OtherComp;
(void) OtherBodyIndex; (void) OtherBodyIndex;
if (RightHandTouchState.ActorPinkyTouching == OtherActor) if (!IsValid(RightHandTouchState.Hand))
{ {
RightHandTouchState.ActorPinkyTouching = nullptr; return;
Pimpl->TriggerTouchStateUpdatedEvent(RightHandTouchState);
Pimpl->TriggerEndTouch(RightHandTouchState.Hand, OtherActor);
} }
if (RightHandTouchState.ActorPinkyTouching != OtherActor)
{
return;
}
RightHandTouchState.ActorPinkyTouching = nullptr;
Pimpl->TriggerTouchStateUpdatedEvent(RightHandTouchState);
Pimpl->TriggerEndTouch(RightHandTouchState.Hand, OtherActor);
} }
bool ASGPawn::IsLeftHandGrabbing(AActor*& OutActor) const bool ASGPawn::IsLeftHandGrabbing(AActor*& OutActor) const
{ {
if (IsValid(LeftHandGrabState.GrabbedActor)) if (!IsValid(LeftHandGrabState.Hand))
{ {
OutActor = LeftHandGrabState.GrabbedActor; return false;
return true;
} }
return false; if (!IsValid(LeftHandGrabState.GrabbedActor))
{
return false;
}
OutActor = LeftHandGrabState.GrabbedActor;
return true;
} }
bool ASGPawn::IsRightHandGrabbing(AActor*& OutActor) const bool ASGPawn::IsRightHandGrabbing(AActor*& OutActor) const
{ {
if (IsValid(RightHandGrabState.GrabbedActor)) if (!IsValid(RightHandGrabState.Hand))
{ {
OutActor = RightHandGrabState.GrabbedActor; return false;
return true;
} }
return false; if (!IsValid(RightHandGrabState.GrabbedActor))
{
return false;
}
OutActor = RightHandGrabState.GrabbedActor;
return true;
} }
bool ASGPawn::IsGrabbing(const USGVirtualHandComponent* Hand, AActor*& OutActor) const bool ASGPawn::IsGrabbing(const USGVirtualHandComponent* Hand, AActor*& OutActor) const
@@ -1368,13 +1698,24 @@ bool ASGPawn::IsGrabbing(const USGVirtualHandComponent* Hand, AActor*& OutActor)
void ASGPawn::Grab(USGVirtualHandComponent* Hand, AActor* Actor) void ASGPawn::Grab(USGVirtualHandComponent* Hand, AActor* Actor)
{ {
if (!ensureAlwaysMsgf(IsValid(Hand), TEXT("%s"), TEXT("ERROR: invalid hand!")))
{
return;
}
const bool bHandVisible = Hand->IsVisible();
if (!bHandVisible)
{
return;
}
if (!ensureAlwaysMsgf(IsValid(Actor), TEXT("%s"), TEXT("ERROR: invalid actor!"))) if (!ensureAlwaysMsgf(IsValid(Actor), TEXT("%s"), TEXT("ERROR: invalid actor!")))
{ {
return; return;
} }
const USGGrabComponent* GrabComponent{USGGrabComponent::GetGrabComponent(Actor)}; const USGGrabComponent* GrabComponent{USGGrabComponent::GetGrabComponent(Actor)};
if (!GrabComponent) if (!IsValid(GrabComponent))
{ {
return; return;
} }
@@ -266,6 +266,16 @@ void ASGPlayerController::BeginPlay()
return; return;
} }
const bool bHandVisible = GrabState.Hand->IsVisible();
if (!bHandVisible)
{
if (SGPawn->IsGrabbing(GrabState.Hand))
{
SGPawn->Release(GrabState.Hand);
}
return;
}
if (SGPawn->IsGrabbing(GrabState.Hand)) if (SGPawn->IsGrabbing(GrabState.Hand))
{ {
if (!IsValid(GrabState.ActorThumbCanGrab) || if (!IsValid(GrabState.ActorThumbCanGrab) ||
@@ -287,6 +297,28 @@ void ASGPlayerController::BeginPlay()
SGPawn->OnTouchStateUpdated().AddWeakLambda( SGPawn->OnTouchStateUpdated().AddWeakLambda(
this, [= SG_CAPTURE_THIS](const FSGTouchState& TouchState) -> void this, [= SG_CAPTURE_THIS](const FSGTouchState& TouchState) -> void
{ {
if (!IsValid(SGPawn))
{
return;
}
if (!IsValid(TouchState.Hand))
{
return;
}
const bool bHandVisible = TouchState.Hand->IsVisible();
if (!bHandVisible)
{
return;
}
const bool bGloveConnected = TouchState.Hand->IsGloveConnected();
if (!bGloveConnected)
{
return;
}
Pimpl->UpdateHapticsFeedback(TouchState); Pimpl->UpdateHapticsFeedback(TouchState);
}); });
} }
@@ -313,6 +345,12 @@ void ASGPlayerController::FImpl::UpdateHapticsFeedback(const FSGTouchState& Touc
return; return;
} }
const bool bGloveConnected = Glove->IsConnected()
if (!bGloveConnected)
{
return;
}
// Queue the Force-Feedback command... // Queue the Force-Feedback command...
TArray<float> ForceFeedbackLevels{ TArray<float> ForceFeedbackLevels{
GetForceFeedbackLevels( GetForceFeedbackLevels(
@@ -342,11 +380,19 @@ void ASGPlayerController::FImpl::UpdateHapticsFeedback(const FSGTouchState& Touc
FTimerDelegate TouchVibrotactileStopHandler; FTimerDelegate TouchVibrotactileStopHandler;
TouchVibrotactileStopHandler.BindLambda([= SG_CAPTURE_THIS]()-> void TouchVibrotactileStopHandler.BindLambda([= SG_CAPTURE_THIS]()-> void
{ {
if (IsValid(Glove)) if (!IsValid(Glove))
{ {
Glove->QueueVibroLevels(VibrotactileOffCommand); return;
Glove->SendHaptics();
} }
const bool bGloveConnected = Glove->IsConnected();
if (!bGloveConnected)
{
return;
}
Glove->QueueVibroLevels(VibrotactileOffCommand);
Glove->SendHaptics();
}); });
Owner->GetWorldTimerManager().SetTimer( Owner->GetWorldTimerManager().SetTimer(