diff --git a/Handbook/src/appendix/changelog.md b/Handbook/src/appendix/changelog.md index 4c85be98..3d3aea87 100644 --- a/Handbook/src/appendix/changelog.md +++ b/Handbook/src/appendix/changelog.md @@ -73,6 +73,7 @@ This is a minor release focusing mainly on bringing OpenXR-compatible hand track ### Fixed - 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. +- Fixed a bug where USGGrabComponent's `bAffectPhysicsState` does not enables physics on its owning actor at `BeginPlay()`. - Fixed various wrong Kismet script names and their class exports. - Fixed the display name for various overloads of the Blueprint-exposed function `Queue Command Vibro Level` to expose sensible display names. - Some Android UPL tweaks, permission, and build fixes. @@ -95,6 +96,7 @@ This is a minor release focusing mainly on bringing OpenXR-compatible hand track - FSGDebugVirtualHand::Draw now accepts a FXRMotionControllerData parameter instead of all WristLocation, WristRotation, JointPositions, and JointRotations parameters. - FSGDebugVirtualHandSettings has been renamed to FSGVirtualHandDebuggingSettings. - The value for USGGrabComponent's AttachmentSocketName uproperty now defaults to the value of the plugin's GrabAttachPointSocketName instead of Name_NONE. +- The USGGrabComponent now enables `bGravityEnabled`, `bSimulatePhysics`, and calls `WakeRigidBody` on its owning actor at `BeginPlay()` if `bAffectPhysicsState` is enabled. - Updated the Directory Structure section of the main README file to reflect the latest toolchain support status. - The `/CHANGELOG.md` file has been migrated to `/Handbook/src/overview/changelog.md` - The `/LICENSE.md` file has been migrated to `/Handbook/src/license/senseglove-unreal-engine-plugin.md` diff --git a/Source/SenseGlove/Private/SenseGlove/Components/SGGrabComponent.cpp b/Source/SenseGlove/Private/SenseGlove/Components/SGGrabComponent.cpp index 65c1726d..b94bf03c 100644 --- a/Source/SenseGlove/Private/SenseGlove/Components/SGGrabComponent.cpp +++ b/Source/SenseGlove/Private/SenseGlove/Components/SGGrabComponent.cpp @@ -135,4 +135,29 @@ USGGrabComponent::FImpl::~FImpl() = default; void USGGrabComponent::FImplDeleter::operator()(const FImpl* P) const { delete P; +} + +void USGGrabComponent::BeginPlay() +{ + Super::BeginPlay(); + + if (bAffectPhysicsState) + { + const AActor* OwnerActor{GetOwner()}; + if (!ensureAlwaysMsgf(IsValid(OwnerActor), TEXT("Invalid OwnerActor!"))) + { + return; + } + + UPrimitiveComponent* ActorRootComponent{Cast(OwnerActor->GetRootComponent())}; + if (!ensureAlwaysMsgf(IsValid(ActorRootComponent), + TEXT("RootComponent is not a valid UPrimativeComponent!"))) + { + return; + } + + ActorRootComponent->SetEnableGravity(true); + ActorRootComponent->SetSimulatePhysics(true); + ActorRootComponent->WakeRigidBody(); + } } \ No newline at end of file diff --git a/Source/SenseGlove/Public/SenseGlove/Components/SGGrabComponent.h b/Source/SenseGlove/Public/SenseGlove/Components/SGGrabComponent.h index e6fad2dd..3cfe8ca2 100644 --- a/Source/SenseGlove/Public/SenseGlove/Components/SGGrabComponent.h +++ b/Source/SenseGlove/Public/SenseGlove/Components/SGGrabComponent.h @@ -196,4 +196,7 @@ public: { bAffectPhysicsState = bInAffectPhysicsState; } + +public: + virtual void BeginPlay() override; }; \ No newline at end of file