From 55e9a67592f2a86037d466e6f0614a9a0a4073d6 Mon Sep 17 00:00:00 2001 From: Mamadou Babaei Date: Fri, 19 May 2023 09:35:28 +0200 Subject: [PATCH] implement an optional feature in order to automatically stop all haptics on the end play event --- CHANGELOG.md | 1 + .../Components/SGVirtualHandComponent.cpp | 12 +++++++----- .../SenseGlove/Components/SGVirtualHandComponent.h | 13 +++++++++++++ .../SGVirtualHandComponentKismetLibrary.cpp | 12 ++++++++++++ .../SGKismet/SGVirtualHandComponentKismetLibrary.h | 7 +++++++ 5 files changed, 40 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ed05241a..5343397d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ This release breaks ABI/API compatibility with the previous versions. - Added Linux AArch64 platform support. - Added a new Grab component that can turn any actor into a grabbable object. - Added a new Touch component that enables haptic feedbacks such as Buzz and Force-Feedback commands. +- Added an optional feature in order to automatically stop all haptics on the EndPlay event, wherever the virtual hand component is used. By default, it's enabled. ### Fixed diff --git a/Source/SenseGlove/Private/SenseGlove/Components/SGVirtualHandComponent.cpp b/Source/SenseGlove/Private/SenseGlove/Components/SGVirtualHandComponent.cpp index c6e735ff..1a86f140 100644 --- a/Source/SenseGlove/Private/SenseGlove/Components/SGVirtualHandComponent.cpp +++ b/Source/SenseGlove/Private/SenseGlove/Components/SGVirtualHandComponent.cpp @@ -210,6 +210,8 @@ USGVirtualHandComponent::USGVirtualHandComponent(const FObjectInitializer& Objec bRight = true; + bAutoStopAllHapticsOnEndPlay = true; + GrabSocketName = FName{TEXT("GrabPoint")}; DefaultFingertipsGrabColliderSize = FVector{0.08f, 0.08f, 0.08f}; @@ -330,6 +332,11 @@ void USGVirtualHandComponent::EndPlay(const EEndPlayReason::Type EndPlayReason) { Super::EndPlay(EndPlayReason); + if (IsValid(Glove) && AutoStopsAllHapticsOnEndPlay()) + { + Glove->StopHaptics(); + } + (void) Pimpl->UninitializeBackend(); } @@ -624,11 +631,6 @@ bool USGVirtualHandComponent::FImpl::InitializeBackend() const bool USGVirtualHandComponent::FImpl::UninitializeBackend() const { - if (IsValid(Owner->Glove)) - { - Owner->Glove->StopHaptics(); - } - // NOTE // In Editor builds we should be avoiding dispose, since stopping the game in PIE mode, causes the virtual-hand // to disappear in the editor as the plugin won't be able to retrieve the glove status anymore. diff --git a/Source/SenseGlove/Public/SenseGlove/Components/SGVirtualHandComponent.h b/Source/SenseGlove/Public/SenseGlove/Components/SGVirtualHandComponent.h index 4330f4a1..f1e4f8b0 100644 --- a/Source/SenseGlove/Public/SenseGlove/Components/SGVirtualHandComponent.h +++ b/Source/SenseGlove/Public/SenseGlove/Components/SGVirtualHandComponent.h @@ -84,6 +84,9 @@ private: UPROPERTY(EditAnywhere, Category="SenseGlove", meta=(AllowPrivateAccess="false")) uint8 bRight : 1; + UPROPERTY(EditAnywhere, Category="SenseGlove | Haptics", meta=(AllowPrivateAccess="false")) + uint8 bAutoStopAllHapticsOnEndPlay : 1; + UPROPERTY(EditAnywhere, Category="SenseGlove | Grab", meta=(AllowPrivateAccess="false")) FName GrabSocketName; @@ -147,6 +150,16 @@ public: void SetRight(const bool bInRight); + FORCEINLINE bool AutoStopsAllHapticsOnEndPlay() const + { + return !!bAutoStopAllHapticsOnEndPlay; + } + + FORCEINLINE void SetAutoStopAllHapticsOnEndPlay(const bool bInAutoStopAllHapticsOnEndPlay) + { + bAutoStopAllHapticsOnEndPlay = bInAutoStopAllHapticsOnEndPlay; + } + FORCEINLINE const FName& GetGrabSocketName() const { return GrabSocketName; diff --git a/Source/SenseGloveKismet/Private/SGKismet/SGVirtualHandComponentKismetLibrary.cpp b/Source/SenseGloveKismet/Private/SGKismet/SGVirtualHandComponentKismetLibrary.cpp index eaef3f75..17b08a21 100644 --- a/Source/SenseGloveKismet/Private/SGKismet/SGVirtualHandComponentKismetLibrary.cpp +++ b/Source/SenseGloveKismet/Private/SGKismet/SGVirtualHandComponentKismetLibrary.cpp @@ -78,6 +78,18 @@ void UVirtualHandComponentKismetLibrary::SetRight(USGVirtualHandComponent* Virtu VirtualHandComponent->SetRight(bInRight); } +bool UVirtualHandComponentKismetLibrary::AutoStopsAllHapticsOnEndPlay( + const USGVirtualHandComponent* VirtualHandComponent) +{ + return VirtualHandComponent->AutoStopsAllHapticsOnEndPlay(); +} + +void UVirtualHandComponentKismetLibrary::SetAutoStopAllHapticsOnEndPlay(USGVirtualHandComponent* VirtualHandComponent, + const bool bInAutoStopAllHapticsOnEndPlay) +{ + VirtualHandComponent->SetAutoStopAllHapticsOnEndPlay(bInAutoStopAllHapticsOnEndPlay); +} + const FName& UVirtualHandComponentKismetLibrary::GetGrabSocketName(const USGVirtualHandComponent* VirtualHandComponent) { return VirtualHandComponent->GetGrabSocketName(); diff --git a/Source/SenseGloveKismet/Public/SGKismet/SGVirtualHandComponentKismetLibrary.h b/Source/SenseGloveKismet/Public/SGKismet/SGVirtualHandComponentKismetLibrary.h index 2463eede..33d79309 100644 --- a/Source/SenseGloveKismet/Public/SGKismet/SGVirtualHandComponentKismetLibrary.h +++ b/Source/SenseGloveKismet/Public/SGKismet/SGVirtualHandComponentKismetLibrary.h @@ -81,6 +81,13 @@ public: UFUNCTION(BlueprintCallable, Category="SenseGlove | Components | Virtual Hand Component") static void SetRight(UPARAM(ref) USGVirtualHandComponent* VirtualHandComponent, bool bInRight); + UFUNCTION(BlueprintPure, Category="SenseGlove | Components | Virtual Hand Component") + static bool AutoStopsAllHapticsOnEndPlay(const USGVirtualHandComponent* VirtualHandComponent); + + UFUNCTION(BlueprintCallable, Category="SenseGlove | Components | Virtual Hand Component") + static void SetAutoStopAllHapticsOnEndPlay(UPARAM(ref) USGVirtualHandComponent* VirtualHandComponent, + const bool bInAutoStopAllHapticsOnEndPlay); + UFUNCTION(BlueprintPure, Category="SenseGlove | Components | Virtual Hand Component") static const FName& GetGrabSocketName(const USGVirtualHandComponent* VirtualHandComponent);