4#include "IHeadMountedDisplay.h"
5#include "HeadMountedDisplayTypes.h"
7#include "Misc/ScopeLock.h"
8#include "Net/UnrealNetwork.h"
9#include "PrimitiveSceneInfo.h"
10#include "Engine/World.h"
11#include "GameFramework/WorldSettings.h"
12#include "IXRSystemAssets.h"
13#include "Components/StaticMeshComponent.h"
14#include "MotionDelayBuffer.h"
15#include "UObject/VRObjectVersion.h"
16#include "UObject/UObjectGlobals.h"
17#include "IXRTrackingSystem.h"
18#include "IXRSystemAssets.h"
19#include "DrawDebugHelpers.h"
20#include "TimerManager.h"
26#include "PhysicsPublic.h"
27#include "PhysicsEngine/BodySetup.h"
28#include "PhysicsEngine/ConstraintDrives.h"
29#include "PhysicsReplication.h"
31#if PHYSICS_INTERFACE_PHYSX
32#include "PhysXPublic.h"
34#include "Chaos/ParticleHandle.h"
35#include "Chaos/KinematicGeometryParticles.h"
36#include "Chaos/PBDJointConstraintTypes.h"
37#include "Chaos/PBDJointConstraintData.h"
38#include "Chaos/Sphere.h"
39#include "PhysicsProxy/SingleParticlePhysicsProxy.h"
40#include "Chaos/ChaosConstraintSettings.h"
45#include "Features/IModularFeatures.h"
50DECLARE_CYCLE_STAT(TEXT(
"GetGripWorldTransform ~ GettingTransform"), STAT_GetGripTransform, STATGROUP_TickGrip);
72 TEXT(
"vr.DrawDebugCenterOfMassForGrips"),
74 TEXT(
"When on, will draw debug speheres for physics grips COM.\n")
75 TEXT(
"0: Disable, 1: Enable"),
81 : Super(ObjectInitializer)
83 PrimaryComponentTick.bCanEverTick =
true;
84 PrimaryComponentTick.bStartWithTickEnabled =
true;
85 PrimaryComponentTick.TickGroup = TG_PrePhysics;
86 PrimaryComponentTick.bTickEvenWhenPaused =
true;
89 MotionSource = FXRMotionControllerBase::LeftHandSourceId;
91 bDisableLowLatencyUpdate =
false;
99 SetIsReplicatedByDefault(
true);
164 UWorld* World = GetWorld();
165 if (World !=
nullptr)
181 if (this->IsPendingKill())
185 FTransform baseTrans = this->GetAttachParent()->GetComponentTransform().Inverse();
196 if (!bSampleRelativeTransform)
202 if (bSampleRelativeTransform)
210 if (UPrimitiveComponent* root = Cast<UPrimitiveComponent>(
Actor->GetRootComponent()))
235 if (
GrippedObjects[i].GrippedObject->GetClass()->ImplementsInterface(UVRGripInterface::StaticClass()))
239 if (!bSampleRelativeTransform)
245 if (bSampleRelativeTransform)
253 if (UPrimitiveComponent* root = Cast<UPrimitiveComponent>(
Actor->GetRootComponent()))
255 GrippedObjects[i].LastWorldTransform = root->GetComponentTransform() * baseTrans;
262 if (UPrimitiveComponent* root = Cast<UPrimitiveComponent>(
GrippedObjects[i].GrippedObject))
264 GrippedObjects[i].LastWorldTransform = root->GetComponentTransform() * baseTrans;
276 QUICK_SCOPE_CYCLE_COUNTER(FGripComponentEndPhysicsTickFunction_ExecuteTick);
277 CSV_SCOPED_TIMING_STAT_EXCLUSIVE(Physics);
281 FActorComponentTickFunction::ExecuteTickHelper(
Target,
false, DeltaTime, TickType, [
this](
float DilatedTime)
290 return TEXT(
"GripComponentEndPhysicsTickFunction");
295 return FName(TEXT(
"GripComponentEndPhysicsTick"));
317 if (VRSettings ==
nullptr)
320 EControllerHand HandType;
323 FTransform NewControllerProfileTransform = FTransform::Identity;
329 else if (HandType == EControllerHand::Right)
357 Super::InitializeComponent();
367 Super::EndPlay(EndPlayReason);
375 if (VRSettings !=
nullptr)
394 bool bSimulateOnDrop =
true;
395 if (
GrippedObjects[i].GrippedObject->GetClass()->ImplementsInterface(UVRGripInterface::StaticClass()))
397 bSimulateOnDrop = IVRGripInterface::Execute_SimulateOnDrop(
GrippedObjects[i].GrippedObject);
418 bool bSimulateOnDrop =
true;
419 if (
LocallyGrippedObjects[i].GrippedObject->GetClass()->ImplementsInterface(UVRGripInterface::StaticClass()))
437 if (UWorld * myWorld = GetWorld())
439 myWorld->GetTimerManager().ClearAllTimersForObject(
this);
447 Super::OnUnregister();
452 Super::BeginDestroy();
459 FScopeLock ScopeLock(&CritSect);
476 if (
bHasAuthority && !bDisableLowLatencyUpdate && IsActive())
486 if (UWorld* world = GetWorld())
505 Super::Super::CreateRenderState_Concurrent(Context);
511 if (
bHasAuthority && !bDisableLowLatencyUpdate && IsActive())
513 struct FPrimitiveUpdateRenderThreadRelativeTransformParams
518 FPrimitiveUpdateRenderThreadRelativeTransformParams UpdateParams;
519 UpdateParams.LateUpdateParams.GripRenderThreadRelativeTransform = GetRelativeTransform();
520 UpdateParams.LateUpdateParams.GripRenderThreadComponentScale = GetComponentScale();
525 if (UpdateParams.LateUpdateParams.bRenderSmoothHandTracking)
527 if (UWorld* world = GetWorld())
529 UpdateParams.LateUpdateParams.RenderLastDeltaTime = world->GetDeltaSeconds();
534 if (UpdateParams.LateUpdateParams.bRenderSmoothWithEuroLowPassFunction)
540 UpdateParams.LateUpdateParams.RenderSmoothingSpeed =
SmoothingSpeed;
545 ENQUEUE_RENDER_COMMAND(UpdateRTRelativeTransformCommand)(
546 [UpdateParams,
this](FRHICommandListImmediate& RHICmdList)
553 Super::Super::SendRenderTransform_Concurrent();
569 return index != INDEX_NONE;
593void UGripMotionControllerComponent::GetLifetimeReplicatedProps(TArray< class FLifetimeProperty > & OutLifetimeProps)
const
595 Super::GetLifetimeReplicatedProps(OutLifetimeProps);
598 DISABLE_REPLICATED_PRIVATE_PROPERTY(
USceneComponent, RelativeLocation);
599 DISABLE_REPLICATED_PRIVATE_PROPERTY(
USceneComponent, RelativeRotation);
626void UGripMotionControllerComponent::Server_SendControllerTransform_Implementation(
FBPVRComponentPosRep NewTransform)
636bool UGripMotionControllerComponent::Server_SendControllerTransform_Validate(
FBPVRComponentPosRep NewTransform)
658 if (!primComp && pActor)
659 primComp = Cast<UPrimitiveComponent>(pActor->GetRootComponent());
663 AngularVelocity = FVector::ZeroVector;
664 LinearVelocity = FVector::ZeroVector;
668 AngularVelocity = primComp->GetPhysicsAngularVelocityInDegrees();
669 LinearVelocity = primComp->GetPhysicsLinearVelocity();
676 if (PhysHandle->HandleData2.IsValid())
678 FPhysicsInterface::GetForce(PhysHandle->HandleData2, LinearForce, AngularForce);
691 if (!primComp && pActor)
692 primComp = Cast<UPrimitiveComponent>(pActor->GetRootComponent());
694 if (!primComp || !primComp->IsSimulatingPhysics())
700 Mass = primComp->GetMass();
705 if (!ActorToLookForGrip)
727 if (!ComponentToLookForGrip)
749 if (!ObjectToLookForGrip)
811 if (fIndex != INDEX_NONE)
819 if (fIndex != INDEX_NONE)
825 if (GripInformation !=
nullptr)
841 if (fIndex != INDEX_NONE)
849 if (fIndex != INDEX_NONE)
855 if (GripInformation !=
nullptr)
857 if (bNoConstraintWhenPaused)
887 if (fIndex != INDEX_NONE)
895 if (fIndex != INDEX_NONE)
901 if (GripInformation !=
nullptr && GripInformation->
GrippedObject !=
nullptr)
905 FTransform ProxyTrans = PausedTransform;
918 GripInformation->
GetGrippedActor()->SetActorTransform(PausedTransform);
936 if (fIndex != INDEX_NONE)
947 if (fIndex != INDEX_NONE)
971 if (fIndex != INDEX_NONE)
973 GrippedObjects[fIndex].GripLateUpdateSetting = NewGripLateUpdateSetting;
981 if (fIndex != INDEX_NONE)
1002 const FTransform & NewRelativeTransform
1007 if (fIndex != INDEX_NONE)
1023 if (fIndex != INDEX_NONE)
1049 const FTransform & NewAdditionTransform,
bool bMakeGripRelative
1054 if (fIndex != INDEX_NONE)
1065 if (fIndex != INDEX_NONE)
1079 float NewStiffness,
float NewDamping,
bool bAlsoSetAngularValues,
float OptionalAngularStiffness,
float OptionalAngularDamping
1085 if (fIndex != INDEX_NONE)
1090 if (bAlsoSetAngularValues)
1092 GrippedObjects[fIndex].AdvancedGripSettings.PhysicsSettings.AngularStiffness = OptionalAngularStiffness;
1093 GrippedObjects[fIndex].AdvancedGripSettings.PhysicsSettings.AngularDamping = OptionalAngularDamping;
1104 if (fIndex != INDEX_NONE)
1109 if (bAlsoSetAngularValues)
1111 LocallyGrippedObjects[fIndex].AdvancedGripSettings.PhysicsSettings.AngularStiffness = OptionalAngularStiffness;
1112 LocallyGrippedObjects[fIndex].AdvancedGripSettings.PhysicsSettings.AngularDamping = OptionalAngularDamping;
1130 const FTransform & AdditionTransform,
1139 const FTransform &WorldOffset,
1140 bool bWorldOffsetIsRelative,
1141 FName OptionalSnapToSocketName,
1142 FName OptionalBoneToGripName,
1146 float GripStiffness,
1150 if (UPrimitiveComponent * PrimComp = Cast<UPrimitiveComponent>(ObjectToGrip))
1152 return GripComponent(PrimComp, WorldOffset, bWorldOffsetIsRelative, OptionalSnapToSocketName, OptionalBoneToGripName, GripCollisionType,GripLateUpdateSetting,GripMovementReplicationSetting,GripStiffness,GripDamping, bIsSlotGrip);
1154 else if (
AActor *
Actor = Cast<AActor>(ObjectToGrip))
1156 return GripActor(
Actor, WorldOffset, bWorldOffsetIsRelative, OptionalSnapToSocketName, OptionalBoneToGripName, GripCollisionType, GripLateUpdateSetting, GripMovementReplicationSetting, GripStiffness, GripDamping, bIsSlotGrip);
1166 FVector OptionalAngularVelocity,
1167 FVector OptionalLinearVelocity)
1170 if (ObjectToDrop !=
nullptr)
1176 if (GripInfo !=
nullptr)
1187 if (GripInfo !=
nullptr)
1198 if (UPrimitiveComponent * PrimComp = Cast<UPrimitiveComponent>(ObjectToGrip))
1200 AActor * Owner = PrimComp->GetOwner();
1205 if (PrimComp->GetClass()->ImplementsInterface(UVRGripInterface::StaticClass()))
1207 EGripCollisionType CollisionType = IVRGripInterface::Execute_GetPrimaryGripType(PrimComp, bIsSlotGrip);
1211 IVRGripInterface::Execute_GetGripStiffnessAndDamping(PrimComp, Stiffness, Damping);
1213 return GripComponent(PrimComp, WorldOffset, bWorldOffsetIsRelative, OptionalSnapToSocketName,
1214 OptionalBoneToGripName,
1216 IVRGripInterface::Execute_GripLateUpdateSetting(PrimComp),
1217 IVRGripInterface::Execute_GripMovementReplicationType(PrimComp),
1223 else if (Owner->GetClass()->ImplementsInterface(UVRGripInterface::StaticClass()))
1225 EGripCollisionType CollisionType = IVRGripInterface::Execute_GetPrimaryGripType(Owner, bIsSlotGrip);
1229 IVRGripInterface::Execute_GetGripStiffnessAndDamping(Owner, Stiffness, Damping);
1231 return GripActor(Owner, WorldOffset, bWorldOffsetIsRelative, OptionalSnapToSocketName,
1232 OptionalBoneToGripName,
1234 IVRGripInterface::Execute_GripLateUpdateSetting(Owner),
1235 IVRGripInterface::Execute_GripMovementReplicationType(Owner),
1253 UE_LOG(LogVRMotionController,
Warning, TEXT(
"VRGripMotionController GripObjectByInterface was called on an object that doesn't implement the interface and doesn't have a parent that implements the interface!"));
1257 else if (
AActor *
Actor = Cast<AActor>(ObjectToGrip))
1259 UPrimitiveComponent * root = Cast<UPrimitiveComponent>(
Actor->GetRootComponent());
1264 if (root->GetClass()->ImplementsInterface(UVRGripInterface::StaticClass()))
1266 EGripCollisionType CollisionType = IVRGripInterface::Execute_GetPrimaryGripType(root, bIsSlotGrip);
1270 IVRGripInterface::Execute_GetGripStiffnessAndDamping(root, Stiffness, Damping);
1272 return GripComponent(root, WorldOffset, bWorldOffsetIsRelative, OptionalSnapToSocketName,
1273 OptionalBoneToGripName,
1275 IVRGripInterface::Execute_GripLateUpdateSetting(root),
1276 IVRGripInterface::Execute_GripMovementReplicationType(root),
1291 else if (
Actor->GetClass()->ImplementsInterface(UVRGripInterface::StaticClass()))
1297 IVRGripInterface::Execute_GetGripStiffnessAndDamping(
Actor, Stiffness, Damping);
1299 return GripActor(
Actor, WorldOffset, bWorldOffsetIsRelative, OptionalSnapToSocketName,
1300 OptionalBoneToGripName,
1302 IVRGripInterface::Execute_GripLateUpdateSetting(
Actor),
1303 IVRGripInterface::Execute_GripMovementReplicationType(
Actor),
1312 UE_LOG(LogVRMotionController,
Warning, TEXT(
"VRGripMotionController GripObjectByInterface was called on an object that doesn't implement the interface and doesn't have a parent that implements the interface!"));
1323 if (ObjectToDrop !=
nullptr)
1336 if (GripInfo ==
nullptr)
1341 if (UPrimitiveComponent * PrimComp = Cast<UPrimitiveComponent>(GripInfo->
GrippedObject))
1343 AActor * Owner = PrimComp->GetOwner();
1348 if (PrimComp->GetClass()->ImplementsInterface(UVRGripInterface::StaticClass()))
1350 return DropGrip_Implementation(*GripInfo, IVRGripInterface::Execute_SimulateOnDrop(PrimComp), OptionalAngularVelocity, OptionalLinearVelocity);
1353 else if (Owner->GetClass()->ImplementsInterface(UVRGripInterface::StaticClass()))
1355 return DropGrip_Implementation(*GripInfo, IVRGripInterface::Execute_SimulateOnDrop(Owner), OptionalAngularVelocity, OptionalLinearVelocity);
1367 UPrimitiveComponent * root = Cast<UPrimitiveComponent>(
Actor->GetRootComponent());
1372 if (root->GetClass()->ImplementsInterface(UVRGripInterface::StaticClass()))
1374 return DropGrip_Implementation(*GripInfo, IVRGripInterface::Execute_SimulateOnDrop(root), OptionalAngularVelocity, OptionalLinearVelocity);
1376 else if (
Actor->GetClass()->ImplementsInterface(UVRGripInterface::StaticClass()))
1378 return DropGrip_Implementation(*GripInfo, IVRGripInterface::Execute_SimulateOnDrop(
Actor), OptionalAngularVelocity, OptionalLinearVelocity);
1392 const FTransform &WorldOffset,
1393 bool bWorldOffsetIsRelative,
1394 FName OptionalSnapToSocketName,
1395 FName OptionalBoneToGripName,
1399 float GripStiffness,
1407 UE_LOG(LogVRMotionController,
Warning, TEXT(
"VRGripMotionController grab function was called on the client side as a replicated grip"));
1411 if (!ActorToGrip || ActorToGrip->IsPendingKill())
1413 UE_LOG(LogVRMotionController,
Warning, TEXT(
"VRGripMotionController grab function was passed an invalid or pending kill actor"));
1419 UE_LOG(LogVRMotionController,
Warning, TEXT(
"VRGripMotionController grab function was passed an already gripped actor"));
1423 UPrimitiveComponent *root = Cast<UPrimitiveComponent>(ActorToGrip->GetRootComponent());
1427 UE_LOG(LogVRMotionController,
Warning, TEXT(
"VRGripMotionController tried to grip an actor without a UPrimitiveComponent Root"));
1434 UE_LOG(LogVRMotionController,
Warning, TEXT(
"VRGripMotionController tried to grip an actor set to static mobility not with a Custom Grip"));
1439 UObject * ObjectToCheck = NULL;
1442 TArray<FBPGripPair> HoldingControllers;
1443 bool bIsHeld =
false;
1444 bool bHadOriginalSettings =
false;
1445 bool bOriginalGravity =
false;
1446 bool bOriginalReplication =
false;
1448 if (root->GetClass()->ImplementsInterface(UVRGripInterface::StaticClass()))
1450 if(IVRGripInterface::Execute_DenyGripping(root,
this))
1453 IVRGripInterface::Execute_IsHeld(root, HoldingControllers, bIsHeld);
1454 bool bAllowMultipleGrips = IVRGripInterface::Execute_AllowsMultipleGrips(root);
1455 if (bIsHeld && !bAllowMultipleGrips)
1462 if (HoldingControllers[0].HoldingController !=
nullptr)
1464 FBPActorGripInformation* gripInfo = HoldingControllers[0].HoldingController->GetGripPtrByID(HoldingControllers[0].GripID);
1466 if (gripInfo !=
nullptr)
1468 bHadOriginalSettings =
true;
1475 AdvancedGripSettings = IVRGripInterface::Execute_AdvancedGripSettings(root);
1476 ObjectToCheck = root;
1478 else if (ActorToGrip->GetClass()->ImplementsInterface(UVRGripInterface::StaticClass()))
1480 if(IVRGripInterface::Execute_DenyGripping(ActorToGrip,
this))
1483 IVRGripInterface::Execute_IsHeld(ActorToGrip, HoldingControllers, bIsHeld);
1484 bool bAllowMultipleGrips = IVRGripInterface::Execute_AllowsMultipleGrips(ActorToGrip);
1485 if (bIsHeld && !bAllowMultipleGrips)
1492 if (HoldingControllers[0].HoldingController !=
nullptr)
1494 FBPActorGripInformation* gripInfo = HoldingControllers[0].HoldingController->GetGripPtrByID(HoldingControllers[0].GripID);
1496 if (gripInfo !=
nullptr)
1498 bHadOriginalSettings =
true;
1505 AdvancedGripSettings = IVRGripInterface::Execute_AdvancedGripSettings(ActorToGrip);
1506 ObjectToCheck = ActorToGrip;
1510 ActorToGrip->AddTickPrerequisiteComponent(
this);
1516 if (bHadOriginalSettings)
1527 newActorGrip.
Damping = GripDamping;
1532 newActorGrip.
SlotName = OptionalSnapToSocketName;
1551 if (ActorToGrip->IsReplicatingMovement())
1565 if (OptionalSnapToSocketName.IsValid() && WorldOffset.Equals(FTransform::Identity) && root->DoesSocketExist(OptionalSnapToSocketName))
1568 FTransform sockTrans = root->GetSocketTransform(OptionalSnapToSocketName, ERelativeTransformSpace::RTS_Component);
1569 sockTrans.SetScale3D(FVector(1.f) / root->GetComponentScale());
1573 ObjectToCheck = NULL;
1575 newActorGrip.
SlotName = OptionalSnapToSocketName;
1577 else if (bWorldOffsetIsRelative)
1596 if (Index != INDEX_NONE)
1609 if (Index != INDEX_NONE)
1629 if (Index != INDEX_NONE)
1646 UE_LOG(LogVRMotionController,
Warning, TEXT(
"VRGripMotionController drop function was passed an invalid actor"));
1657 UE_LOG(LogVRMotionController,
Warning, TEXT(
"VRGripMotionController drop function was called on the client side with a replicated grip"));
1669 UPrimitiveComponent* ComponentToGrip,
1670 const FTransform &WorldOffset,
1671 bool bWorldOffsetIsRelative,
1672 FName OptionalSnapToSocketName,
1673 FName OptionalBoneToGripName,
1677 float GripStiffness,
1687 UE_LOG(LogVRMotionController,
Warning, TEXT(
"VRGripMotionController grab function was called on the client side with a replicating grip"));
1691 if (!ComponentToGrip || ComponentToGrip->IsPendingKill())
1693 UE_LOG(LogVRMotionController,
Warning, TEXT(
"VRGripMotionController grab function was passed an invalid or pending kill component"));
1699 UE_LOG(LogVRMotionController,
Warning, TEXT(
"VRGripMotionController grab function was passed an already gripped component"));
1706 UE_LOG(LogVRMotionController,
Warning, TEXT(
"VRGripMotionController tried to grip a component set to static mobility not in CustomGrip mode"));
1711 UObject * ObjectToCheck = NULL;
1714 TArray<FBPGripPair> HoldingControllers;
1715 bool bIsHeld =
false;
1716 bool bHadOriginalSettings =
false;
1717 bool bOriginalGravity =
false;
1718 bool bOriginalReplication =
false;
1720 if (ComponentToGrip->GetClass()->ImplementsInterface(UVRGripInterface::StaticClass()))
1722 if(IVRGripInterface::Execute_DenyGripping(ComponentToGrip,
this))
1725 IVRGripInterface::Execute_IsHeld(ComponentToGrip, HoldingControllers, bIsHeld);
1726 bool bAllowMultipleGrips = IVRGripInterface::Execute_AllowsMultipleGrips(ComponentToGrip);
1727 if (bIsHeld && !bAllowMultipleGrips)
1734 if (HoldingControllers[0].HoldingController !=
nullptr)
1738 HoldingControllers[0].HoldingController->GetGripByID(gripInfo, HoldingControllers[0].GripID, result);
1742 bHadOriginalSettings =
true;
1750 AdvancedGripSettings = IVRGripInterface::Execute_AdvancedGripSettings(ComponentToGrip);
1751 ObjectToCheck = ComponentToGrip;
1757 ComponentToGrip->AddTickPrerequisiteComponent(
this);
1764 if (bHadOriginalSettings)
1771 if (ComponentToGrip->GetOwner())
1776 newComponentGrip.
Stiffness = GripStiffness;
1777 newComponentGrip.
Damping = GripDamping;
1783 newComponentGrip.
SlotName = OptionalSnapToSocketName;
1803 if (ComponentToGrip->GetOwner())
1805 if (ComponentToGrip->GetOwner()->IsReplicatingMovement())
1820 if (OptionalSnapToSocketName.IsValid() && WorldOffset.Equals(FTransform::Identity) && ComponentToGrip->DoesSocketExist(OptionalSnapToSocketName))
1823 FTransform sockTrans = ComponentToGrip->GetSocketTransform(OptionalSnapToSocketName, ERelativeTransformSpace::RTS_Component);
1824 sockTrans.SetScale3D(FVector(1.f) / ComponentToGrip->GetComponentScale());
1828 ObjectToCheck = NULL;
1830 else if (bWorldOffsetIsRelative)
1849 if (Index != INDEX_NONE)
1863 if (Index != INDEX_NONE)
1883 if (Index != INDEX_NONE)
1903 if (GripInfo !=
nullptr)
1911 UE_LOG(LogVRMotionController,
Warning, TEXT(
"VRGripMotionController drop function was called on the client side for a replicated grip"));
1918 if (GripInfo !=
nullptr)
1924 UE_LOG(LogVRMotionController,
Warning, TEXT(
"VRGripMotionController drop function was passed an invalid component"));
1940 bool bWasLocalGrip =
false;
1945 UE_LOG(LogVRMotionController,
Warning, TEXT(
"VRGripMotionController drop function was called on the client side for a replicated grip"));
1951 UE_LOG(LogVRMotionController,
Warning, TEXT(
"VRGripMotionController drop function was passed an invalid drop"));
1955 bWasLocalGrip =
false;
1958 bWasLocalGrip =
true;
1960 if (bWasLocalGrip && bIsServer)
1969 UPrimitiveComponent * PrimComp =
nullptr;
1971 AActor * pActor =
nullptr;
1983 if (!PrimComp && pActor)
1984 PrimComp = Cast<UPrimitiveComponent>(pActor->GetRootComponent());
1988 UE_LOG(LogVRMotionController,
Warning, TEXT(
"VRGripMotionController drop function was passed an invalid drop or CleanUpBadGrip wascalled"));
1993 if (bSimulate && (!OptionalLinearVelocity.IsNearlyZero() || !OptionalAngularVelocity.IsNearlyZero()))
2000 if (PrimComp->IsSimulatingPhysics() != bSimulate)
2002 PrimComp->SetSimulatePhysics(bSimulate);
2008 if (PrimComp->IsSimulatingPhysics())
2010 PrimComp->SetPhysicsLinearVelocity(OptionalLinearVelocity);
2011 PrimComp->SetPhysicsAngularVelocityInDegrees(OptionalAngularVelocity);
2018 if (GetNetMode() == ENetMode::NM_Client)
2030 TransformAtDrop = GrippedActor->GetActorTransform();
2037 TransformAtDrop = GrippedPrim->GetComponentTransform();
2064 if (!SocketingParent)
2066 UE_LOG(LogVRMotionController,
Warning, TEXT(
"VRGripMotionController drop and socket function was passed an invalid socketing parent"));
2072 UE_LOG(LogVRMotionController,
Warning, TEXT(
"VRGripMotionController drop and socket function was passed an invalid object"));
2076 bool bWasLocalGrip =
false;
2086 bWasLocalGrip =
true;
2092 UE_LOG(LogVRMotionController,
Warning, TEXT(
"VRGripMotionController drop and socket function was called on the client side for a replicated grip"));
2103 bWasLocalGrip =
false;
2107 UE_LOG(LogVRMotionController,
Warning, TEXT(
"VRGripMotionController drop and socket function was passed an invalid drop"));
2125 if (!SocketingParent || SocketingParent->IsPendingKill())
2127 UE_LOG(LogVRMotionController,
Warning, TEXT(
"VRGripMotionController drop and socket function was passed an invalid socketing parent"));
2131 bool bWasLocalGrip =
false;
2137 bWasLocalGrip =
true;
2143 UE_LOG(LogVRMotionController,
Warning, TEXT(
"VRGripMotionController drop and socket function was called on the client side for a replicated grip"));
2151 bWasLocalGrip =
false;
2155 UE_LOG(LogVRMotionController,
Warning, TEXT(
"VRGripMotionController drop and socket function was passed an invalid drop"));
2160 UPrimitiveComponent * PrimComp =
nullptr;
2162 AActor * pActor =
nullptr;
2167 if (!PrimComp && pActor)
2168 PrimComp = Cast<UPrimitiveComponent>(pActor->GetRootComponent());
2172 UE_LOG(LogVRMotionController,
Warning, TEXT(
"VRGripMotionController drop and socket function was passed an invalid drop or CleanUpBadGrip wascalled"));
2178 if (!GrippedObject || GrippedObject->IsPendingKill())
2180 UE_LOG(LogVRMotionController,
Warning, TEXT(
"VRGripMotionController drop and socket function was passed an invalid or pending kill gripped object"));
2184 int PhysicsHandleIndex = INDEX_NONE;
2189 if (GetNetMode() == ENetMode::NM_Client)
2196 OnSocketingObject.Broadcast(*GripInfo, SocketingParent, OptionalSocketName, RelativeTransformToParent, bWeldBodies);
2197 Socket_Implementation(GrippedObject, (PhysicsHandleIndex != INDEX_NONE), SocketingParent, OptionalSocketName, RelativeTransformToParent, bWeldBodies);
2205 NotifyDropAndSocket(*GripInfo, SocketingParent, OptionalSocketName, RelativeTransformToParent, bWeldBodies);
2211 NotifyDropAndSocket(*GripInfo, SocketingParent, OptionalSocketName, RelativeTransformToParent, bWeldBodies);
2233 if (!ObjectToSocket || ObjectToSocket->IsPendingKill())
2239 if (UPrimitiveComponent * root = Cast<UPrimitiveComponent>(ObjectToSocket))
2244 if(root->GetAttachParent())
2245 root->SetRelativeTransform(RelativeTransformToParent);
2247 else if (
AActor * pActor = Cast<AActor>(ObjectToSocket))
2252 if(pActor->GetAttachParentActor())
2253 pActor->SetActorRelativeTransform(RelativeTransformToParent);
2258bool UGripMotionControllerComponent::Server_NotifyDropAndSocketGrip_Validate(uint8 GripID,
USceneComponent * SocketingParent, FName OptionalSocketName,
const FTransform_NetQuantize & RelativeTransformToParent,
bool bWeldBodies)
2263void UGripMotionControllerComponent::Server_NotifyDropAndSocketGrip_Implementation(uint8 GripID,
USceneComponent * SocketingParent, FName OptionalSocketName,
const FTransform_NetQuantize & RelativeTransformToParent,
bool bWeldBodies)
2273 int PhysicsHandleIndex = INDEX_NONE;
2278 OnSocketingObject.Broadcast(FoundGrip, SocketingParent, OptionalSocketName, RelativeTransformToParent, bWeldBodies);
2292 if (!SocketingParent || !SocketingParent->IsValidLowLevelFast() || !ObjectToSocket || !ObjectToSocket->IsValidLowLevelFast())
2294 if (!SocketingParent || !SocketingParent->IsValidLowLevelFast())
2296 UE_LOG(LogVRMotionController,
Error, TEXT(
"VRGripMotionController Socket_Implementation was called with an invalid Socketing Parent object"));
2300 UE_LOG(LogVRMotionController,
Error, TEXT(
"VRGripMotionController Socket_Implementation was called with an invalid Object to Socket"));
2305 FAttachmentTransformRules TransformRule = FAttachmentTransformRules::KeepWorldTransform;
2306 TransformRule.bWeldSimulatedBodies = bWeldBodies;
2310 if (UPrimitiveComponent * root = Cast<UPrimitiveComponent>(ObjectToSocket))
2313 if (FBodyInstance* rBodyInstance = root->GetBodyInstance())
2315 if (rBodyInstance->OnRecalculatedMassProperties().IsBoundToObject(
this))
2317 rBodyInstance->OnRecalculatedMassProperties().RemoveAll(
this);
2322 if (bWasSimulating || root->IsSimulatingPhysics())
2324 root->SetSimulatePhysics(
false);
2325 bWasSimulating =
true;
2328 root->AttachToComponent(SocketingParent, TransformRule, OptionalSocketName);
2329 root->SetRelativeTransform(RelativeTransformToParent);
2331 else if (
AActor * pActor = Cast<AActor>(ObjectToSocket))
2334 if (UPrimitiveComponent * rootComp = Cast<UPrimitiveComponent>(pActor->GetRootComponent()))
2337 if (FBodyInstance* rBodyInstance = rootComp->GetBodyInstance())
2339 if (rBodyInstance->OnRecalculatedMassProperties().IsBoundToObject(
this))
2341 rBodyInstance->OnRecalculatedMassProperties().RemoveAll(
this);
2345 if (bWasSimulating || rootComp->IsSimulatingPhysics())
2348 rootComp->SetSimulatePhysics(
false);
2349 bWasSimulating =
true;
2353 pActor->AttachToComponent(SocketingParent, TransformRule, OptionalSocketName);
2354 pActor->SetActorRelativeTransform(RelativeTransformToParent);
2375 GetNetMode() == ENetMode::NM_Client)
2386 int PhysicsHandleIndex = INDEX_NONE;
2391 OnSocketingObject.Broadcast(NewDrop, SocketingParent, OptionalSocketName, RelativeTransformToParent, bWeldBodies);
2401 bool bIsHeld =
false;
2407 UPrimitiveComponent *root = NULL;
2419 root = Cast<UPrimitiveComponent>(pActor->GetRootComponent());
2421 pActor->RemoveTickPrerequisiteComponent(
this);
2424 if (
APawn* OwningPawn = Cast<APawn>(GetOwner()))
2426 OwningPawn->MoveIgnoreActorRemove(pActor);
2449 root->SetSimulatePhysics(
false);
2457 if (pActor->GetClass()->ImplementsInterface(UVRGripInterface::StaticClass()))
2459 IVRGripInterface::Execute_SetHeld(pActor,
this, NewDrop.
GripID,
false);
2469 TArray<UVRGripScriptBase*> GripScripts;
2470 if (IVRGripInterface::Execute_GetGripScripts(pActor, GripScripts))
2479 Script->OnGripRelease(
this, NewDrop,
true);
2484 IVRGripInterface::Execute_OnGripRelease(pActor,
this, NewDrop,
true);
2487 GripInterface->Native_NotifyThrowGripDelegates(
this,
false, NewDrop,
true);
2500 pActor = root->GetOwner();
2502 root->RemoveTickPrerequisiteComponent(
this);
2514 root->SetSimulatePhysics(
false);
2518 if (
IsServer() && root == pActor->GetRootComponent())
2523 if (pActor->GetClass()->ImplementsInterface(UVRGripInterface::StaticClass()))
2525 IVRGripInterface::Execute_OnChildGripRelease(pActor,
this, NewDrop,
true);
2529 if (root->GetClass()->ImplementsInterface(UVRGripInterface::StaticClass()))
2531 IVRGripInterface::Execute_SetHeld(root,
this, NewDrop.
GripID,
false);
2541 TArray<UVRGripScriptBase*> GripScripts;
2542 if (IVRGripInterface::Execute_GetGripScripts(root, GripScripts))
2551 Script->OnGripRelease(
this, NewDrop,
true);
2556 IVRGripInterface::Execute_OnGripRelease(root,
this, NewDrop,
true);
2559 GripInterface->Native_NotifyThrowGripDelegates(
this,
false, NewDrop,
true);
2564 if (root->GetAttachParent() && root->GetAttachParent()->GetClass()->ImplementsInterface(UVRGripInterface::StaticClass()))
2566 IVRGripInterface::Execute_OnChildGripRelease(root->GetAttachParent(),
this, NewDrop,
true);
2613 UPrimitiveComponent *root = NULL;
2616 bool bRootHasInterface =
false;
2617 bool bActorHasInterface =
false;
2637 root = Cast<UPrimitiveComponent>(pActor->GetRootComponent());
2639 if (root->GetClass()->ImplementsInterface(UVRGripInterface::StaticClass()))
2641 bRootHasInterface =
true;
2643 if (pActor->GetClass()->ImplementsInterface(UVRGripInterface::StaticClass()))
2646 bActorHasInterface =
true;
2649 if (
APawn* OwningPawn = Cast<APawn>(GetOwner()))
2653 OwningPawn->MoveIgnoreActorAdd(pActor);
2661 if (GetNetMode() < ENetMode::NM_Client)
2663 pActor->SetOwner(OwningPawn);
2668 if (!bIsReInit && bActorHasInterface)
2670 IVRGripInterface::Execute_SetHeld(pActor,
this, NewGrip.
GripID,
true);
2672 TArray<UVRGripScriptBase*> GripScripts;
2673 if (IVRGripInterface::Execute_GetGripScripts(pActor, GripScripts))
2679 Script->OnGrip(
this, NewGrip);
2684 uint8 GripID = NewGrip.
GripID;
2685 IVRGripInterface::Execute_OnGrip(pActor,
this, NewGrip);
2694 GripInterface->Native_NotifyThrowGripDelegates(
this,
true, NewGrip,
false);
2711 root->SetEnableGravity(
false);
2747 pActor = root->GetOwner();
2749 if (root->GetClass()->ImplementsInterface(UVRGripInterface::StaticClass()))
2751 bRootHasInterface =
true;
2753 if (pActor->GetClass()->ImplementsInterface(UVRGripInterface::StaticClass()))
2756 bActorHasInterface =
true;
2759 if (!bIsReInit && bRootHasInterface)
2761 IVRGripInterface::Execute_SetHeld(root,
this, NewGrip.
GripID,
true);
2763 TArray<UVRGripScriptBase*> GripScripts;
2764 if (IVRGripInterface::Execute_GetGripScripts(root, GripScripts))
2770 Script->OnGrip(
this, NewGrip);
2775 uint8 GripID = NewGrip.
GripID;
2776 IVRGripInterface::Execute_OnGrip(root,
this, NewGrip);
2786 GripInterface->Native_NotifyThrowGripDelegates(
this,
true, NewGrip,
false);
2804 if (!bIsReInit && bActorHasInterface)
2806 uint8 GripID = NewGrip.
GripID;
2807 IVRGripInterface::Execute_OnChildGrip(pActor,
this, NewGrip);
2817 if (!bIsReInit && root->GetAttachParent() && root->GetAttachParent()->GetClass()->ImplementsInterface(UVRGripInterface::StaticClass()))
2819 uint8 GripID = NewGrip.
GripID;
2820 IVRGripInterface::Execute_OnChildGrip(root->GetAttachParent(),
this, NewGrip);
2831 root->SetEnableGravity(
false);
2869 pActor->SetReplicateMovement(
false);
2877 if (UWorld* World = GetWorld())
2879 if (FPhysScene* PhysScene = World->GetPhysicsScene())
2884 if (BI && BI->IsInstanceSimulatingPhysics())
2886 PhysicsReplication->RemoveReplicatedTarget(root);
2904 pActor->SetReplicateMovement(
true);
2923 if (bHasMovementAuthority)
2932 if (bHasMovementAuthority)
2951 root->SetSimulatePhysics(
false);
2954 if (bHasMovementAuthority)
2962 if (bHasMovementAuthority ||
IsServer())
2979 if (root->IsSimulatingPhysics())
2981 root->SetSimulatePhysics(
false);
2984 if(root->GetAttachParent())
2986 root->DetachFromComponent(FDetachmentTransformRules::KeepWorldTransform);
2991 if (bHasMovementAuthority)
3023 TSubclassOf<class UVRGripScriptBase> Class = UGS_LerpToHand::StaticClass();
3038 GripInformation.
OnGripTransform = PrimParent->GetComponentTransform();
3047 float Distance = FVector::Dist(GripInformation.
OnGripTransform.GetLocation(), TargetTransform.GetLocation());
3057 float LerpScaler = 1.0f;
3058 float DistanceToSpeed = Distance / VRSettings.
LerpDuration;
3090 bool bIsHeld =
false;
3091 TArray<FBPGripPair> HoldingControllers;
3093 IVRGripInterface::Execute_IsHeld(GripInformation.
GrippedObject, HoldingControllers, bIsHeld);
3095 if (HoldingControllers.Num() > 0)
3097 for (
FBPGripPair& ControllerPair : HoldingControllers)
3099 if (ControllerPair.HoldingController && ControllerPair.HoldingController !=
this)
3103 ControllerPair.HoldingController->GetGripByID(Grip, ControllerPair.
GripID, Result);
3122 TSubclassOf<class UVRGripScriptBase> Class = UGS_LerpToHand::StaticClass();
3141 float OrigAlpha = FMath::Clamp(GripInformation.
CurrentLerpTime, 0.f, 1.0f);
3158 Alpha = FMath::Clamp(richCurve->Eval(Alpha), 0.f, 1.f);
3164 FTransform NB = WorldTransform;
3165 NA.NormalizeRotation();
3166 NB.NormalizeRotation();
3171 WorldTransform.Blend(NA, NB, Alpha);
3177 WorldTransform.SetTranslation(FMath::Lerp(NA.GetTranslation(), NB.GetTranslation(), Alpha));
3178 WorldTransform.SetScale3D(FMath::Lerp(NA.GetScale3D(), NB.GetScale3D(), Alpha));
3180 FRotator A = NA.Rotator();
3181 FRotator B = NB.Rotator();
3182 WorldTransform.SetRotation(FQuat(A + (Alpha * (B - A))));
3187 if ((NB.GetRotation() | NA.GetRotation()) < 0.0f)
3189 NB.SetRotation(NB.GetRotation() * -1.0f);
3191 WorldTransform = (FDualQuat(NA) * (1 - Alpha) + FDualQuat(NB) * Alpha).Normalized().AsFTransform(FMath::Lerp(NA.GetScale3D(), NB.GetScale3D(), Alpha));
3195 if (OrigAlpha >= 1.0f)
3238void UGripMotionControllerComponent::NotifyDrop_Implementation(
const FBPActorGripInformation &NewDrop,
bool bSimulate)
3244 GetNetMode() == ENetMode::NM_Client)
3261 bool bSkipFullDrop =
false;
3262 bool bHadAnotherSelfGrip =
false;
3263 TArray<FBPGripPair> HoldingControllers;
3264 bool bIsHeld =
false;
3268 IVRGripInterface::Execute_IsHeld(NewDrop.
GrippedObject, HoldingControllers, bIsHeld);
3270 if (bIsHeld && (!HoldingControllers.Contains(
this) || HoldingControllers.Num() > 1))
3273 bSkipFullDrop =
true;
3281 bSkipFullDrop =
true;
3282 bHadAnotherSelfGrip =
true;
3289 bSkipFullDrop =
true;
3290 bHadAnotherSelfGrip =
true;
3299 UPrimitiveComponent *root = NULL;
3311 root = Cast<UPrimitiveComponent>(pActor->GetRootComponent());
3316 pActor->RemoveTickPrerequisiteComponent(
this);
3321 if (
APawn * OwningPawn = Cast<APawn>(GetOwner()))
3323 OwningPawn->MoveIgnoreActorRemove(pActor);
3338 root->DetachFromComponent(FDetachmentTransformRules::KeepWorldTransform);
3348 if (root->IsSimulatingPhysics() != bSimulate)
3350 root->SetSimulatePhysics(bSimulate);
3354 root->WakeAllRigidBodies();
3358 root->UpdateComponentToWorld();
3399 if (pActor->GetClass()->ImplementsInterface(UVRGripInterface::StaticClass()))
3401 IVRGripInterface::Execute_SetHeld(pActor,
this, NewDrop.
GripID,
false);
3411 TArray<UVRGripScriptBase*> GripScripts;
3412 if (IVRGripInterface::Execute_GetGripScripts(pActor, GripScripts))
3421 Script->OnGripRelease(
this, NewDrop,
false);
3426 IVRGripInterface::Execute_OnGripRelease(pActor,
this, NewDrop,
false);
3430 GripInterface->Native_NotifyThrowGripDelegates(
this,
false, NewDrop,
false);
3442 pActor = root->GetOwner();
3446 root->RemoveTickPrerequisiteComponent(
this);
3454 root->DetachFromComponent(FDetachmentTransformRules::KeepWorldTransform);
3465 if (root->IsSimulatingPhysics() != bSimulate)
3467 root->SetSimulatePhysics(bSimulate);
3471 root->WakeAllRigidBodies();
3475 root->UpdateComponentToWorld();
3511 if (
IsServer() && root == pActor->GetRootComponent() && !bSkipFullDrop)
3516 if (pActor->GetClass()->ImplementsInterface(UVRGripInterface::StaticClass()))
3518 IVRGripInterface::Execute_OnChildGripRelease(pActor,
this, NewDrop,
false);
3523 if (root->GetClass()->ImplementsInterface(UVRGripInterface::StaticClass()))
3525 IVRGripInterface::Execute_SetHeld(root,
this, NewDrop.
GripID,
false);
3535 TArray<UVRGripScriptBase*> GripScripts;
3536 if (IVRGripInterface::Execute_GetGripScripts(root, GripScripts))
3545 Script->OnGripRelease(
this, NewDrop,
false);
3550 IVRGripInterface::Execute_OnGripRelease(root,
this, NewDrop,
false);
3553 GripInterface->Native_NotifyThrowGripDelegates(
this,
false, NewDrop,
false);
3559 if (root->GetAttachParent() && root->GetAttachParent()->GetClass()->ImplementsInterface(UVRGripInterface::StaticClass()))
3561 IVRGripInterface::Execute_OnChildGripRelease(root->GetAttachParent(),
this, NewDrop,
false);
3581 if (UWorld * World = GetWorld())
3583 if (FPhysScene * PhysScene = World->GetPhysicsScene())
3588 if (BI && BI->IsInstanceSimulatingPhysics())
3590 PhysicsReplication->RemoveReplicatedTarget(root);
3647 bool bNeedsPhysicsTick =
false;
3655 bNeedsPhysicsTick =
true;
3667 bNeedsPhysicsTick =
true;
3673 if (!bNeedsPhysicsTick)
3682 bNeedsPhysicsTick =
true;
3691 if (!bNeedsPhysicsTick)
3733 UE_LOG(LogVRMotionController,
Warning, TEXT(
"VRGripMotionController add secondary attachment function was called on the client side with a replicated grip"));
3737 GripToUse =
GrippedObjects.FindByKey(GrippedObjectToAddAttachment);
3742 return AddSecondaryAttachmentToGrip(*GripToUse, SecondaryPointComponent, OriginalTransform, bTransformIsAlreadyRelative, LerpToTime, bIsSlotGrip, SecondarySlotName);
3761 return AddSecondaryAttachmentToGrip(*GripToUse, SecondaryPointComponent, OriginalTransform, bTransformIsAlreadyRelative, LerpToTime, bIsSlotGrip, SecondarySlotName);
3770 if (!SecondaryPointComponent)
3772 UE_LOG(LogVRMotionController,
Warning, TEXT(
"VRGripMotionController add secondary attachment function was called with a bad secondary component target!"));
3777 bool bWasLocal =
false;
3790 UE_LOG(LogVRMotionController,
Warning, TEXT(
"VRGripMotionController add secondary attachment function was called with a bad grip! It was not valid / found."));
3796 UE_LOG(LogVRMotionController,
Warning, TEXT(
"VRGripMotionController add secondary attachment function was called with a bad grip (gripped object invalid)!"));
3803 UE_LOG(LogVRMotionController,
Warning, TEXT(
"VRGripMotionController add secondary attachment function was called on the client side with a replicated grip"));
3807 bool bGrippedObjectIsInterfaced = GripToUse->
GrippedObject->GetClass()->ImplementsInterface(UVRGripInterface::StaticClass());
3809 if (bGrippedObjectIsInterfaced)
3815 UE_LOG(LogVRMotionController,
Warning, TEXT(
"VRGripMotionController add secondary attachment function was called on an interface object set to SG_None!"));
3820 UPrimitiveComponent * root =
nullptr;
3830 root = Cast<UPrimitiveComponent>(pActor->GetRootComponent());
3843 UE_LOG(LogVRMotionController,
Warning, TEXT(
"VRGripMotionController add secondary attachment function was unable to get root component or gripped component."));
3847 if (bTransformIsAlreadyRelative)
3869 if (LerpToTime > 0.0f)
3876 if (bGrippedObjectIsInterfaced)
3880 IVRGripInterface::Execute_OnSecondaryGrip(GripToUse->
GrippedObject,
this, SecondaryPointComponent, *GripToUse);
3882 TArray<UVRGripScriptBase*> GripScripts;
3883 if (IVRGripInterface::Execute_GetGripScripts(GripToUse->
GrippedObject, GripScripts))
3889 Script->OnSecondaryGrip(
this, SecondaryPointComponent, *GripToUse);
3901 GripToUse =
nullptr;
3921 UE_LOG(LogVRMotionController,
Warning, TEXT(
"VRGripMotionController remove secondary attachment function was called on the client side for a replicating grip"));
3925 GripToUse =
GrippedObjects.FindByKey(GrippedObjectToRemoveAttachment);
3959 bool bWasLocal =
false;
3970 if (GripToUse && !bWasLocal && !
IsServer())
3972 UE_LOG(LogVRMotionController,
Warning, TEXT(
"VRGripMotionController remove secondary attachment function was called on the client side for a replicating grip"));
3986 UPrimitiveComponent * primComp =
nullptr;
3998 primComp = Cast<UPrimitiveComponent>(pActor->GetRootComponent());
4002 bool bGripObjectHasInterface = GripToUse->
GrippedObject->GetClass()->ImplementsInterface(UVRGripInterface::StaticClass());
4005 if (bGripObjectHasInterface)
4007 SecondaryType = IVRGripInterface::Execute_SecondaryGripType(GripToUse->
GrippedObject);
4014 switch (SecondaryType)
4029 if (LerpToTime > 0.0f)
4047 if (bGripObjectHasInterface)
4051 TArray<UVRGripScriptBase*> GripScripts;
4052 if (IVRGripInterface::Execute_GetGripScripts(GripToUse->
GrippedObject, GripScripts))
4069 switch (SecondaryType)
4092 GripToUse =
nullptr;
4135 FTransform EmptyTransform = FTransform::Identity;
4149 FTransform EmptyTransform = FTransform::Identity;
4157 if (!bHasMovementAuthority)
4160 UPrimitiveComponent * PrimComp = NULL;
4164 bool bRootHasInterface =
false;
4165 bool bActorHasInterface =
false;
4175 PrimComp = Cast<UPrimitiveComponent>(actor->GetRootComponent());
4176 if (actor->GetClass()->ImplementsInterface(UVRGripInterface::StaticClass()))
4178 bActorHasInterface =
true;
4190 actor = PrimComp->GetOwner();
4191 if (PrimComp->GetClass()->ImplementsInterface(UVRGripInterface::StaticClass()))
4193 bRootHasInterface =
true;
4201 if (!PrimComp || !actor || actor->IsPendingKill() || PrimComp->IsPendingKill())
4207 bool bSimulateOnDrop =
false;
4210 if (bRootHasInterface)
4212 TeleportBehavior = IVRGripInterface::Execute_TeleportBehavior(PrimComp);
4213 bSimulateOnDrop = IVRGripInterface::Execute_SimulateOnDrop(PrimComp);
4215 else if (bActorHasInterface)
4218 TeleportBehavior = IVRGripInterface::Execute_TeleportBehavior(actor);
4219 bSimulateOnDrop = IVRGripInterface::Execute_SimulateOnDrop(actor);
4222 if (bIsForPostTeleport)
4226 if (
AActor * owner = PrimComp->GetOwner())
4228 if (PrimComp != owner->GetRootComponent())
4252 switch (TeleportBehavior)
4263 FTransform WorldTransform;
4268 if (!OptionalTransform.Equals(FTransform::Identity))
4270 WorldTransform = OptionalTransform;
4274 TArray<UVRGripScriptBase*> Scripts;
4276 if (bRootHasInterface)
4278 IVRGripInterface::Execute_GetGripScripts(PrimComp, Scripts);
4280 else if (bActorHasInterface)
4282 IVRGripInterface::Execute_GetGripScripts(actor, Scripts);
4285 bool bForceADrop =
false;
4286 bool bHadValidWorldTransform =
GetGripWorldTransform(Scripts, 0.0f, WorldTransform, ParentTransform, copyGrip, actor, PrimComp, bRootHasInterface, bActorHasInterface,
true, bForceADrop);
4288 if (!bHadValidWorldTransform)
4292 if (!WorldTransform.IsValid())
4294 UE_LOG(LogVRMotionController,
Warning, TEXT(
"Something went wrong, TeleportGrip_Impl's target transform contained NAN."));
4300 FTransform physicsTrans = WorldTransform;
4303 FTransform baseTrans = this->GetAttachParent()->GetComponentTransform();
4311 TArray<FBPGripPair> HoldingControllers;
4312 bool bIsHeld =
false;
4313 IVRGripInterface::Execute_IsHeld(Grip.
GrippedObject, HoldingControllers, bIsHeld);
4317 if (pair.HoldingController && pair.HoldingController !=
this && pair.HoldingController->bIsPostTeleport)
4331 if (!WorldTransform.IsValid())
4333 if (WorldTransform.ContainsNaN())
4335 UE_LOG(LogVRMotionController,
Error, TEXT(
"Failed to teleport grip, bad transform, NaN detected with object: %s"), *Grip.
GrippedObject->GetName());
4338 else if (!WorldTransform.GetRotation().IsNormalized())
4340 WorldTransform.NormalizeRotation();
4342 if (!WorldTransform.IsValid())
4344 UE_LOG(LogVRMotionController,
Error, TEXT(
"Failed to teleport grip, bad transform, rotation normalization issue: %s"), *Grip.
GrippedObject->GetName());
4349 UE_LOG(LogVRMotionController,
Error, TEXT(
"Error during teleport grip, rotation not normalized for object: %s"), *Grip.
GrippedObject->GetName());
4359 PrimComp->SetWorldTransform(WorldTransform,
false, NULL, ETeleportType::TeleportPhysics);
4361 else if (Handle && FPhysicsInterface::IsValid(Handle->
KinActorData2) && bTeleportPhysicsGrips)
4364#if PHYSICS_INTERFACE_PHYSX
4383 PrimComp->SetWorldTransform(WorldTransform,
false, NULL, ETeleportType::TeleportPhysics);
4387 physicsTrans.SetScale3D(FVector(1.0f));
4391 FBodyInstance* pInstance = PrimComp->GetBodyInstance();
4394 if (pInstance && pInstance->IsValidBodyInstance())
4396 FPhysicsCommand::ExecuteWrite(pInstance->GetPhysicsScene(), [&]()
4398 if (FPhysicsInterface::IsValid(ActorHandle) && FPhysicsInterface::GetCurrentScene(ActorHandle))
4400 FPhysicsInterface::SetKinematicTarget_AssumesLocked(ActorHandle, newTrans);
4401 FPhysicsInterface::SetGlobalPose_AssumesLocked(ActorHandle, newTrans);
4422 Super::Deactivate();
4429 FScopeLock ScopeLock(&CritSect);
4439 if (
AVRBaseCharacter* CharacterOwner = Cast<AVRBaseCharacter>(this->GetOwner()))
4448 Super::OnAttachmentChanged();
4473 float NewDistance = OldToNewVector.SizeSquared();
4510 FVector Position = GetRelativeLocation();
4511 FRotator Orientation = GetRelativeRotation();
4517 GripViewExtension = FSceneViewExtensions::NewExtension<FGripViewExtension>(
this);
4520 float WorldToMeters = GetWorld() ? GetWorld()->GetWorldSettings()->WorldToMeters : 100.0f;
4521 ETrackingStatus LastTrackingStatus = CurrentTrackingStatus;
4529 FTransform CalcedTransform = FTransform(Orientation, Position, this->GetRelativeScale3D());
4539 SetRelativeTransform(CalcedTransform);
4544 const float Alpha = FMath::Clamp(DeltaTime *
SmoothingSpeed, 0.f, 1.f);
4563 SetRelativeTransform(FTransform(Orientation, Position, this->GetRelativeScale3D()));
4568 if (LastTrackingStatus != CurrentTrackingStatus)
4572 if (LastTrackingStatus == ETrackingStatus::NotTracked)
4576 if (bDisplayDeviceModel && DisplayModelSource != UMotionControllerComponent::CustomModelSourceId)
4577 RefreshDisplayComponent();
4588 FVector RelLoc = GetRelativeLocation();
4589 FRotator RelRot = GetRelativeRotation();
4606 if (GetNetMode() == NM_Client)
4628 FScopeLock ScopeLock(&CritSect);
4649 if (LerpVal >= 1.0f)
4664 SetRelativeLocationAndRotation(
4681 FTransform NA = FTransform(GetRelativeRotation(), GetRelativeLocation(), FVector(1.0f));
4683 NA.NormalizeRotation();
4684 NB.NormalizeRotation();
4686 NA.Blend(NA, NB, Alpha);
4689 if (NA.EqualsNoScale(NB))
4696 SetRelativeLocationAndRotation(NA.GetTranslation(), NA.Rotator());
4705 Super::Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
4739bool UGripMotionControllerComponent::GetGripWorldTransform(TArray<UVRGripScriptBase*>& GripScripts,
float DeltaTime, FTransform & WorldTransform,
const FTransform &ParentTransform,
FBPActorGripInformation &Grip,
AActor * actor, UPrimitiveComponent * root,
bool bRootHasInterface,
bool bActorHasInterface,
bool bIsForTeleport,
bool &bForceADrop)
4741 SCOPE_CYCLE_COUNTER(STAT_GetGripTransform);
4743 bool bHasValidTransform =
true;
4745 if (GripScripts.Num())
4747 bool bGetDefaultTransform =
true;
4755 bGetDefaultTransform =
false;
4772 bHasValidTransform = Script->CallCorrect_GetWorldTransform(
this, DeltaTime, WorldTransform, ParentTransform, Grip, actor, root, bRootHasInterface, bActorHasInterface, bIsForTeleport);
4773 bForceADrop = Script->Wants_ToForceDrop();
4776 if (!bHasValidTransform || bForceADrop)
4792 if (bHasValidTransform && !WorldTransform.IsValid())
4794 UE_LOG(LogVRMotionController,
Warning, TEXT(
"Something went wrong, GetGripWorldTransform tried to return NAN!."));
4795 bHasValidTransform =
false;
4798 return bHasValidTransform;
4803 SCOPE_CYCLE_COUNTER(STAT_TickGrip);
4809 UE_LOG(LogVRMotionController,
Warning, TEXT(
"Something went wrong, there were too many physics handles for how many grips exist! Cleaned up bad handles."));
4826 if (bOriginalPostTeleport)
4844 ComponentVelocity = newVelocitySample;
4872 return Super::GetComponentVelocity();
4877 if (GrippedObjectsArray.Num())
4879 FTransform WorldTransform;
4881 for (
int i = GrippedObjectsArray.Num() - 1; i >= 0; --i)
4904 UPrimitiveComponent *root = NULL;
4915 root = Cast<UPrimitiveComponent>(actor->GetRootComponent());
4923 actor = root->GetOwner();
4930 if (!root || !actor || root->IsPendingKill() || actor->IsPendingKill())
4935 if (GetWorld()->IsInSeamlessTravel())
4941 bool bRootHasInterface =
false;
4942 bool bActorHasInterface =
false;
4944 if (root->GetClass()->ImplementsInterface(UVRGripInterface::StaticClass()))
4946 bRootHasInterface =
true;
4948 else if (actor->GetClass()->ImplementsInterface(UVRGripInterface::StaticClass()))
4951 bActorHasInterface =
true;
4957 if(bRootHasInterface)
4958 IVRGripInterface::Execute_TickGrip(root,
this, *Grip, DeltaTime);
4959 else if(bActorHasInterface)
4960 IVRGripInterface::Execute_TickGrip(actor,
this, *Grip, DeltaTime);
4965 bool bRescalePhysicsGrips =
false;
4967 TArray<UVRGripScriptBase*> GripScripts;
4969 if (bRootHasInterface)
4971 IVRGripInterface::Execute_GetGripScripts(root, GripScripts);
4973 else if (bActorHasInterface)
4975 IVRGripInterface::Execute_GetGripScripts(actor, GripScripts);
4979 bool bForceADrop =
false;
4982 bool bHasValidWorldTransform =
GetGripWorldTransform(GripScripts, DeltaTime, WorldTransform, ParentTransform, *Grip, actor, root, bRootHasInterface, bActorHasInterface,
false, bForceADrop);
4989 if (bRootHasInterface)
4991 else if (bActorHasInterface)
4999 else if (!bHasValidWorldTransform)
5004 if (Grip->
GrippedBoneName == NAME_None && !root->GetComponentTransform().GetScale3D().Equals(WorldTransform.GetScale3D()))
5005 bRescalePhysicsGrips =
true;
5011 bool bSkipTeleport =
false;
5014 if (Script && Script->IsScriptActive() && Script->Wants_DenyTeleport(
this))
5016 bSkipTeleport =
true;
5037 if ((bRootHasInterface || bActorHasInterface) &&
5054 float BreakDistance = 0.0f;
5055 if (bRootHasInterface)
5057 BreakDistance = IVRGripInterface::Execute_GripBreakDistance(root);
5059 else if (bActorHasInterface)
5062 BreakDistance = IVRGripInterface::Execute_GripBreakDistance(actor);
5065 FVector CheckDistance;
5068 CheckDistance = (WorldTransform.GetLocation() - root->GetComponentLocation());
5074 if (BreakDistance > 0.0f)
5078 bool bIgnoreDrop =
false;
5081 if (Script && Script->IsScriptActive() && Script->Wants_DenyAutoDrop())
5094 uint8 GripID = Grip->
GripID;
5109 if(bRootHasInterface)
5130 if (bRescalePhysicsGrips)
5131 root->SetWorldScale3D(WorldTransform.GetScale3D());
5142 FComponentQueryParams Params(NAME_None, this->GetOwner());
5144 Params.AddIgnoredActor(actor);
5145 Params.AddIgnoredActors(root->MoveIgnoreActors);
5147 actor->ForEachAttachedActors([&Params](
AActor*
Actor)
5149 Params.AddIgnoredActor(
Actor);
5153 TArray<FHitResult> Hits;
5157 GetWorld()->ComponentSweepMulti(Hits, root, root->GetComponentLocation(), WorldTransform.GetLocation(), WorldTransform.GetRotation(), Params)
5169 for (
const FHitResult& Hit : Hits)
5193 FVector OriginalPosition(root->GetComponentLocation());
5194 FVector NewPosition(WorldTransform.GetTranslation());
5197 root->ComponentVelocity = (NewPosition - OriginalPosition) / DeltaTime;
5208 FTransform baseTrans = this->GetAttachParent()->GetComponentTransform();
5209 root->SetWorldTransform(Grip->
LastWorldTransform * baseTrans,
false,
nullptr, ETeleportType::None);
5210 root->SetWorldTransform(WorldTransform,
true, &OutHit);
5214 root->SetWorldTransform(WorldTransform,
true, &OutHit);
5217 if (OutHit.bBlockingHit)
5240 if (bRescalePhysicsGrips)
5241 root->SetWorldScale3D(WorldTransform.GetScale3D());
5245 FComponentQueryParams Params(NAME_None, this->GetOwner());
5247 Params.AddIgnoredActor(actor);
5248 Params.AddIgnoredActors(root->MoveIgnoreActors);
5250 actor->ForEachAttachedActors([&Params](
AActor*
Actor)
5252 Params.AddIgnoredActor(
Actor);
5256 TArray<FHitResult> Hits;
5268 else if (GetWorld()->ComponentSweepMulti(Hits, root, root->GetComponentLocation(), WorldTransform.GetLocation(), WorldTransform.GetRotation(), Params))
5280 for (
const FHitResult& Hit : Hits)
5284 if (!bOriginalColliding)
5295 if (bOriginalColliding)
5328 TArray<FHitResult> Hits;
5329 FComponentQueryParams Params(NAME_None, this->GetOwner());
5331 Params.AddIgnoredActor(actor);
5332 Params.AddIgnoredActors(root->MoveIgnoreActors);
5334 actor->ForEachAttachedActors([&Params](
AActor*
Actor)
5336 Params.AddIgnoredActor(
Actor);
5340 FTransform BaseTransform = root->GetComponentTransform();
5344 FTransform baseTrans = this->GetAttachParent()->GetComponentTransform();
5349 bool bLerpCollisions =
false;
5350 bool bLerpRotationOnly =
false;
5351 bool bDistanceBasedInterpolation =
false;
5352 float LerpSpeed = 0.0f;
5368 else if (GetWorld()->ComponentSweepMulti(Hits, root, BaseTransform.GetLocation(), WorldTransform.GetLocation(), WorldTransform.GetRotation(), Params))
5378 for (
const FHitResult& Hit : Hits)
5390 if (bLerpCollisions && GetWorld()->ComponentSweepMulti(Hits, root, BaseTransform.GetLocation(), WorldTransform.GetLocation(), root->GetComponentRotation(), Params))
5392 for (
const FHitResult& Hit : Hits)
5409 else if (bLerpCollisions && GetWorld()->ComponentSweepMulti(Hits, root, BaseTransform.GetLocation(), WorldTransform.GetLocation(), root->GetComponentRotation(), Params))
5419 for (
const FHitResult& Hit : Hits)
5440 if (GripHandle && !GripHandle->
bIsPaused)
5449 root->SetSimulatePhysics(
false);
5453 root->SetSimulatePhysics(
false);
5470 if (bDistanceBasedInterpolation)
5482 if (bDistanceBasedInterpolation)
5490 Alpha = FMath::Clamp(DeltaTime * Grip->
LerpSpeed, 0.f, 1.f);
5495 float OrigAlpha = FMath::Clamp(1.0f - Grip->
CurrentLerpTime, 0.f, 1.0f);
5499 FTransform NA = WorldTransform;
5500 NA.NormalizeRotation();
5501 NB.NormalizeRotation();
5503 if (!bLerpRotationOnly)
5505 WorldTransform.Blend(NB, NA, Alpha);
5509 WorldTransform.SetRotation(FQuat::Slerp(NB.GetRotation(), NA.GetRotation(), Alpha));
5512 if (bDistanceBasedInterpolation)
5514 if (NA.Equals(WorldTransform))
5530 FTransform baseTrans = this->GetAttachParent()->GetComponentTransform();
5531 root->SetWorldTransform(Grip->
LastWorldTransform * baseTrans,
false,
nullptr, ETeleportType::None);
5532 root->SetWorldTransform(WorldTransform,
false);
5536 root->SetWorldTransform(WorldTransform,
false);
5560 if (bRescalePhysicsGrips)
5561 root->SetWorldScale3D(WorldTransform.GetScale3D());
5570 if (bRescalePhysicsGrips)
5571 root->SetWorldScale3D(WorldTransform.GetScale3D());
5580 if (root->IsSimulatingPhysics())
5582 root->SetSimulatePhysics(
false);
5585 FVector OriginalPosition(root->GetComponentLocation());
5586 FRotator OriginalOrientation(root->GetComponentRotation());
5588 FVector NewPosition(WorldTransform.GetTranslation());
5589 FRotator NewOrientation(WorldTransform.GetRotation());
5591 root->ComponentVelocity = (NewPosition - OriginalPosition) / DeltaTime;
5594 if (
bUseWithoutTracking || NewPosition != OriginalPosition || NewOrientation != OriginalOrientation)
5596 FVector move = NewPosition - OriginalPosition;
5599 const float MinMovementDistSq = (FMath::Square(4.f*KINDA_SMALL_NUMBER));
5601 if (
bUseWithoutTracking || move.SizeSquared() > MinMovementDistSq || NewOrientation != OriginalOrientation)
5612 TArray<USceneComponent* > PrimChildren;
5613 root->GetChildrenComponents(
true, PrimChildren);
5616 if (UPrimitiveComponent * primComp = Cast<UPrimitiveComponent>(Prim))
5627 FTransform baseTrans = this->GetAttachParent()->GetComponentTransform();
5628 root->SetWorldTransform(Grip->
LastWorldTransform * baseTrans,
false,
nullptr, ETeleportType::None);
5630 root->SetWorldTransform(WorldTransform,
false);
5635 root->SetWorldTransform(WorldTransform,
false);
5643 if (root->IsSimulatingPhysics())
5645 root->SetSimulatePhysics(
false);
5651 FTransform baseTrans = this->GetAttachParent()->GetComponentTransform();
5652 root->SetWorldTransform(Grip->
LastWorldTransform * baseTrans,
false,
nullptr, ETeleportType::None);
5654 root->SetWorldTransform(WorldTransform,
false);
5659 root->SetWorldTransform(WorldTransform,
false);
5666 FTransform RelativeTrans = WorldTransform.GetRelativeTransform(ParentTransform);
5668 if (!root->GetAttachParent() || root->IsSimulatingPhysics())
5670 UE_LOG(LogVRMotionController,
Warning, TEXT(
"Attachment Grip was missing attach parent - Attempting to Re-attach"));
5674 root->SetSimulatePhysics(
false);
5677 UE_LOG(LogVRMotionController,
Warning, TEXT(
"Re-attached"));
5678 if (!root->GetRelativeTransform().Equals(RelativeTrans))
5680 root->SetRelativeTransform(RelativeTrans);
5687 if (!root->GetRelativeTransform().Equals(RelativeTrans))
5689 root->SetRelativeTransform(RelativeTrans);
5699 if (bRescalePhysicsGrips)
5700 root->SetWorldScale3D(WorldTransform.GetScale3D());
5712 if (bRootHasInterface)
5714 IVRGripInterface::Execute_TickGrip(root,
this, *Grip, DeltaTime);
5717 if (bActorHasInterface)
5719 IVRGripInterface::Execute_TickGrip(actor,
this, *Grip, DeltaTime);
5756 UE_LOG(LogVRMotionController,
Warning, TEXT(
"Gripped object was null or destroying, auto dropping it"));
5760 GrippedObjectsArray[GripIndex].bIsPendingKill =
true;
5761 GrippedObjectsArray[GripIndex].bIsPaused =
true;
5797 int HandleIndex = 0;
5805#if !PHYSICS_INTERFACE_PHYSX
5820 if (!root && pActor)
5821 root = Cast<UPrimitiveComponent>(pActor->GetRootComponent());
5826 FBodyInstance* rBodyInstance = root->GetBodyInstance(GripInfo.
GrippedBoneName);
5827 if (!rBodyInstance || !rBodyInstance->IsValidBodyInstance() || !FPhysicsInterface::IsValid(rBodyInstance->ActorHandle))
5832 check(rBodyInstance->BodySetup->GetCollisionTraceFlag() != CTF_UseComplexAsSimple);
5834 FPhysicsCommand::ExecuteWrite(rBodyInstance->ActorHandle, [&](
const FPhysicsActorHandle&
Actor)
5838 if (PxRigidDynamic * PActor = FPhysicsInterface::GetPxRigidDynamic_AssumesLocked(Actor))
5840 if(HandleInfo->HandleData2.IsValid() && HandleInfo->HandleData2.ConstraintData)
5841 HandleInfo->HandleData2.ConstraintData->setActors(PActor, FPhysicsInterface::GetPxRigidDynamic_AssumesLocked(HandleInfo->KinActorData2));
5844 if (HandleInfo->bSetCOM && !HandleInfo->bSkipResettingCom)
5849 FTransform localCom = FPhysicsInterface::GetComTransformLocal_AssumesLocked(Actor);
5851 localCom.SetLocation(HandleInfo->COMPosition.GetTranslation());
5852 FPhysicsInterface::SetComLocalPose_AssumesLocked(Actor, localCom);
5871 FPhysicsInterface::ReleaseConstraint(HandleInfo->
HandleData2);
5891 FPhysicsInterface::ReleaseConstraint(HandleInfo->
HandleData2);
5897 FPhysicsActorHandle ActorHandle = HandleInfo->
KinActorData2;
5898 FPhysicsCommand::ExecuteWrite(ActorHandle, [&](
const FPhysicsActorHandle&
Actor)
5920 if (!root && pActor)
5921 root = Cast<UPrimitiveComponent>(pActor->GetRootComponent());
5925 if (FBodyInstance * rBodyInstance = root->GetBodyInstance(Grip.
GrippedBoneName))
5929 if (!bSkipUnregistering)
5931 if (rBodyInstance->OnRecalculatedMassProperties().IsBoundToObject(
this))
5933 rBodyInstance->OnRecalculatedMassProperties().RemoveAll(
this);
5941 FVector vel = rBodyInstance->GetUnrealWorldVelocity();
5942 FVector aVel = rBodyInstance->GetUnrealWorldAngularVelocityInRadians();
5943 FVector originalCOM = rBodyInstance->GetCOMPosition();
5945 if (rBodyInstance->IsValidBodyInstance() && rBodyInstance->BodySetup.IsValid())
5947 rBodyInstance->UpdateMassProperties();
5950 if (rBodyInstance->IsInstanceSimulatingPhysics())
5953 vel += FVector::CrossProduct(aVel, rBodyInstance->GetCOMPosition() - originalCOM);
5954 rBodyInstance->SetLinearVelocity(vel,
false);
5971 TArray<FBPActorGripInformation> GripArray;
5975 for (
int i = 0; i < GripArray.Num(); i++)
5977 NewGrip = GripArray[i];
5982 if (!root && pActor)
5984 if (pActor->IsPendingKill())
5987 root = Cast<UPrimitiveComponent>(pActor->GetRootComponent());
5990 if (!root || root != GripBodyInstance->OwnerComponent)
5993 if (!root->IsPendingKill())
6007 root = Cast<UPrimitiveComponent>(pActor->GetRootComponent());
6013 if (HandleInfo ==
nullptr)
6028 TArray<UVRGripScriptBase*> LocalGripScripts;
6029 if (GripScripts ==
nullptr)
6031 if (root && root->GetClass()->ImplementsInterface(UVRGripInterface::StaticClass()))
6033 if (IVRGripInterface::Execute_GetGripScripts(root, LocalGripScripts))
6035 GripScripts = &LocalGripScripts;
6038 else if (pActor && pActor->GetClass()->ImplementsInterface(UVRGripInterface::StaticClass()))
6040 if (IVRGripInterface::Execute_GetGripScripts(pActor, LocalGripScripts))
6042 GripScripts = &LocalGripScripts;
6055 root->RecreatePhysicsState();
6058 if(!root->IsSimulatingPhysics())
6060 root->SetSimulatePhysics(
true);
6065 FBodyInstance* rBodyInstance = root->GetBodyInstance(NewGrip.
GrippedBoneName);
6066 if (!rBodyInstance || !rBodyInstance->IsValidBodyInstance() || !FPhysicsInterface::IsValid(rBodyInstance->ActorHandle) || !rBodyInstance->BodySetup.IsValid())
6071 check(rBodyInstance->BodySetup->GetCollisionTraceFlag() != CTF_UseComplexAsSimple);
6073 if (!HandleInfo->
bSkipResettingCom && !FPhysicsInterface::IsValid(HandleInfo->
KinActorData2) && !rBodyInstance->OnRecalculatedMassProperties().IsBoundToObject(
this))
6077 rBodyInstance->UpdateMassProperties();
6081 FPhysicsCommand::ExecuteWrite(rBodyInstance->ActorHandle, [&](
const FPhysicsActorHandle&
Actor)
6085 FTransform trans = FPhysicsInterface::GetGlobalPose_AssumesLocked(Actor);
6086 FTransform RootBoneRotation = FTransform::Identity;
6088 if (NewGrip.GrippedBoneName != NAME_None)
6097 if (USkeletalMeshComponent * skele = Cast<USkeletalMeshComponent>(root))
6099 int32 RootBodyIndex = INDEX_NONE;
6100 if (const UPhysicsAsset* PhysicsAsset = skele->GetPhysicsAsset())
6102 for (int32 i = 0; i < skele->GetNumBones(); i++)
6104 if (PhysicsAsset->FindBodyIndex(skele->GetBoneName(i)) != INDEX_NONE)
6112 if (RootBodyIndex != INDEX_NONE)
6114 RootBoneRotation = FTransform(skele->GetBoneTransform(RootBodyIndex, FTransform::Identity));
6115 RootBoneRotation.SetScale3D(FVector(1.f));
6116 RootBoneRotation.NormalizeRotation();
6117 HandleInfo->RootBoneRotation = RootBoneRotation;
6122 EPhysicsGripCOMType COMType = NewGrip.AdvancedGripSettings.PhysicsSettings.PhysicsGripLocationSettings;
6126 if (NewGrip.GripCollisionType == EGripCollisionType::ManipulationGrip || NewGrip.GripCollisionType == EGripCollisionType::ManipulationGripWithWristTwist)
6128 COMType = EPhysicsGripCOMType::COM_GripAtControllerLoc;
6132 COMType = EPhysicsGripCOMType::COM_SetAndGripAt;
6140 FTransform ForwardTrans = (RootBoneRotation * NewGrip.RelativeTransform);
6141 ForwardTrans.NormalizeRotation();
6142 FVector Loc = (FTransform(ForwardTrans.ToInverseMatrixWithScale())).GetLocation();
6143 Loc *= rBodyInstance->Scale3D;
6145 FTransform localCom = FPhysicsInterface::GetComTransformLocal_AssumesLocked(
Actor);
6146 localCom.SetLocation(Loc);
6147 FPhysicsInterface::SetComLocalPose_AssumesLocked(
Actor, localCom);
6149 FVector ComLoc = FPhysicsInterface::GetComTransform_AssumesLocked(
Actor).GetLocation();
6150 trans.SetLocation(ComLoc);
6151 HandleInfo->COMPosition = FTransform(rBodyInstance->GetUnrealWorldTransform().InverseTransformPosition(ComLoc));
6152 HandleInfo->bSetCOM =
true;
6156 FVector ControllerLoc = (FTransform(NewGrip.RelativeTransform.ToInverseMatrixWithScale()) * root->GetComponentTransform()).GetLocation();
6157 trans.SetLocation(ControllerLoc);
6158 HandleInfo->COMPosition = FTransform(rBodyInstance->GetUnrealWorldTransform().InverseTransformPosition(ControllerLoc));
6162 FVector ComLoc = FPhysicsInterface::GetComTransform_AssumesLocked(
Actor).GetLocation();
6163 trans.SetLocation(ComLoc);
6164 HandleInfo->COMPosition = FTransform(rBodyInstance->GetUnrealWorldTransform().InverseTransformPosition(ComLoc));
6168 bool bRecreatingConstraint =
false;
6176 FQuat DeltaQuat = (PivTrans.GetRotation().Inverse() * KinPose.GetRotation()).Inverse();
6179 KinPose.SetRotation(KinPose.GetRotation() * DeltaQuat);
6180 HandleInfo->COMPosition.SetRotation(HandleInfo->COMPosition.GetRotation()* DeltaQuat);
6185 bool bResetCom =
false;
6190 if (Script && Script->IsScriptActive() && Script->InjectPrePhysicsHandle())
6192 Script->HandlePrePhysicsHandle(
this, NewGrip, HandleInfo, KinPose);
6197 if (HandleInfo->bSetCOM && bResetCom)
6199 FTransform localCom = FPhysicsInterface::GetComTransformLocal_AssumesLocked(
Actor);
6200 localCom.SetLocation(HandleInfo->COMPosition.GetTranslation());
6202 FPhysicsInterface::SetComLocalPose_AssumesLocked(
Actor, localCom);
6212 HandleInfo->KinActorData2 = Bodyinst->GetPhysicsActorHandle();
6217 if (!FPhysicsInterface::IsValid(HandleInfo->KinActorData2))
6224 FActorCreationParams ActorParams;
6225 ActorParams.InitialTM = KinPose;
6226 ActorParams.DebugName =
nullptr;
6227 ActorParams.bEnableGravity =
false;
6228 ActorParams.bQueryOnly =
false;
6229 ActorParams.bStatic =
false;
6230 ActorParams.Scene = FPhysicsInterface::GetCurrentScene(
Actor);
6231 FPhysicsInterface::CreateActor(ActorParams, HandleInfo->KinActorData2);
6233 if (FPhysicsInterface::IsValid(HandleInfo->KinActorData2))
6235 FPhysicsInterface::SetMass_AssumesLocked(HandleInfo->KinActorData2, 1.0f);
6236 FPhysicsInterface::SetMassSpaceInertiaTensor_AssumesLocked(HandleInfo->KinActorData2, FVector(1.f));
6237 FPhysicsInterface::SetIsKinematic_AssumesLocked(HandleInfo->KinActorData2,
true);
6238 FPhysicsInterface::SetMaxDepenetrationVelocity_AssumesLocked(HandleInfo->KinActorData2, MAX_FLT);
6242#if PHYSICS_INTERFACE_PHYSX
6244 ActorParams.Scene->GetPxScene()->addActor(*FPhysicsInterface_PhysX::GetPxRigidActor_AssumesLocked(HandleInfo->KinActorData2));
6246 using namespace Chaos;
6249 HandleInfo->KinActorData2->GetGameThreadAPI().SetGeometry(TUniquePtr<FImplicitObject>(
new TSphere<FReal, 3>(TVector<FReal, 3>(0.f), 1000.f)));
6250 HandleInfo->KinActorData2->GetGameThreadAPI().SetObjectState(EObjectStateType::Kinematic);
6251 FPhysicsInterface::AddActorToSolver(HandleInfo->KinActorData2, ActorParams.Scene->GetSolver());
6258 if (!HandleInfo->HandleData2.IsValid())
6264 FTransform TargetTrans(FTransform(NewGrip.RelativeTransform.ToMatrixNoScale().Inverse()) * HandleInfo->RootBoneRotation.Inverse());
6265 HandleInfo->HandleData2 = FPhysicsInterface::CreateConstraint(HandleInfo->KinActorData2,
Actor, FTransform::Identity, TargetTrans);
6269 HandleInfo->HandleData2 = FPhysicsInterface::CreateConstraint(HandleInfo->KinActorData2,
Actor, FTransform::Identity, KinPose.GetRelativeTransform(FPhysicsInterface::GetGlobalPose_AssumesLocked(
Actor)));
6274 bRecreatingConstraint =
true;
6279#if PHYSICS_INTERFACE_PHYSX
6281 if (HandleInfo->HandleData2.IsValid() && HandleInfo->HandleData2.ConstraintData)
6285 HandleInfo->HandleData2.ConstraintData->setActors(FPhysicsInterface_PhysX::GetPxRigidDynamic_AssumesLocked(
Actor), FPhysicsInterface_PhysX::GetPxRigidDynamic_AssumesLocked(HandleInfo->KinActorData2));
6287 FTransform TargetTrans(NewGrip.RelativeTransform.ToMatrixNoScale().Inverse());
6288 FPhysicsInterface::SetLocalPose(HandleInfo->HandleData2, TargetTrans, EConstraintFrame::Frame2);
6292 HandleInfo->HandleData2.ConstraintData->setActors(FPhysicsInterface_PhysX::GetPxRigidDynamic_AssumesLocked(
Actor), FPhysicsInterface_PhysX::GetPxRigidDynamic_AssumesLocked(HandleInfo->KinActorData2));
6293 FPhysicsInterface::SetLocalPose(HandleInfo->HandleData2, KinPose.GetRelativeTransform(FPhysicsInterface::GetGlobalPose_AssumesLocked(
Actor)), EConstraintFrame::Frame2);
6299 FPhysicsInterface::ReleaseConstraint(HandleInfo->HandleData2);
6303 FTransform TargetTrans(NewGrip.RelativeTransform.ToMatrixNoScale().Inverse());
6304 HandleInfo->HandleData2 = FPhysicsInterface::CreateConstraint(HandleInfo->KinActorData2,
Actor, FTransform::Identity, TargetTrans);
6308 HandleInfo->HandleData2 = FPhysicsInterface::CreateConstraint(HandleInfo->KinActorData2,
Actor, FTransform::Identity, KinPose.GetRelativeTransform(FPhysicsInterface::GetGlobalPose_AssumesLocked(
Actor)));
6314 if (HandleInfo->HandleData2.IsValid())
6316 FPhysicsInterface::SetBreakForces_AssumesLocked(HandleInfo->HandleData2, MAX_FLT, MAX_FLT);
6321 FPhysicsInterface::SetLinearMotionLimitType_AssumesLocked(HandleInfo->HandleData2, PhysicsInterfaceTypes::ELimitAxis::X, ELinearConstraintMotion::LCM_Locked);
6322 FPhysicsInterface::SetLinearMotionLimitType_AssumesLocked(HandleInfo->HandleData2, PhysicsInterfaceTypes::ELimitAxis::Y, ELinearConstraintMotion::LCM_Locked);
6323 FPhysicsInterface::SetLinearMotionLimitType_AssumesLocked(HandleInfo->HandleData2, PhysicsInterfaceTypes::ELimitAxis::Z, ELinearConstraintMotion::LCM_Locked);
6324 FPhysicsInterface::SetAngularMotionLimitType_AssumesLocked(HandleInfo->HandleData2, PhysicsInterfaceTypes::ELimitAxis::Twist, EAngularConstraintMotion::ACM_Locked);
6325 FPhysicsInterface::SetAngularMotionLimitType_AssumesLocked(HandleInfo->HandleData2, PhysicsInterfaceTypes::ELimitAxis::Swing1, EAngularConstraintMotion::ACM_Locked);
6326 FPhysicsInterface::SetAngularMotionLimitType_AssumesLocked(HandleInfo->HandleData2, PhysicsInterfaceTypes::ELimitAxis::Swing2, EAngularConstraintMotion::ACM_Locked);
6327 FPhysicsInterface::SetProjectionEnabled_AssumesLocked(HandleInfo->HandleData2,
true, 0.01f, 0.01f);
6331 FPhysicsInterface::SetLinearMotionLimitType_AssumesLocked(HandleInfo->HandleData2, PhysicsInterfaceTypes::ELimitAxis::X, ELinearConstraintMotion::LCM_Free);
6332 FPhysicsInterface::SetLinearMotionLimitType_AssumesLocked(HandleInfo->HandleData2, PhysicsInterfaceTypes::ELimitAxis::Y, ELinearConstraintMotion::LCM_Free);
6333 FPhysicsInterface::SetLinearMotionLimitType_AssumesLocked(HandleInfo->HandleData2, PhysicsInterfaceTypes::ELimitAxis::Z, ELinearConstraintMotion::LCM_Free);
6334 FPhysicsInterface::SetAngularMotionLimitType_AssumesLocked(HandleInfo->HandleData2, PhysicsInterfaceTypes::ELimitAxis::Twist, EAngularConstraintMotion::ACM_Free);
6335 FPhysicsInterface::SetAngularMotionLimitType_AssumesLocked(HandleInfo->HandleData2, PhysicsInterfaceTypes::ELimitAxis::Swing1, EAngularConstraintMotion::ACM_Free);
6336 FPhysicsInterface::SetAngularMotionLimitType_AssumesLocked(HandleInfo->HandleData2, PhysicsInterfaceTypes::ELimitAxis::Swing2, EAngularConstraintMotion::ACM_Free);
6337 FPhysicsInterface::SetProjectionEnabled_AssumesLocked(HandleInfo->HandleData2,
false);
6340 FPhysicsInterface::SetDrivePosition(HandleInfo->HandleData2, FVector::ZeroVector);
6344 float Stiffness = NewGrip.Stiffness;
6345 float Damping = NewGrip.Damping;
6347 float AngularStiffness;
6348 float AngularDamping;
6349 float AngularMaxForce;
6351 if (NewGrip.AdvancedGripSettings.PhysicsSettings.bUsePhysicsSettings && NewGrip.AdvancedGripSettings.PhysicsSettings.bUseCustomAngularValues)
6353 AngularStiffness = NewGrip.AdvancedGripSettings.PhysicsSettings.AngularStiffness;
6354 AngularDamping = NewGrip.AdvancedGripSettings.PhysicsSettings.AngularDamping;
6371 AngularMaxForce = (float)FMath::Clamp<double>((
double)AngularStiffness * (double)NewGrip.AdvancedGripSettings.PhysicsSettings.AngularMaxForceCoefficient, 0, (
double)MAX_FLT);
6372 MaxForce = (float)FMath::Clamp<double>((
double)Stiffness * (double)NewGrip.AdvancedGripSettings.PhysicsSettings.LinearMaxForceCoefficient, 0, (
double)MAX_FLT);
6377 if (!bRecreatingConstraint)
6379 FConstraintDrive NewLinDrive;
6380 NewLinDrive.bEnablePositionDrive =
true;
6381 NewLinDrive.bEnableVelocityDrive =
true;
6382 NewLinDrive.Damping = Damping;
6383 NewLinDrive.Stiffness = Stiffness;
6384 NewLinDrive.MaxForce = MaxForce;
6386 HandleInfo->LinConstraint.bEnablePositionDrive =
true;
6387 HandleInfo->LinConstraint.XDrive = NewLinDrive;
6388 HandleInfo->LinConstraint.YDrive = NewLinDrive;
6389 HandleInfo->LinConstraint.ZDrive = NewLinDrive;
6395 if (!bRecreatingConstraint)
6397 FConstraintDrive NewAngDrive;
6398 NewAngDrive.bEnablePositionDrive =
true;
6399 NewAngDrive.bEnableVelocityDrive =
true;
6400 NewAngDrive.Damping = AngularDamping;
6401 NewAngDrive.Stiffness = AngularStiffness;
6402 NewAngDrive.MaxForce = AngularMaxForce;
6405 HandleInfo->AngConstraint.AngularDriveMode = EAngularDriveMode::TwistAndSwing;
6407 HandleInfo->AngConstraint.TwistDrive = NewAngDrive;
6416 if (Script && Script->IsScriptActive() && Script->InjectPostPhysicsHandle())
6418 Script->HandlePostPhysicsHandle(
this, HandleInfo);
6423 FPhysicsInterface::UpdateLinearDrive_AssumesLocked(HandleInfo->HandleData2, HandleInfo->LinConstraint);
6424 FPhysicsInterface::UpdateAngularDrive_AssumesLocked(HandleInfo->HandleData2, HandleInfo->AngConstraint);
6434 AngularMaxForce = (float)FMath::Clamp<double>((
double)AngularStiffness * (double)NewGrip.AdvancedGripSettings.PhysicsSettings.AngularMaxForceCoefficient, 0, (
double)MAX_FLT);
6435 MaxForce = (float)FMath::Clamp<double>((
double)Stiffness * (double)NewGrip.AdvancedGripSettings.PhysicsSettings.LinearMaxForceCoefficient, 0, (
double)MAX_FLT);
6438 if (!bRecreatingConstraint)
6442 FConstraintDrive NewLinDrive;
6443 NewLinDrive.bEnablePositionDrive =
true;
6444 NewLinDrive.bEnableVelocityDrive =
true;
6445 NewLinDrive.Damping = Damping;
6446 NewLinDrive.Stiffness = Stiffness;
6447 NewLinDrive.MaxForce = MaxForce;
6450 FConstraintDrive NewAngDrive;
6451 NewAngDrive.bEnablePositionDrive =
true;
6452 NewAngDrive.bEnableVelocityDrive =
true;
6453 NewAngDrive.Damping = AngularDamping;
6454 NewAngDrive.Stiffness = AngularStiffness;
6455 NewAngDrive.MaxForce = AngularMaxForce;
6458 HandleInfo->LinConstraint.bEnablePositionDrive =
true;
6459 HandleInfo->LinConstraint.XDrive = NewLinDrive;
6460 HandleInfo->LinConstraint.YDrive = NewLinDrive;
6461 HandleInfo->LinConstraint.ZDrive = NewLinDrive;
6463 HandleInfo->AngConstraint.AngularDriveMode = EAngularDriveMode::SLERP;
6464 HandleInfo->AngConstraint.SlerpDrive = NewAngDrive;
6473 if (Script && Script->IsScriptActive() && Script->InjectPostPhysicsHandle())
6475 Script->HandlePostPhysicsHandle(
this, HandleInfo);
6480 FPhysicsInterface::UpdateLinearDrive_AssumesLocked(HandleInfo->HandleData2, HandleInfo->LinConstraint);
6481 FPhysicsInterface::UpdateAngularDrive_AssumesLocked(HandleInfo->HandleData2, HandleInfo->AngConstraint);
6488#if PHYSICS_INTERFACE_PHYSX
6489 if (bUseForceDrive && HandleInfo->HandleData2.IsValid() && HandleInfo->HandleData2.ConstraintData)
6493 PxD6JointDrive driveVal = HandleInfo->HandleData2.ConstraintData->getDrive(PxD6Drive::Enum::eX);
6494 driveVal.flags = PxD6JointDriveFlags();
6495 HandleInfo->HandleData2.ConstraintData->setDrive(PxD6Drive::Enum::eX, driveVal);
6497 driveVal = HandleInfo->HandleData2.ConstraintData->getDrive(PxD6Drive::Enum::eY);
6498 driveVal.flags = PxD6JointDriveFlags();
6499 HandleInfo->HandleData2.ConstraintData->setDrive(PxD6Drive::Enum::eY, driveVal);
6501 driveVal = HandleInfo->HandleData2.ConstraintData->getDrive(PxD6Drive::Enum::eZ);
6502 driveVal.flags = PxD6JointDriveFlags();
6503 HandleInfo->HandleData2.ConstraintData->setDrive(PxD6Drive::Enum::eZ, driveVal);
6505 driveVal = HandleInfo->HandleData2.ConstraintData->getDrive(PxD6Drive::Enum::eTWIST);
6506 driveVal.flags = PxD6JointDriveFlags();
6507 HandleInfo->HandleData2.ConstraintData->setDrive(PxD6Drive::Enum::eTWIST, driveVal);
6509 driveVal = HandleInfo->HandleData2.ConstraintData->getDrive(PxD6Drive::Enum::eSWING);
6510 driveVal.flags = PxD6JointDriveFlags();
6511 HandleInfo->HandleData2.ConstraintData->setDrive(PxD6Drive::Enum::eTWIST, driveVal);
6513 driveVal = HandleInfo->HandleData2.ConstraintData->getDrive(PxD6Drive::Enum::eSLERP);
6514 driveVal.flags = PxD6JointDriveFlags();
6515 HandleInfo->HandleData2.ConstraintData->setDrive(PxD6Drive::Enum::eSLERP, driveVal);
6519 if (bUseForceDrive && HandleInfo->HandleData2.IsValid() && HandleInfo->HandleData2.Constraint)
6521 if (HandleInfo->HandleData2.IsValid() && HandleInfo->HandleData2.Constraint->IsType(Chaos::EConstraintType::JointConstraintType))
6523 if (Chaos::FJointConstraint* Constraint =
static_cast<Chaos::FJointConstraint*
>(HandleInfo->HandleData2.Constraint))
6525 Constraint->SetLinearDriveForceMode(Chaos::EJointForceMode::Force);
6526 Constraint->SetAngularDriveForceMode(Chaos::EJointForceMode::Force);
6534 HandleInfo->bInitiallySetup =
true;
6537 if (!rBodyInstance->OnRecalculatedMassProperties().IsBoundToObject(
this))
6556 FPhysicsInterface::ExecuteOnUnbrokenConstraintReadWrite(HandleInfo->
HandleData2, [&](
const FPhysicsConstraintHandle& InUnbrokenConstraint)
6558 bool bUseForceDrive = (Grip->AdvancedGripSettings.PhysicsSettings.bUsePhysicsSettings && Grip->AdvancedGripSettings.PhysicsSettings.PhysicsConstraintType == EPhysicsGripConstraintType::ForceConstraint);
6560 float Stiffness = Grip->Stiffness;
6561 float Damping = Grip->Damping;
6563 float AngularStiffness;
6564 float AngularDamping;
6565 float AngularMaxForce;
6567 if (Grip->AdvancedGripSettings.PhysicsSettings.bUsePhysicsSettings && Grip->AdvancedGripSettings.PhysicsSettings.bUseCustomAngularValues)
6569 AngularStiffness = Grip->AdvancedGripSettings.PhysicsSettings.AngularStiffness;
6570 AngularDamping = Grip->AdvancedGripSettings.PhysicsSettings.AngularDamping;
6574 AngularStiffness = Stiffness * ANGULAR_STIFFNESS_MULTIPLIER;
6575 AngularDamping = Damping * ANGULAR_DAMPING_MULTIPLIER;
6605#if PHYSICS_INTERFACE_PHYSX
6608 PxD6JointDrive driveVal = HandleInfo->
HandleData2.ConstraintData->getDrive(PxD6Drive::Enum::eX);
6609 driveVal.flags &= ~PxD6JointDriveFlag::eACCELERATION;
6610 HandleInfo->
HandleData2.ConstraintData->setDrive(PxD6Drive::Enum::eX, driveVal);
6612 driveVal = HandleInfo->
HandleData2.ConstraintData->getDrive(PxD6Drive::Enum::eY);
6613 driveVal.flags &= ~PxD6JointDriveFlag::eACCELERATION;
6614 HandleInfo->
HandleData2.ConstraintData->setDrive(PxD6Drive::Enum::eY, driveVal);
6616 driveVal = HandleInfo->
HandleData2.ConstraintData->getDrive(PxD6Drive::Enum::eZ);
6617 driveVal.flags &= ~PxD6JointDriveFlag::eACCELERATION;
6618 HandleInfo->
HandleData2.ConstraintData->setDrive(PxD6Drive::Enum::eZ, driveVal);
6623 if (HandleInfo->
HandleData2.IsValid() && HandleInfo->
HandleData2.Constraint->IsType(Chaos::EConstraintType::JointConstraintType))
6625 if (Chaos::FJointConstraint* Constraint =
static_cast<Chaos::FJointConstraint*
>(HandleInfo->
HandleData2.Constraint))
6627 Constraint->SetLinearDriveForceMode(Chaos::EJointForceMode::Force);
6628 Constraint->SetAngularDriveForceMode(Chaos::EJointForceMode::Force);
6636 HandleInfo->
AngConstraint.TwistDrive.Damping = AngularDamping;
6637 HandleInfo->
AngConstraint.TwistDrive.Stiffness = AngularStiffness;
6638 HandleInfo->
AngConstraint.TwistDrive.MaxForce = AngularMaxForce;
6642#if PHYSICS_INTERFACE_PHYSX
6645 PxD6JointDrive driveVal = HandleInfo->
HandleData2.ConstraintData->getDrive(PxD6Drive::Enum::eTWIST);
6646 driveVal.flags &= ~PxD6JointDriveFlag::eACCELERATION;
6647 HandleInfo->
HandleData2.ConstraintData->setDrive(PxD6Drive::Enum::eTWIST, driveVal);
6652 FPhysicsInterface::SetDrivePosition(HandleInfo->
HandleData2, FVector::ZeroVector);
6653 FPhysicsInterface::SetDriveOrientation(HandleInfo->
HandleData2, FQuat::Identity);
6680#if PHYSICS_INTERFACE_PHYSX
6683 PxD6JointDrive driveVal = HandleInfo->
HandleData2.ConstraintData->getDrive(PxD6Drive::Enum::eX);
6684 driveVal.flags &= ~PxD6JointDriveFlag::eACCELERATION;
6685 HandleInfo->
HandleData2.ConstraintData->setDrive(PxD6Drive::Enum::eX, driveVal);
6687 driveVal = HandleInfo->
HandleData2.ConstraintData->getDrive(PxD6Drive::Enum::eY);
6688 driveVal.flags &= ~PxD6JointDriveFlag::eACCELERATION;
6689 HandleInfo->
HandleData2.ConstraintData->setDrive(PxD6Drive::Enum::eY, driveVal);
6691 driveVal = HandleInfo->
HandleData2.ConstraintData->getDrive(PxD6Drive::Enum::eZ);
6692 driveVal.flags &= ~PxD6JointDriveFlag::eACCELERATION;
6693 HandleInfo->
HandleData2.ConstraintData->setDrive(PxD6Drive::Enum::eZ, driveVal);
6698 if (HandleInfo->
HandleData2.IsValid() && HandleInfo->
HandleData2.Constraint->IsType(Chaos::EConstraintType::JointConstraintType))
6700 if (Chaos::FJointConstraint* Constraint =
static_cast<Chaos::FJointConstraint*
>(HandleInfo->
HandleData2.Constraint))
6702 Constraint->SetLinearDriveForceMode(Chaos::EJointForceMode::Force);
6709 HandleInfo->
AngConstraint.SlerpDrive.Damping = AngularDamping;
6710 HandleInfo->
AngConstraint.SlerpDrive.Stiffness = AngularStiffness;
6711 HandleInfo->
AngConstraint.SlerpDrive.MaxForce = AngularMaxForce;
6714#if PHYSICS_INTERFACE_PHYSX
6717 PxD6JointDrive driveVal = HandleInfo->
HandleData2.ConstraintData->getDrive(PxD6Drive::Enum::eTWIST);
6718 driveVal.flags &= ~PxD6JointDriveFlag::eACCELERATION;
6719 HandleInfo->
HandleData2.ConstraintData->setDrive(PxD6Drive::Enum::eTWIST, driveVal);
6721 driveVal = HandleInfo->
HandleData2.ConstraintData->getDrive(PxD6Drive::Enum::eSWING);
6722 driveVal.flags &= ~PxD6JointDriveFlag::eACCELERATION;
6723 HandleInfo->
HandleData2.ConstraintData->setDrive(PxD6Drive::Enum::eSWING, driveVal);
6725 driveVal = HandleInfo->
HandleData2.ConstraintData->getDrive(PxD6Drive::Enum::eSLERP);
6726 driveVal.flags &= ~PxD6JointDriveFlag::eACCELERATION;
6727 HandleInfo->
HandleData2.ConstraintData->setDrive(PxD6Drive::Enum::eSLERP, driveVal);
6732 if (HandleInfo->
HandleData2.IsValid() && HandleInfo->
HandleData2.Constraint->IsType(Chaos::EConstraintType::JointConstraintType))
6734 if (Chaos::FJointConstraint* Constraint =
static_cast<Chaos::FJointConstraint*
>(HandleInfo->
HandleData2.Constraint))
6736 Constraint->SetAngularDriveForceMode(Chaos::EJointForceMode::Force);
6759 if (!HandleInfo || !FPhysicsInterface::IsValid(HandleInfo->
KinActorData2))
6775 FTransform tran3 = FTransform::Identity;
6777 FBodyInstance* rBodyInstance = rootComp->GetBodyInstance(GrippedActor.
GrippedBoneName);
6779 if (bUseComLoc && rBodyInstance && rBodyInstance->IsValidBodyInstance())
6781 tran3 = FTransform(rBodyInstance->GetCOMPosition());
6786 tran3 = FPhysicsInterface::GetLocalPose(HandleInfo->
HandleData2, EConstraintFrame::Frame2);
6788 if (!rBodyInstance || !rBodyInstance->IsValidBodyInstance())
6790 rr = rootComp->GetComponentTransform();
6792 rr.SetScale3D(FVector(1, 1, 1));
6795 rr = rBodyInstance->GetUnrealWorldTransform();
6802 FTransform kinPose = FTransform::Identity;
6803 FPhysicsCommand::ExecuteRead(HandleInfo->
KinActorData2, [&](
const FPhysicsActorHandle &
Actor)
6805 kinPose = FPhysicsInterface::GetGlobalPose_AssumesLocked(Actor);
6809 LocOut = FTransform::SubtractTranslations(kinPose, tran3);
6819 if (!NewTransform.IsValid())
6821 UE_LOG(LogVRMotionController,
Warning, TEXT(
"Something went wrong, UpdatePhysicsHandeTransforms target transform contained NAN!."));
6827 if (!HandleInfo || !FPhysicsInterface::IsValid(HandleInfo->
KinActorData2))
6830#if PHYSICS_INTERFACE_PHYSX
6846 FPhysicsActorHandle ActorHandle = HandleInfo->
KinActorData2;
6848 FPhysicsCommand::ExecuteWrite(ActorHandle, [&](
const FPhysicsActorHandle &
Actor)
6850 FPhysicsInterface::SetKinematicTarget_AssumesLocked(
Actor, newTrans);
6855#if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
6859 FVector curCOMPosition = me->GetBodyInstance(GrippedActor.
GrippedBoneName)->GetCOMPosition();
6860 DrawDebugSphere(GetWorld(), curCOMPosition, 4, 32, FColor::Red,
false);
6862 DrawDebugSphere(GetWorld(), TargetTransform.GetLocation(), 4, 32, FColor::Cyan,
false);
6863 DrawDebugLine(GetWorld(), TargetTransform.GetTranslation(), TargetTransform.GetTranslation() + (TargetTransform.GetRotation().GetForwardVector() * 20.f), FColor::Red);
6864 DrawDebugLine(GetWorld(), TargetTransform.GetTranslation(), TargetTransform.GetTranslation() + (TargetTransform.GetRotation().GetRightVector() * 20.f), FColor::Green);
6865 DrawDebugLine(GetWorld(), TargetTransform.GetTranslation(), TargetTransform.GetTranslation() + (TargetTransform.GetRotation().GetUpVector() * 20.f), FColor::Blue);
6871static void PullBackHitComp(FHitResult& Hit,
const FVector& Start,
const FVector& End,
const float Dist)
6873 const float DesiredTimeBack = FMath::Clamp(0.1f, 0.1f / Dist, 1.f / Dist) + 0.001f;
6874 Hit.Time = FMath::Clamp(Hit.Time - DesiredTimeBack, 0.f, 1.f);
6879 TArray<FHitResult> Hits;
6881 FHitResult BlockingHit(NoInit);
6882 BlockingHit.bBlockingHit =
false;
6883 BlockingHit.Time = 1.f;
6884 bool bFilledHitResult =
false;
6885 bool bMoved =
false;
6886 bool bIncludesOverlapsAtEnd =
false;
6887 bool bRotationOnly =
false;
6889 UPrimitiveComponent *root = ComponentToCheck;
6891 if (!root || !root->IsQueryCollisionEnabled())
6894 FVector start(root->GetComponentLocation());
6896 const bool bCollisionEnabled = root->IsQueryCollisionEnabled();
6898 if (bCollisionEnabled)
6900#if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
6901 if (!root->IsRegistered())
6903 UE_LOG(LogVRMotionController,
Warning, TEXT(
"MovedComponent %s not initialized in grip motion controller"), *root->GetFullName());
6907 UWorld*
const MyWorld = GetWorld();
6908 FComponentQueryParams Params(TEXT(
"sweep_params"), root->GetOwner());
6910 FCollisionResponseParams ResponseParam;
6911 root->InitSweepCollisionParams(Params, ResponseParam);
6913 FVector end = start + Move;
6914 bool const bHadBlockingHit = MyWorld->ComponentSweepMulti(Hits, root, start, end, newOrientation.Quaternion(), Params);
6918 const float DeltaSize = FVector::Dist(start, end);
6919 for (int32 HitIdx = 0; HitIdx < Hits.Num(); HitIdx++)
6925 if (bHadBlockingHit)
6927 int32 BlockingHitIndex = INDEX_NONE;
6928 float BlockingHitNormalDotDelta = BIG_NUMBER;
6929 for (int32 HitIdx = 0; HitIdx < Hits.Num(); HitIdx++)
6931 const FHitResult& TestHit = Hits[HitIdx];
6934 if (TestHit.Actor == this->GetOwner() || (bSkipSimulatingComponents && TestHit.Component->IsSimulatingPhysics()))
6936 if (Hits.Num() == 1)
6945 if (TestHit.bBlockingHit && TestHit.IsValidBlockingHit())
6947 if (TestHit.Time == 0.f)
6950 const float NormalDotDelta = (TestHit.ImpactNormal | Move);
6951 if (NormalDotDelta < BlockingHitNormalDotDelta)
6953 BlockingHitNormalDotDelta = NormalDotDelta;
6954 BlockingHitIndex = HitIdx;
6957 else if (BlockingHitIndex == INDEX_NONE)
6961 BlockingHitIndex = HitIdx;
6969 if (BlockingHitIndex >= 0)
6971 BlockingHit = Hits[BlockingHitIndex];
6972 bFilledHitResult =
true;
6978 if (BlockingHit.bBlockingHit && !root->IsPendingKill())
6980 check(bFilledHitResult);
6981 if (root->IsDeferringMovementUpdates())
6984 ScopedUpdate->AppendBlockingHitAfterMove(BlockingHit);
6989 if(root->GetOwner())
6990 root->DispatchBlockingHit(*root->GetOwner(), BlockingHit);
7013 OriginalPosition.Z = FMath::Max(OriginalPosition.Z,
MinimumHeight);
7018 OriginalPosition.Z = FMath::Min(OriginalPosition.Z,
MaximumHeight);
7023 if (bIsInGameThread)
7025 if (
IsLocallyControlled() && GEngine->XRSystem.IsValid() && GEngine->XRSystem->IsHeadTrackingAllowedForWorld(*GetWorld()))
7029 if (GEngine->XRSystem->GetCurrentPose(IXRTrackingSystem::HMDDeviceId, curRot, curLoc))
7034 AttachChar->VRReplicatedCamera->ApplyTrackingParameters(curLoc);
7058 OriginalPosition -= FVector(CorrectLastLocation.X, CorrectLastLocation.Y, 0.0f);
7063 FVector DifferenceVec =
bOffsetByHMD ? OriginalPosition : (OriginalPosition - CorrectLastLocation);
7065 if (DifferenceVec.SizeSquared() > FMath::Square(
LeashRange))
7067 OriginalPosition = CorrectLastLocation + (DifferenceVec.GetSafeNormal() *
LeashRange);
7078 bool bIsInGameThread = IsInGameThread();
7083 TArray<IMotionController*> MotionControllers = IModularFeatures::Get().GetModularFeatureImplementations<IMotionController>(IMotionController::GetModularFeatureName());
7084 for (
auto MotionController : MotionControllers)
7086 if (MotionController ==
nullptr)
7092 if (bIsInGameThread)
7094 CurrentTrackingStatus = MotionController->GetControllerTrackingStatus(PlayerIndex, MotionSource);
7100 if (MotionController->GetControllerOrientationAndPosition(PlayerIndex, MotionSource, Orientation, Position, WorldToMetersScale))
7104 if (bIsInGameThread)
7106 CurrentTrackingStatus = MotionController->GetControllerTrackingStatus(PlayerIndex, MotionSource);
7119 FTransform FinalControllerTransform(Orientation,Position);
7120 if (bIsInGameThread)
7129 Orientation = FinalControllerTransform.Rotator();
7130 Position = FinalControllerTransform.GetTranslation();
7134 if (bIsInGameThread)
7136 InUseMotionController = MotionController;
7137 OnMotionControllerUpdated();
7138 InUseMotionController =
nullptr;
7144 else if (bIsInGameThread)
7146 CurrentTrackingStatus = MotionController->GetControllerTrackingStatus(PlayerIndex, MotionSource);
7153 if (MotionSource == FXRMotionControllerBase::HMDSourceId)
7155 IXRTrackingSystem* TrackingSys = GEngine->XRSystem.Get();
7158 FQuat OrientationQuat = FQuat::Identity;
7159 if (TrackingSys->GetCurrentPose(IXRTrackingSystem::HMDDeviceId, OrientationQuat, Position))
7161 Orientation = OrientationQuat.Rotator();
7173 , MotionControllerComponent(InMotionControllerComponent)
7175 FSceneViewExtensionIsActiveFunctor IsActiveFunc;
7176 IsActiveFunc.IsActiveFunction = [
this](
const ISceneViewExtension* SceneViewExtension,
const FSceneViewExtensionContext& Context)
7178 check(IsInGameThread());
7180 static const auto CVarEnableMotionControllerLateUpdate = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT(
"vr.EnableMotionControllerLateUpdate"));
7184 IsActiveThisFrameFunctions.Add(IsActiveFunc);
7190 FTransform OldTransform;
7191 FTransform NewTransform;
7194 FScopeLock ScopeLock(&CritSect);
7196 if (!MotionControllerComponent)
7200 float WorldToMetersScale = -1.0f;
7201 for (
const FSceneView* SceneView : InViewFamily.Views)
7203 if (SceneView && SceneView->PlayerIndex == MotionControllerComponent->PlayerIndex)
7205 WorldToMetersScale = SceneView->WorldToMetersScale;
7211 if (WorldToMetersScale < 0.0f)
7213 check(InViewFamily.Views.Num() > 0);
7214 WorldToMetersScale = InViewFamily.Views[0]->WorldToMetersScale;
7218 FVector Position = MotionControllerComponent->LateUpdateParams.GripRenderThreadRelativeTransform.GetTranslation();
7219 FRotator Orientation = MotionControllerComponent->LateUpdateParams.GripRenderThreadRelativeTransform.GetRotation().Rotator();
7221 if (!MotionControllerComponent->GripPollControllerState(Position, Orientation, WorldToMetersScale))
7226 if (MotionControllerComponent->LateUpdateParams.bRenderSmoothHandTracking)
7228 FTransform CalcedTransform = FTransform(Orientation, Position, MotionControllerComponent->LateUpdateParams.GripRenderThreadComponentScale);
7230 if (MotionControllerComponent->LateUpdateParams.bRenderSmoothWithEuroLowPassFunction)
7232 CalcedTransform = MotionControllerComponent->LateUpdateParams.RenderEuroSmoothingParams.RunFilterSmoothing(CalcedTransform, MotionControllerComponent->LateUpdateParams.RenderLastDeltaTime);
7237 if (MotionControllerComponent->LateUpdateParams.RenderSmoothingSpeed <= 0.f || MotionControllerComponent->LateUpdateParams.RenderLastSmoothRelativeTransform.Equals(FTransform::Identity))
7243 const float Alpha = FMath::Clamp(MotionControllerComponent->LateUpdateParams.RenderLastDeltaTime * MotionControllerComponent->LateUpdateParams.RenderSmoothingSpeed, 0.f, 1.f);
7244 MotionControllerComponent->LateUpdateParams.RenderLastSmoothRelativeTransform.Blend(MotionControllerComponent->LateUpdateParams.RenderLastSmoothRelativeTransform, CalcedTransform, Alpha);
7245 CalcedTransform = MotionControllerComponent->LateUpdateParams.RenderLastSmoothRelativeTransform;
7251 NewTransform = CalcedTransform;
7255 NewTransform = FTransform(Orientation, Position, MotionControllerComponent->LateUpdateParams.GripRenderThreadComponentScale);
7258 OldTransform = MotionControllerComponent->LateUpdateParams.GripRenderThreadRelativeTransform;
7260 MotionControllerComponent->LateUpdateParams.GripRenderThreadRelativeTransform = NewTransform;
7264 LateUpdate.Apply_RenderThread(InViewFamily.Scene, InViewFamily.bLateLatchingEnabled ? InViewFamily.FrameNumber : -1, OldTransform, NewTransform);
7269 SCOPED_NAMED_EVENT(UMotionControllerComponent_Latch, FColor::Orange);
7270 if (!MotionControllerComponent)
7275 FTransform OldTransform;
7276 FTransform NewTransform;
7278 FScopeLock ScopeLock(&CritSect);
7279 if (!MotionControllerComponent)
7285 float WorldToMetersScale = -1.0f;
7286 for (
const FSceneView* SceneView : InViewFamily.Views)
7288 if (SceneView && SceneView->PlayerIndex == MotionControllerComponent->PlayerIndex)
7290 WorldToMetersScale = SceneView->WorldToMetersScale;
7295 if (WorldToMetersScale < 0.0f)
7297 check(InViewFamily.Views.Num() > 0);
7298 WorldToMetersScale = InViewFamily.Views[0]->WorldToMetersScale;
7303 FRotator Orientation;
7305 if (!MotionControllerComponent->GripPollControllerState(Position, Orientation, WorldToMetersScale))
7310 if (MotionControllerComponent->LateUpdateParams.bRenderSmoothHandTracking)
7312 FTransform CalcedTransform = FTransform(Orientation, Position, MotionControllerComponent->LateUpdateParams.GripRenderThreadComponentScale);
7314 if (MotionControllerComponent->LateUpdateParams.bRenderSmoothWithEuroLowPassFunction)
7316 CalcedTransform = MotionControllerComponent->LateUpdateParams.RenderEuroSmoothingParams.RunFilterSmoothing(CalcedTransform, MotionControllerComponent->LateUpdateParams.RenderLastDeltaTime);
7321 if (MotionControllerComponent->LateUpdateParams.RenderSmoothingSpeed <= 0.f || MotionControllerComponent->LateUpdateParams.RenderLastSmoothRelativeTransform.Equals(FTransform::Identity))
7327 const float Alpha = FMath::Clamp(MotionControllerComponent->LateUpdateParams.RenderLastDeltaTime * MotionControllerComponent->LateUpdateParams.RenderSmoothingSpeed, 0.f, 1.f);
7328 MotionControllerComponent->LateUpdateParams.RenderLastSmoothRelativeTransform.Blend(MotionControllerComponent->LateUpdateParams.RenderLastSmoothRelativeTransform, CalcedTransform, Alpha);
7329 CalcedTransform = MotionControllerComponent->LateUpdateParams.RenderLastSmoothRelativeTransform;
7335 NewTransform = CalcedTransform;
7339 NewTransform = FTransform(Orientation, Position, MotionControllerComponent->LateUpdateParams.GripRenderThreadComponentScale);
7342 OldTransform = MotionControllerComponent->LateUpdateParams.GripRenderThreadRelativeTransform;
7344 MotionControllerComponent->LateUpdateParams.GripRenderThreadRelativeTransform = NewTransform;
7349 LateUpdate.Apply_RenderThread(InViewFamily.Scene, InViewFamily.FrameNumber, OldTransform, NewTransform);
7358 FirstActiveGrip = *FirstGrip;
7369 if (Grip.IsValid() && !Grip.bIsPaused)
7377 if (LocalGrip.IsValid() && !LocalGrip.bIsPaused)
7429 GrippedComponentsArray.Add(
GrippedObjects[i].GetGrippedComponent());
7440void UGripMotionControllerComponent::Client_NotifyInvalidLocalGrip_Implementation(
UObject * LocallyGrippedObject, uint8 GripID,
bool bWasAGripConflict)
7448 if (LocallyGrippedObject && bWasAGripConflict)
7467 if (LocallyGrippedObject && bWasAGripConflict)
7473bool UGripMotionControllerComponent::Server_NotifyHandledTransaction_Validate(uint8 GripID)
7478void UGripMotionControllerComponent::Server_NotifyHandledTransaction_Implementation(uint8 GripID)
7487bool UGripMotionControllerComponent::Server_NotifyLocalGripAddedOrChanged_Validate(
const FBPActorGripInformation & newGrip)
7492void UGripMotionControllerComponent::Server_NotifyLocalGripAddedOrChanged_Implementation(
const FBPActorGripInformation & newGrip)
7502 bool bImplementsInterface = newGrip.
GrippedObject->GetClass()->ImplementsInterface(UVRGripInterface::StaticClass());
7504 TArray<FBPGripPair> HoldingControllers;
7505 bool bIsHeld =
false;
7506 if (bImplementsInterface)
7508 IVRGripInterface::Execute_IsHeld(newGrip.
GrippedObject, HoldingControllers, bIsHeld);
7513 if (!IVRGripInterface::Execute_AllowsMultipleGrips(newGrip.
GrippedObject))
7524 if (GripPair.HoldingController->GetOwner()->GetNetOwner() != this->GetOwner()->GetNetOwner())
7539 GripPair.HoldingController->DropObjectByInterface(newGrip.
GrippedObject, GripPair.GripID);
7540 GripPair.HoldingController->Client_NotifyInvalidLocalGrip(newGrip.
GrippedObject, GripPair.GripID,
true);
7548 GripPair.HoldingController->DropObjectByInterface(newGrip.
GrippedObject, GripPair.GripID);
7549 GripPair.HoldingController->Client_NotifyInvalidLocalGrip(newGrip.
GrippedObject, GripPair.GripID,
true);
7566 UPrimitiveComponent* PrimComp =
nullptr;
7567 AActor* pActor =
nullptr;
7572 if (!PrimComp && pActor)
7574 PrimComp = Cast<UPrimitiveComponent>(pActor->GetRootComponent());
7576 else if (!pActor && PrimComp)
7578 pActor = PrimComp->GetOwner();
7581 if (!PrimComp || !pActor)
7587 bool bHadOriginalSettings =
false;
7588 bool bOriginalGravity =
false;
7589 bool bOriginalReplication =
false;
7591 if (bImplementsInterface)
7598 if (HoldingControllers.Num() > 0 && HoldingControllers[0].HoldingController !=
nullptr)
7600 FBPActorGripInformation* gripInfo = HoldingControllers[0].HoldingController->GetGripPtrByID(HoldingControllers[0].GripID);
7602 if (gripInfo !=
nullptr)
7604 bHadOriginalSettings =
true;
7616 if (bHadOriginalSettings)
7635 int32 IndexFound = INDEX_NONE;
7649bool UGripMotionControllerComponent::Server_NotifyLocalGripRemoved_Validate(uint8 GripID,
const FTransform_NetQuantize &TransformAtDrop, FVector_NetQuantize100 AngularVelocity, FVector_NetQuantize100 LinearVelocity)
7654void UGripMotionControllerComponent::Server_NotifyLocalGripRemoved_Implementation(uint8 GripID,
const FTransform_NetQuantize &TransformAtDrop, FVector_NetQuantize100 AngularVelocity, FVector_NetQuantize100 LinearVelocity)
7671 if (!DroppingActor->IsPendingKill() && TransformAtDrop.IsValid())
7673 DroppingActor->SetActorTransform(TransformAtDrop,
false,
nullptr, ETeleportType::TeleportPhysics);
7681 if (!DroppingComp->IsPendingKill() && TransformAtDrop.IsValid())
7683 DroppingComp->SetWorldTransform(TransformAtDrop,
false,
nullptr, ETeleportType::TeleportPhysics);
7698bool UGripMotionControllerComponent::Server_NotifySecondaryAttachmentChanged_Validate(
7705void UGripMotionControllerComponent::Server_NotifySecondaryAttachmentChanged_Implementation(
7711 if (GripInfo !=
nullptr)
7724bool UGripMotionControllerComponent::Server_NotifySecondaryAttachmentChanged_Retain_Validate(
7731void UGripMotionControllerComponent::Server_NotifySecondaryAttachmentChanged_Retain_Implementation(
7737 if (GripInfo !=
nullptr)
7752 EControllerHand ControllerHandIndex;
7753 if (!FXRMotionControllerBase::GetHandEnumForSourceName(MotionSource, ControllerHandIndex))
7759 TArray<IXRSystemAssets*> XRAssetSystems = IModularFeatures::Get().GetModularFeatureImplementations<IXRSystemAssets>(IXRSystemAssets::GetModularFeatureName());
7760 for (IXRSystemAssets* AssetSys : XRAssetSystems)
7762 if (bCheckOpenVROnly && !AssetSys->GetSystemName().IsEqual(
FName(TEXT(
"SteamVR"))))
7765 const int32 XRID = AssetSys->GetDeviceId(ControllerHandIndex);
7767 if (XRID != INDEX_NONE)
7769 DeviceID = FXRDeviceId(AssetSys, XRID);
7775 DeviceID = FXRDeviceId();
7788 : LateUpdateGameWriteIndex(0)
7789 , LateUpdateRenderReadIndex(0)
7798 check(IsInGameThread());
7824 ENQUEUE_RENDER_COMMAND(UpdateLateUpdateRenderReadIndexCommand)(
7825 [NextFrameRenderReadIndex,
this](FRHICommandListImmediate& RHICmdList)
7834 check(IsInRenderingThread());
7844 const FMatrix LateUpdateTransform = (OldCameraTransform.Inverse() * NewCameraTransform).ToMatrixWithScale();
7846 bool bIndicesHaveChanged =
false;
7854 for (
auto& PrimitivePair : PrimitivesLocal)
7856 if (PrimitivePair.Value == -1)
7859 FPrimitiveSceneInfo* RetrievedSceneInfo = Scene->GetPrimitiveSceneInfo(PrimitivePair.Value);
7860 FPrimitiveSceneInfo* CachedSceneInfo = PrimitivePair.Key;
7864 if (CachedSceneInfo != RetrievedSceneInfo)
7866 bIndicesHaveChanged =
true;
7869 else if (CachedSceneInfo->Proxy)
7871 CachedSceneInfo->Proxy->ApplyLateUpdateTransform(LateUpdateTransform);
7872 PrimitivePair.Value = -1;
7873 if (FrameNumber >= 0)
7875 CachedSceneInfo->Proxy->SetPatchingFrameNumber(FrameNumber);
7881 if (bIndicesHaveChanged)
7884 FPrimitiveSceneInfo* RetrievedSceneInfo = Scene->GetPrimitiveSceneInfo(Index++);
7885 while (RetrievedSceneInfo)
7888 int32* PrimitiveIndex = PrimitivesLocal.Find(RetrievedSceneInfo);
7889 if (RetrievedSceneInfo->Proxy && PrimitiveIndex !=
nullptr && *PrimitiveIndex >= 0)
7891 RetrievedSceneInfo->Proxy->ApplyLateUpdateTransform(LateUpdateTransform);
7892 if (FrameNumber >= 0)
7894 RetrievedSceneInfo->Proxy->SetPatchingFrameNumber(FrameNumber);
7897 RetrievedSceneInfo = Scene->GetPrimitiveSceneInfo(Index++);
7904 ensureMsgf(!Component->IsUsingAbsoluteLocation() && !Component->IsUsingAbsoluteRotation(), TEXT(
"SceneComponents that use absolute location or rotation are not supported by the LateUpdateManager"));
7906 UPrimitiveComponent* PrimitiveComponent =
dynamic_cast<UPrimitiveComponent*
>(Component);
7907 if (PrimitiveComponent && PrimitiveComponent->SceneProxy)
7909 FPrimitiveSceneInfo* PrimitiveSceneInfo = PrimitiveComponent->SceneProxy->GetPrimitiveSceneInfo();
7910 if (PrimitiveSceneInfo && PrimitiveSceneInfo->IsIndexValid())
7920 TArray<USceneComponent*> DirectComponents;
7923 ParentComponent->GetChildrenComponents(
true, DirectComponents);
7926 if (Component !=
nullptr)
7953 if (actor.bIsPaused)
7956 switch (actor.GripLateUpdateSetting)
7970 if (actor.SecondaryGripInfo.bHasSecondaryAttachment)
7977 (actor.SecondaryGripInfo.bHasSecondaryAttachment)
7989 if (actor.GrippedObject->GetClass()->ImplementsInterface(UVRGripInterface::StaticClass()))
7991 TArray<UVRGripScriptBase*> GripScripts;
7992 if (IVRGripInterface::Execute_GetGripScripts(actor.GrippedObject, GripScripts))
7994 bool bContinueOn =
false;
7997 if (Script && Script->IsScriptActive() && Script->Wants_DenyLateUpdates())
8010 switch (actor.GripTargetType)
8015 AActor * pActor = actor.GetGrippedActor();
8029 UPrimitiveComponent * cPrimComp = actor.GetGrippedComponent();
8041 if (!FXRMotionControllerBase::GetHandEnumForSourceName(MotionSource, Hand))
8043 Hand = EControllerHand::Left;
8070 return InTransform.GetRelativeTransform(GrippedActorTransform);
8091 if (!ComponentToCheck)
8101 if (!ComponentToCheck)
8152 PhysicsHandleSettingsOut.
FillFrom(HandleInfo);
8163 PhysicsHandleSettingsIn.
FillTo(HandleInfo);
8178 UPrimitiveComponent * RootComp =
nullptr;
8182 RootComp = Cast<UPrimitiveComponent>(Grip.
GetGrippedActor()->GetRootComponent());
8190 FVector CheckDistance;
8193 CheckDistance = (ExpectedLocation - RootComp->GetComponentLocation());
8197 CurrentDistance = CheckDistance.Size();
DECLARE_CYCLE_STAT(TEXT("TickGrip ~ TickingGrip"), STAT_TickGrip, STATGROUP_TickGrip)
static void PullBackHitComp(FHitResult &Hit, const FVector &Start, const FVector &End, const float Dist)
const float ANGULAR_DAMPING_MULTIPLIER
const float ANGULAR_STIFFNESS_MULTIPLIER
DEFINE_LOG_CATEGORY(LogVRMotionController)
const float HYBRID_PHYSICS_GRIP_MULTIPLIER
EGripMovementReplicationSettings
UENUM(Blueprintable)
@ ForceClientSideMovement
@ ClientSide_Authoritive_NoRep
@ ForceServerSideMovement
ESecondaryGripType
UENUM(Blueprintable)
@ SG_FreeWithScaling_Retain
@ SG_SlotOnlyWithScaling_Retain
EGripCollisionType
UENUM(Blueprintable)
@ InteractiveHybridCollisionWithPhysics
@ ManipulationGripWithWristTwist
@ InteractiveHybridCollisionWithSweep
@ InteractiveCollisionWithSweep
@ InteractiveCollisionWithPhysics
@ VRLOCITY_RunningAverage
#define INVALID_VRGRIP_ID
EGripLateUpdateSettings
UENUM(Blueprintable)
@ NotWhenCollidingOrDoubleGripping
@ VRGRIP_CONFLICT_DropAll
EGripInterfaceTeleportBehavior
UENUM(Blueprintable)
@ OnlyTeleportRootComponent
EPhysicsGripCOMType
UENUM(Blueprintable)
@ COM_GripAtControllerLoc
@ OverridesWorldTransform
int32 LateUpdateRenderReadIndex
void CacheSceneInfo(USceneComponent *Component)
void GatherLateUpdatePrimitives(USceneComponent *ParentComponent)
int32 LateUpdateGameWriteIndex
void Apply_RenderThread(FSceneInterface *Scene, const int32 FrameNumber, const FTransform &OldRelativeTransform, const FTransform &NewRelativeTransform)
void Setup(const FTransform &ParentToWorld, UGripMotionControllerComponent *Component, bool bSkipLateUpdate)
void ProcessGripArrayLateUpdatePrimitives(UGripMotionControllerComponent *MotionController, TArray< FBPActorGripInformation > &GripArray)
FExpandedLateUpdateManager()
FLateUpdateState UpdateStates[2]
bool AreComponentsIgnoringCollisions(UPrimitiveComponent *Prim1, UPrimitiveComponent *Prim2)
bool HasCollisionIgnorePairs()
UGripMotionControllerComponent * MotionControllerComponent
FExpandedLateUpdateManager LateUpdate
virtual void PreRenderViewFamily_RenderThread(FRHICommandListImmediate &RHICmdList, FSceneViewFamily &InViewFamily) override
FGripViewExtension(const FAutoRegister &AutoRegister, UGripMotionControllerComponent *InMotionControllerComponent)
virtual void LateLatchingViewFamily_RenderThread(FRHICommandListImmediate &RHICmdList, FSceneViewFamily &InViewFamily) override
virtual void BeginRenderViewFamily(FSceneViewFamily &InViewFamily) override
UCLASS(Blueprintable, meta = (BlueprintSpawnableComponent), ClassGroup = MotionController)
bool UpdatePhysicsHandle(uint8 GripID, bool bFullyRecreate=true)
bool GetGripDistance_BP(UPARAM(ref) FBPActorGripInformation &Grip, FVector ExpectedLocation, float &CurrentDistance)
UFUNCTION(BlueprintCallable, Category = "GripMotionController|Custom", meta = (DisplayName = "GetGrip...
void Server_NotifySecondaryAttachmentChanged_Retain(uint8 GripID, const FBPSecondaryGripInfo &SecondaryGripInfo, const FTransform_NetQuantize &NewRelativeTransform)
UFUNCTION(Reliable, Server, WithValidation)
void SetSocketTransform(UObject *ObjectToSocket, const FTransform_NetQuantize RelativeTransformToParent)
UFUNCTION()
bool bSmoothHandTracking
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "GripMotionController|Smoothing")
FTransform CreateGripRelativeAdditionTransform_BP(const FBPActorGripInformation &GripToSample, const FTransform &AdditionTransform, bool bGripRelative=false)
UFUNCTION(BlueprintPure, Category = "GripMotionController", meta = (DisplayName = "CreateGripRelative...
void Drop_Implementation(const FBPActorGripInformation &NewDrop, bool bSimulate)
bool UpdatePhysicsHandle_BP(UPARAM(ref) const FBPActorGripInformation &Grip, bool bFullyRecreate=true)
UFUNCTION(BlueprintCallable, Category = "GripMotionController|Custom", meta = (DisplayName = "UpdateP...
bool DropAndSocketGrip(const FBPActorGripInformation &GripToDrop, USceneComponent *SocketingParent, FName OptionalSocketName, const FTransform_NetQuantize &RelativeTransformToParent, bool bWeldBodies=true)
UFUNCTION(BlueprintCallable, Category = "GripMotionController")
FBPVRComponentPosRep ReplicatedControllerTransform
UPROPERTY(EditDefaultsOnly, ReplicatedUsing = OnRep_ReplicatedControllerTransform,...
TArray< FBPActorPhysicsHandleInformation > PhysicsGrips
float SmoothingSpeed
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "GripMotionController|Smoothing")
virtual void BeginDestroy() override
void NotifyDrop(const FBPActorGripInformation &NewDrop, bool bSimulate)
UFUNCTION(Reliable, NetMulticast)
TArray< UObject * > ObjectsWaitingForSocketUpdate
UPROPERTY()
bool GripObject(UObject *ObjectToGrip, const FTransform &WorldOffset, bool bWorldOffsetIsRelative=false, FName OptionalSnapToSocketName=NAME_None, FName OptionalBoneToGripName=NAME_None, EGripCollisionType GripCollisionType=EGripCollisionType::InteractiveCollisionWithPhysics, EGripLateUpdateSettings GripLateUpdateSetting=EGripLateUpdateSettings::NotWhenCollidingOrDoubleGripping, EGripMovementReplicationSettings GripMovementReplicationSetting=EGripMovementReplicationSettings::ForceClientSideMovement, float GripStiffness=1500.0f, float GripDamping=200.0f, bool bIsSlotGrip=false)
UFUNCTION(BlueprintCallable, Category = "GripMotionController")
FDelegateHandle NewControllerProfileEvent_Handle
FTransform CreateGripRelativeAdditionTransform(const FBPActorGripInformation &GripToSample, const FTransform &AdditionTransform, bool bGripRelative=false)
void NewControllerProfileLoaded()
UFUNCTION()
bool HandleGripReplication(FBPActorGripInformation &Grip, FBPActorGripInformation *OldGripInfo=nullptr)
bool bSmoothReplicatedMotion
UPROPERTY(EditAnywhere, BlueprintReadWrite, Replicated, Category = "GripMotionController|Networking")
bool DropAndSocketGrip_Implementation(const FBPActorGripInformation &GripToDrop, USceneComponent *SocketingParent, FName OptionalSocketName, const FTransform_NetQuantize &RelativeTransformToParent, bool bWeldBodies=true, bool bSkipServerNotify=false)
float InterpolationSpeed
UPROPERTY(EditAnywhere, Category = "GripMotionController|Networking|Smoothing", meta = (editcondition...
void PostTeleportMoveGrippedObjects()
UFUNCTION(BlueprintCallable, Category = "GripMotionController")
bool bAlwaysSendTickGrip
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "GripMotionController")
bool bLimitMinHeight
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "GripMotionController|Advanced|Tracking")
void GetGripMass(const FBPActorGripInformation &Grip, float &Mass)
UFUNCTION(BlueprintPure, Category = "GripMotionController")
FVector LastUpdatesRelativePosition
void ApplyTrackingParameters(FVector &OriginalPosition, bool bIsInGameThread)
bool bReplicateWithoutTracking
UPROPERTY(EditAnywhere, BlueprintReadWrite, Replicated, Category = "GripMotionController|Networking")
void UpdatePhysicsHandleTransform_BP(UPARAM(ref) const FBPActorGripInformation &GrippedActor, UPARAM(ref) const FTransform &NewTransform)
UFUNCTION(BlueprintCallable, Category = "GripMotionController|Custom", meta = (DisplayName = "UpdateP...
bool bOffsetByControllerProfile
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "GripMotionController")
FBPEuroLowPassFilterTrans EuroSmoothingParams
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "GripMotionController|Smoothing")
bool SetGripConstraintStiffnessAndDamping(const FBPActorGripInformation *Grip, bool bUseHybridMultiplier=false)
void CancelGlobalLerpToHand(uint8 GripID)
UFUNCTION(BlueprintCallable, Category = "GripMotionController")
bool GetPhysicsJointLength(const FBPActorGripInformation &GrippedActor, UPrimitiveComponent *rootComp, FVector &LocOut)
void NotifyGripTransformChanged(const FBPActorGripInformation &GripInfo)
bool bSmoothWithEuroLowPassFunction
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "GripMotionController|Smoothing")
virtual void InitializeComponent() override
bool AddSecondaryAttachmentPoint(UObject *GrippedObjectToAddAttachment, USceneComponent *SecondaryPointComponent, const FTransform &OriginalTransform, bool bTransformIsAlreadyRelative=false, float LerpToTime=0.25f, bool bIsSlotGrip=false, FName SecondarySlotName=NAME_None)
UFUNCTION(BlueprintCallable, Category = "GripMotionController")
bool RemoveSecondaryAttachmentFromGrip(const FBPActorGripInformation &GripToRemoveAttachment, float LerpToTime=0.25f)
UFUNCTION(BlueprintCallable, Category = "GripMotionController")
FTransform ConvertToControllerRelativeTransform(const FTransform &InTransform)
UFUNCTION(BlueprintPure, Category = "GripMotionController")
TWeakObjectPtr< AVRBaseCharacter > AttachChar
UPROPERTY()
bool bScaleTracking
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "GripMotionController|Advanced|Tracking")
bool HasGrippedObjects()
UFUNCTION(BlueprintPure, Category = "GripMotionController")
TArray< FBPActorGripInformation > LocalTransactionBuffer
UPROPERTY(BlueprintReadOnly, Replicated, Category = "GripMotionController", ReplicatedUsing = OnRep_L...
virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override
bool K2_GetFirstActiveGrip(FBPActorGripInformation &FirstActiveGrip)
UFUNCTION(BlueprintCallable, meta = (Keywords = "Grip", DisplayName = "GetFirstActiveGrip",...
bool HasGripAuthority(const FBPActorGripInformation &Grip)
void DropAndSocket_Implementation(const FBPActorGripInformation &NewDrop)
bool DestroyPhysicsHandle(const FBPActorGripInformation &Grip, bool bSkipUnregistering=false)
bool bSkipPivotTransformAdjustment
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "GripMotionController|CustomPivot")
UGripMotionControllerComponent(const FObjectInitializer &ObjectInitializer)
virtual void OnAttachmentChanged() override
void NotifyDropAndSocket(const FBPActorGripInformation &NewDrop, USceneComponent *SocketingParent, FName OptionalSocketName, const FTransform_NetQuantize &RelativeTransformToParent, bool bWeldBodies=true)
UFUNCTION(Reliable, NetMulticast)
FVROnControllerTeleportedGripsSignature OnTeleportedGrips
UPROPERTY(BlueprintAssignable, Category = "Grip Events")
void EndPhysicsTickComponent(FGripComponentEndPhysicsTickFunction &ThisTickFunction)
virtual void SendRenderTransform_Concurrent() override
FORCEINLINE FVector GetPivotLocation()
bool DropComponent(UPrimitiveComponent *ComponentToDrop, bool bSimulate, FVector OptionalAngularVelocity=FVector::ZeroVector, FVector OptionalLinearVelocity=FVector::ZeroVector)
UFUNCTION(BlueprintCallable, Category = "GripMotionController")
float ControllerNetUpdateCount
FVector LastLocationForLateUpdate
void TickGrip(float DeltaTime)
void SetGripLateUpdateSetting(const FBPActorGripInformation &Grip, EBPVRResultSwitch &Result, EGripLateUpdateSettings NewGripLateUpdateSetting=EGripLateUpdateSettings::NotWhenCollidingOrDoubleGripping)
UFUNCTION(BlueprintCallable, Category = "GripMotionController", meta = (ExpandEnumAsExecs = "Result")...
void InitializeLerpToHand(FBPActorGripInformation &GripInfo)
void GetGripByObject(FBPActorGripInformation &Grip, UObject *ObjectToLookForGrip, EBPVRResultSwitch &Result)
UFUNCTION(BlueprintCallable, Category = "GripMotionController", meta = (ExpandEnumAsExecs = "Result")...
void Server_SendControllerTransform(FBPVRComponentPosRep NewTransform)
UFUNCTION(Unreliable, Server, WithValidation)
float NetworkMaxSmoothUpdateDistance
UPROPERTY(EditAnywhere, Category = "GripMotionController|Networking|Smoothing", meta = (editcondition...
void Server_NotifyLocalGripRemoved(uint8 GripID, const FTransform_NetQuantize &TransformAtDrop, FVector_NetQuantize100 AngularVelocity, FVector_NetQuantize100 LinearVelocity)
UFUNCTION(Reliable, Server, WithValidation)
bool GetIsSecondaryAttachment(const USceneComponent *ComponentToCheck, FBPActorGripInformation &Grip)
UFUNCTION(BlueprintCallable, Category = "GripMotionController")
void RegisterEndPhysicsTick(bool bRegister)
FVector GetPivotLocation_BP()
UFUNCTION(BlueprintPure, Category = "GripMotionController", meta = (DisplayName = "GetPivotLocation")...
void GetControllerDeviceID(FXRDeviceId &DeviceID, EBPVRResultSwitch &Result, bool bCheckOpenVROnly=false)
UFUNCTION(BlueprintCallable, Category = "GripMotionController", meta = (ExpandEnumAsExecs = "Result")...
void Socket_Implementation(UObject *ObjectToSocket, bool bWasSimulating, USceneComponent *SocketingParent, FName OptionalSocketName, const FTransform_NetQuantize &RelativeTransformToParent, bool bWeldBodies=true)
TArray< uint8 > SecondaryGripIDs
bool IsLocallyControlled() const
bool RemoveSecondaryAttachmentFromGripByID(const uint8 GripID=0, float LerpToTime=0.25f)
UFUNCTION(BlueprintCallable, Category = "GripMotionController")
void GetGrippedActors(TArray< AActor * > &GrippedActorArray)
UFUNCTION(BlueprintCallable, Category = "GripMotionController")
FBPActorPhysicsHandleInformation * GetPhysicsGrip(const FBPActorGripInformation &GripInfo)
bool TeleportMoveGrip_Impl(FBPActorGripInformation &Grip, bool bTeleportPhysicsGrips, bool bIsForPostTeleport, FTransform &OptionalTransform)
bool SetUpPhysicsHandle(const FBPActorGripInformation &NewGrip, TArray< UVRGripScriptBase * > *GripScripts=nullptr)
void SetGripStiffnessAndDamping(const FBPActorGripInformation &Grip, EBPVRResultSwitch &Result, float NewStiffness, float NewDamping, bool bAlsoSetAngularValues=false, float OptionalAngularStiffness=0.0f, float OptionalAngularDamping=0.0f)
UFUNCTION(BlueprintCallable, Category = "GripMotionController", meta = (ExpandEnumAsExecs = "Result")...
bool DestroyPhysicsHandle_BP(UPARAM(ref) const FBPActorGripInformation &Grip)
UFUNCTION(BlueprintCallable, Category = "GripMotionController|Custom", meta = (DisplayName = "Destroy...
void Server_NotifyLocalGripAddedOrChanged(const FBPActorGripInformation &newGrip)
UFUNCTION(Reliable, Server, WithValidation, Category = "GripMotionController")
bool NotifyGrip(FBPActorGripInformation &NewGrip, bool bIsReInit=false)
virtual bool GripPollControllerState(FVector &Position, FRotator &Orientation, float WorldToMetersScale)
FVROnControllerDropSignature OnDroppedObject
UPROPERTY(BlueprintAssignable, Category = "Grip Events")
void GetCurrentProfileTransform(bool bBindToNoticationDelegate)
void Client_NotifyInvalidLocalGrip(UObject *LocallyGrippedObject, uint8 GripID, bool bWasAGripConflict=false)
UFUNCTION(Reliable, Client, Category = "GripMotionController")
virtual void CreateRenderState_Concurrent(FRegisterComponentContext *Context) override
bool bUseWithoutTracking
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "GripMotionController")
FVROnControllerGripSignature OnLerpToHandFinished
UPROPERTY(BlueprintAssignable, Category = "Grip Events")
bool DropAndSocketObject(const FTransform_NetQuantize &RelativeTransformToParent, UObject *ObjectToDrop=nullptr, uint8 GripIDToDrop=0, USceneComponent *SocketingParent=nullptr, FName OptionalSocketName=NAME_None, bool bWeldBodies=true)
UFUNCTION(BlueprintCallable, Category = "GripMotionController")
TArray< FBPActorGripInformation > GrippedObjects
UPROPERTY(BlueprintReadOnly, Replicated, Category = "GripMotionController", ReplicatedUsing = OnRep_G...
void GetAllGrips(TArray< FBPActorGripInformation > &GripArray)
UFUNCTION(BlueprintCallable, Category = "GripMotionController")
TSubclassOf< class UVRGripScriptBase > DefaultGripScriptClass
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "GripMotionController|Advanced")
UVRGripScriptBase * DefaultGripScript
UPROPERTY(VisibleAnywhere, Transient, BlueprintReadOnly, Category = "GripMotionController|Advanced")
~UGripMotionControllerComponent()
FVROnControllerGripSignature OnSecondaryGripRemoved
UPROPERTY(BlueprintAssignable, Category = "Grip Events")
void HandleGlobalLerpToHand(FBPActorGripInformation &GripInformation, FTransform &WorldTransform, float DeltaTime)
float ControllerNetUpdateRate
UPROPERTY(EditAnywhere, BlueprintReadWrite, Replicated, Category = "GripMotionController|Networking",...
FBPActorGripInformation * GetGripPtrByID(uint8 IDToLookForGrip)
bool GripObjectByInterface(UObject *ObjectToGrip, const FTransform &WorldOffset, bool bWorldOffsetIsRelative=false, FName OptionalBoneToGripName=NAME_None, FName OptionalSnapToSocketName=NAME_None, bool bIsSlotGrip=false)
UFUNCTION(BlueprintCallable, Category = "GripMotionController")
bool GripComponent(UPrimitiveComponent *ComponentToGrip, const FTransform &WorldOffset, bool bWorldOffsetIsRelative=false, FName OptionalsnapToSocketName=NAME_None, FName OptionalBoneToGripName=NAME_None, EGripCollisionType GripCollisionType=EGripCollisionType::InteractiveCollisionWithPhysics, EGripLateUpdateSettings GripLateUpdateSetting=EGripLateUpdateSettings::NotWhenCollidingOrDoubleGripping, EGripMovementReplicationSettings GripMovementReplicationSetting=EGripMovementReplicationSettings::ForceClientSideMovement, float GripStiffness=1500.0f, float GripDamping=200.0f, bool bIsSlotGrip=false)
UFUNCTION(BlueprintCallable, Category = "GripMotionController")
bool DropGrip_Implementation(const FBPActorGripInformation &Grip, bool bSimulate=false, FVector OptionalAngularVelocity=FVector::ZeroVector, FVector OptionalLinearVelocity=FVector::ZeroVector, bool bSkipNotify=false)
bool CheckComponentWithSweep(UPrimitiveComponent *ComponentToCheck, FVector Move, FRotator newOrientation, bool bSkipSimulatingComponents)
void CleanUpBadGrip(TArray< FBPActorGripInformation > &GrippedObjectsArray, int GripIndex, bool bReplicatedArray)
FRotator LastUpdatesRelativeRotation
void GetGripByID(FBPActorGripInformation &Grip, uint8 IDToLookForGrip, EBPVRResultSwitch &Result)
UFUNCTION(BlueprintCallable, Category = "GripMotionController", meta = (ExpandEnumAsExecs = "Result")...
bool TeleportMoveGrippedActor(AActor *GrippedActorToMove, bool bTeleportPhysicsGrips=true)
UFUNCTION(BlueprintCallable, Category = "GripMotionController")
bool AddSecondaryAttachmentToGripByID(const uint8 GripID, USceneComponent *SecondaryPointComponent, const FTransform &OriginalTransform, bool bTransformIsAlreadyRelative=false, float LerpToTime=0.25f, bool bIsSlotGrip=false, FName SecondarySlotName=NAME_None)
UFUNCTION(BlueprintCallable, Category = "GripMotionController")
bool bOffsetByHMD
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "GripMotionController|Advanced|Tracking")
FVRGripControllerOnTrackingEventSignature OnTrackingChanged
UPROPERTY(BlueprintAssignable, Category = "GripMotionController")
void SetCustomPivotComponent(USceneComponent *NewCustomPivotComponent, FName PivotSocketName=NAME_None)
UFUNCTION(BlueprintCallable, Category = "GripMotionController|CustomPivot")
void SetPausedTransform(const FBPActorGripInformation &Grip, const FTransform &PausedTransform, bool bTeleport=false)
UFUNCTION(BlueprintCallable, Category = "GripMotionController")
float MinimumHeight
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "GripMotionController|Advanced|Tracking",...
bool bIgnoreTrackingStatus
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "GripMotionController")
void GetGripByComponent(FBPActorGripInformation &Grip, UPrimitiveComponent *ComponentToLookForGrip, EBPVRResultSwitch &Result)
UFUNCTION(BlueprintCallable, Category = "GripMotionController", meta = (ExpandEnumAsExecs = "Result")...
void GetGripByActor(FBPActorGripInformation &Grip, AActor *ActorToLookForGrip, EBPVRResultSwitch &Result)
UFUNCTION(BlueprintCallable, Category = "GripMotionController", meta = (ExpandEnumAsExecs = "Result")...
void GetGrippedObjects(TArray< UObject * > &GrippedObjectsArray)
UFUNCTION(BlueprintCallable, Category = "GripMotionController")
virtual FVector GetComponentVelocity() const override
FVRGripControllerOnGripOutOfRange OnGripOutOfRange
UPROPERTY(BlueprintAssignable, Category = "GripMotionController")
bool BP_HasGripMovementAuthority(const FBPActorGripInformation &Grip)
UFUNCTION(BlueprintPure, Category = "GripMotionController", meta = (DisplayName = "HasGripMovementAut...
FVector TrackingScaler
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "GripMotionController|Advanced|Tracking",...
void TeleportMoveGrips(bool bTeleportPhysicsGrips=true, bool bIsForPostTeleport=false)
UFUNCTION(BlueprintCallable, Category = "GripMotionController")
bool GetPhysicsConstraintForce(const FBPActorGripInformation &Grip, FVector &AngularForce, FVector &LinearForce)
UFUNCTION(BlueprintCallable, Category = "GripMotionController")
float NetworkNoSmoothUpdateDistance
UPROPERTY(EditAnywhere, Category = "GripMotionController|Networking|Smoothing", meta = (editcondition...
void SetGripAdditionTransform(const FBPActorGripInformation &Grip, EBPVRResultSwitch &Result, const FTransform &NewAdditionTransform, bool bMakeGripRelative=false)
UFUNCTION(BlueprintCallable, Category = "GripMotionController", meta = (ExpandEnumAsExecs = "Result")...
bool bLeashToHMD
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "GripMotionController|Advanced|Tracking")
void ReCreateGrip(FBPActorGripInformation &GripInfo)
bool HasTrackingParameters()
void Server_NotifySecondaryAttachmentChanged(uint8 GripID, const FBPSecondaryGripInfo &SecondaryGripInfo)
UFUNCTION(Reliable, Server, WithValidation)
void GetPhysicsVelocities(const FBPActorGripInformation &Grip, FVector &AngularVelocity, FVector &LinearVelocity)
UFUNCTION(BlueprintPure, Category = "GripMotionController")
FTransform LastRelativePosition
void SetGripCollisionType(const FBPActorGripInformation &Grip, EBPVRResultSwitch &Result, EGripCollisionType NewGripCollisionType=EGripCollisionType::InteractiveCollisionWithPhysics)
UFUNCTION(BlueprintCallable, Category = "GripMotionController", meta = (ExpandEnumAsExecs = "Result")...
bool bConstrainToPivot
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "GripMotionController|Advanced")
TWeakObjectPtr< USceneComponent > CustomPivotComponent
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "GripMotionController|CustomPivot")
bool GripControllerIsTracked() const
UFUNCTION(BlueprintPure, Category = "GripMotionController")
EVRClientAuthConflictResolutionMode ClientAuthConflictResolutionMethod
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "GripMotionController|ClientAuth")
void OnGripMassUpdated(FBodyInstance *GripBodyInstance)
VRBaseCharTransformRPC_Pointer OverrideSendTransform
void RunNetworkedSmoothing(float DeltaTime)
bool RemoveSecondaryAttachmentPoint(UObject *GrippedObjectToRemoveAttachment, float LerpToTime=0.25f)
UFUNCTION(BlueprintCallable, Category = "GripMotionController")
virtual void OnUnregister() override
bool GetIsComponentHeld(const UPrimitiveComponent *ComponentToCheck)
UFUNCTION(BlueprintPure, Category = "GripMotionController")
FVRGripControllerOnProfileTransformChanged OnControllerProfileTransformChanged
UPROPERTY(BlueprintAssignable, Category = "GripMotionController")
virtual void Deactivate() override
bool DropObjectByInterface(UObject *ObjectToDrop=nullptr, uint8 GripIDToDrop=0, FVector OptionalAngularVelocity=FVector::ZeroVector, FVector OptionalLinearVelocity=FVector::ZeroVector)
UFUNCTION(BlueprintCallable, Category = "GripMotionController")
TSharedPtr< FGripViewExtension, ESPMode::ThreadSafe > GripViewExtension
bool DropObject(UObject *ObjectToDrop=nullptr, uint8 GripIdToDrop=0, bool bSimulate=false, FVector OptionalAngularVelocity=FVector::ZeroVector, FVector OptionalLinearVelocity=FVector::ZeroVector)
UFUNCTION(BlueprintCallable, Category = "GripMotionController")
FTransform CurrentControllerProfileTransform
bool bProjectNonSimulatingGrips
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "GripMotionController|Advanced")
static FTransform ConvertToGripRelativeTransform(const FTransform &GrippedActorTransform, const FTransform &InTransform)
UFUNCTION(BlueprintPure, Category = "GripMotionController")
uint8 GetNextGripID(bool bIsLocalGrip)
FBPLowPassPeakFilter PeakFilter
float MaximumHeight
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "GripMotionController|Advanced|Tracking",...
FVROnControllerSocketSignature OnSocketingObject
UPROPERTY(BlueprintAssignable, Category = "Grip Events")
FVROnClientAuthGripConflict OnClientAuthGripConflict
UPROPERTY(BlueprintAssignable, Category = "Grip Events")
void SetGripPaused(const FBPActorGripInformation &Grip, EBPVRResultSwitch &Result, bool bIsPaused=false, bool bNoConstraintWhenPaused=false)
UFUNCTION(BlueprintCallable, Category = "GripMotionController", meta = (ExpandEnumAsExecs = "Result")...
FTransform LastSmoothRelativeTransform
FGripComponentEndPhysicsTickFunction EndPhysicsTickFunction
struct UGripMotionControllerComponent::FRenderTrackingParams LateUpdateParams
FVROnControllerGripSignature OnSecondaryGripAdded
UPROPERTY(BlueprintAssignable, Category = "Grip Events")
bool bUseExponentialSmoothing
UPROPERTY(EditAnywhere, Category = "GripMotionController|Networking|Smoothing", meta = (editcondition...
bool HasGripMovementAuthority(const FBPActorGripInformation &Grip)
FName CustomPivotComponentSocketName
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "GripMotionController|CustomPivot")
bool PausePhysicsHandle(FBPActorPhysicsHandleInformation *HandleInfo)
void UpdateTracking(float DeltaTime)
void CleanUpBadPhysicsHandles()
void GetHandType(EControllerHand &Hand)
UFUNCTION(BlueprintPure, Category = "VRExpansionFunctions", meta = (bIgnoreSelf = "true",...
void CheckTransactionBuffer()
TArray< UPrimitiveComponent * > AdditionalLateUpdateComponents
UPROPERTY(BlueprintReadWrite, Category = "GripMotionController")
void SetGripRelativeTransform(const FBPActorGripInformation &Grip, EBPVRResultSwitch &Result, const FTransform &NewRelativeTransform)
UFUNCTION(BlueprintCallable, Category = "GripMotionController", meta = (ExpandEnumAsExecs = "Result")...
bool GetPhysicsGripIndex(const FBPActorGripInformation &GripInfo, int &index)
TArray< FBPActorGripInformation > LocallyGrippedObjects
UPROPERTY(BlueprintReadOnly, Replicated, Category = "GripMotionController", ReplicatedUsing = OnRep_L...
EVRVelocityType VelocityCalculationType
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "GripMotionController|ComponentVelocity")
void Server_NotifyDropAndSocketGrip(uint8 GripID, USceneComponent *SocketingParent, FName OptionalSocketName, const FTransform_NetQuantize &RelativeTransformToParent, bool bWeldBodies=true)
UFUNCTION(Reliable, Server, WithValidation, Category = "GripMotionController")
int32 VelocitySamples
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "GripMotionController|ComponentVelocity")
bool BP_HasGripAuthority(const FBPActorGripInformation &Grip)
UFUNCTION(BlueprintPure, Category = "GripMotionController", meta = (DisplayName = "HasGripAuthority")...
FORCEINLINE FTransform GetPivotTransform()
FTransform GetPivotTransform_BP()
UFUNCTION(BlueprintPure, Category = "GripMotionController", meta = (DisplayName = "GetPivotTransform"...
bool BP_IsLocallyControlled()
UFUNCTION(BlueprintPure, Category = "GripMotionController", meta = (DisplayName = "IsLocallyControlle...
bool GripActor(AActor *ActorToGrip, const FTransform &WorldOffset, bool bWorldOffsetIsRelative=false, FName OptionalSnapToSocketName=NAME_None, FName OptionalBoneToGripName=NAME_None, EGripCollisionType GripCollisionType=EGripCollisionType::InteractiveCollisionWithPhysics, EGripLateUpdateSettings GripLateUpdateSetting=EGripLateUpdateSettings::NotWhenCollidingOrDoubleGripping, EGripMovementReplicationSettings GripMovementReplicationSetting=EGripMovementReplicationSettings::ForceClientSideMovement, float GripStiffness=1500.0f, float GripDamping=200.0f, bool bIsSlotGrip=false)
UFUNCTION(BlueprintCallable, Category = "GripMotionController")
void HandleGripArray(TArray< FBPActorGripInformation > &GrippedObjectsArray, const FTransform &ParentTransform, float DeltaTime, bool bReplicatedArray=false)
bool DropActor(AActor *ActorToDrop, bool bSimulate, FVector OptionalAngularVelocity=FVector::ZeroVector, FVector OptionalLinearVelocity=FVector::ZeroVector)
UFUNCTION(BlueprintCallable, Category = "GripMotionController")
void UpdatePhysicsHandleTransform(const FBPActorGripInformation &GrippedActor, const FTransform &NewTransform)
void GetGrippedComponents(TArray< UPrimitiveComponent * > &GrippedComponentsArray)
UFUNCTION(BlueprintCallable, Category = "GripMotionController")
bool bLimitMaxHeight
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "GripMotionController|Advanced|Tracking")
bool bSampleVelocityInWorldSpace
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "GripMotionController|ComponentVelocity")
float LeashRange
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "GripMotionController|Advanced|Tracking",...
bool TeleportMoveGrippedComponent(UPrimitiveComponent *ComponentToMove, bool bTeleportPhysicsGrips=true)
UFUNCTION(BlueprintCallable, Category = "GripMotionController")
bool GetGripWorldTransform(TArray< UVRGripScriptBase * > &GripScripts, float DeltaTime, FTransform &WorldTransform, const FTransform &ParentTransform, FBPActorGripInformation &Grip, AActor *actor, UPrimitiveComponent *root, bool bRootHasInterface, bool bActorHasInterface, bool bIsForTeleport, bool &bForceADrop)
bool GetPhysicsHandleSettings(UPARAM(ref) const FBPActorGripInformation &Grip, FBPAdvancedPhysicsHandleSettings &PhysicsHandleSettingsOut)
UFUNCTION(BlueprintCallable, Category = "GripMotionController|Custom", meta = (DisplayName = "GetPhys...
bool GetIsHeld(const AActor *ActorToCheck)
UFUNCTION(BlueprintPure, Category = "GripMotionController")
void TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction) override
bool BP_HasGripAuthorityForObject(const UObject *ObjToCheck)
UFUNCTION(BlueprintPure, Category = "GripMotionController", meta = (DisplayName = "HasGripAuthorityFo...
virtual void OnRep_ReplicatedControllerTransform()
UFUNCTION()
virtual void BeginPlay() override
bool UnPausePhysicsHandle(FBPActorGripInformation &GripInfo, FBPActorPhysicsHandleInformation *HandleInfo)
FBPActorGripInformation * GetFirstActiveGrip()
bool DropGrip(const FBPActorGripInformation &Grip, bool bSimulate=false, FVector OptionalAngularVelocity=FVector::ZeroVector, FVector OptionalLinearVelocity=FVector::ZeroVector)
UFUNCTION(BlueprintCallable, Category = "GripMotionController")
bool SetPhysicsHandleSettings(UPARAM(ref) const FBPActorGripInformation &Grip, UPARAM(ref) const FBPAdvancedPhysicsHandleSettings &PhysicsHandleSettingsIn)
UFUNCTION(BlueprintCallable, Category = "GripMotionController|Custom", meta = (DisplayName = "SetPhys...
void SetGripHybridLock(const FBPActorGripInformation &Grip, EBPVRResultSwitch &Result, bool bIsLocked=false)
UFUNCTION(BlueprintCallable, Category = "GripMotionController", meta = (ExpandEnumAsExecs = "Result")...
bool GetIsObjectHeld(const UObject *ObjectToCheck)
UFUNCTION(BlueprintPure, Category = "GripMotionController")
bool SetUpPhysicsHandle_BP(UPARAM(ref) const FBPActorGripInformation &Grip)
UFUNCTION(BlueprintCallable, Category = "GripMotionController|Custom", meta = (DisplayName = "SetUpPh...
bool TeleportMoveGrip(UPARAM(ref) FBPActorGripInformation &Grip, bool bTeleportPhysicsGrips=true, bool bIsForPostTeleport=false)
UFUNCTION(BlueprintCallable, Category = "GripMotionController")
FVROnControllerGripSignature OnGrippedObject
UPROPERTY(BlueprintAssignable, Category = "Grip Events")
FBPActorPhysicsHandleInformation * CreatePhysicsGrip(const FBPActorGripInformation &GripInfo)
bool AddSecondaryAttachmentToGrip(const FBPActorGripInformation &GripToAddAttachment, USceneComponent *SecondaryPointComponent, const FTransform &OriginalTransform, bool bTransformIsAlreadyRelative=false, float LerpToTime=0.25f, bool bIsSlotGrip=false, FName SecondarySlotName=NAME_None)
UFUNCTION(BlueprintCallable, Category = "GripMotionController")
static void UpdatePeakLowPassFilter(UPARAM(ref) FBPLowPassPeakFilter &TargetPeakFilter, FVector NewSample)
UFUNCTION(BlueprintCallable, Category = "LowPassFilter_Peak")
static void LowPassFilter_RollingAverage(FVector lastAverage, FVector newSample, FVector &newAverage, int32 numSamples=10)
UFUNCTION(BlueprintPure, Category = "VRExpansionFunctions", meta = (bIgnoreSelf = "true",...
UCLASS(config = Engine, defaultconfig)
bool bUseSeperateHandTransforms
float LinearDriveDampingScale
UPROPERTY(config, BlueprintReadWrite, EditAnywhere, Category = "ChaosPhysics")
bool bHybridWithSweepUseDistanceBasedLerp
UPROPERTY(config, BlueprintReadWrite, EditAnywhere, Category = "HybridWithSweepLerp")
float LerpDuration
UPROPERTY(config, BlueprintReadWrite, EditAnywhere, Category = "GlobalLerpToHand")
float AngularDriveDampingScale
UPROPERTY(config, BlueprintReadWrite, EditAnywhere, Category = "ChaosPhysics")
FVRControllerProfileChangedEvent OnControllerProfileChangedEvent
float HybridWithSweepLerpDuration
UPROPERTY(config, BlueprintReadWrite, EditAnywhere, Category = "HybridWithSweepLerp")
bool bLerpHybridWithSweepGrips
UPROPERTY(config, BlueprintReadWrite, EditAnywhere, Category = "HybridWithSweepLerp")
float MaxSpeedForLerp
UPROPERTY(config, BlueprintReadWrite, EditAnywhere, Category = "GlobalLerpToHand")
float MinSpeedForLerp
UPROPERTY(config, BlueprintReadWrite, EditAnywhere, Category = "GlobalLerpToHand")
FRuntimeFloatCurve OptionalCurveToFollow
UPROPERTY(config, Category = "GlobalLerpToHand|Curve", EditAnywhere, meta = (editcondition = "bUseCur...
FTransform CurrentControllerProfileTransform
float MinDistanceForLerp
UPROPERTY(config, BlueprintReadWrite, EditAnywhere, Category = "GlobalLerpToHand")
EVRLerpInterpolationMode LerpInterpolationMode
UPROPERTY(config, BlueprintReadWrite, EditAnywhere, Category = "GlobalLerpToHand")
float AngularDriveStiffnessScale
UPROPERTY(config, BlueprintReadWrite, EditAnywhere, Category = "ChaosPhysics")
bool bUseGlobalLerpToHand
UPROPERTY(config, BlueprintReadWrite, EditAnywhere, Category = "GlobalLerpToHand")
bool bOnlyLerpHybridRotation
UPROPERTY(config, BlueprintReadWrite, EditAnywhere, Category = "HybridWithSweepLerp")
float LinearDriveStiffnessScale
UPROPERTY(config, BlueprintReadWrite, EditAnywhere, Category = "ChaosPhysics")
bool bUseCurve
UPROPERTY(config, BlueprintReadWrite, EditAnywhere, Category = "GlobalLerpToHand|Curve")
bool bSkipLerpToHandIfHeld
UPROPERTY(config, BlueprintReadWrite, EditAnywhere, Category = "GlobalLerpToHand")
FTransform CurrentControllerProfileTransformRight
UCLASS(NotBlueprintable, BlueprintType, EditInlineNew, DefaultToInstanced, Abstract,...
FORCEINLINE bool Wants_ToForceDrop()
virtual bool CallCorrect_GetWorldTransform(UGripMotionControllerComponent *OwningController, float DeltaTime, FTransform &WorldTransform, const FTransform &ParentTransform, FBPActorGripInformation &Grip, AActor *actor, UPrimitiveComponent *root, bool bRootHasInterface, bool bActorHasInterface, bool bIsForTeleport)
static UVRGripScriptBase * GetGripScriptByClass(UObject *WorldContextObject, TSubclassOf< UVRGripScriptBase > GripScriptClass, EBPVRResultSwitch &Result)
UFUNCTION(BlueprintCallable, Category = "VRGripScript|Functions", meta = (WorldContext = "WorldContex...
static int32 DrawDebugGripCOM
FAutoConsoleVariableRef CVarDrawCOMDebugSpheres(TEXT("vr.DrawDebugCenterOfMassForGrips"), DrawDebugGripCOM, TEXT("0: Disable, 1: Enable"), ECVF_Default)
FCriticalSection CritSect
EPhysicsGripCOMType PhysicsGripLocationSettings
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "PhysicsSettings", meta = (editcondition = "bU...
bool bUsePhysicsSettings
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "PhysicsSettings")
bool bTurnOffGravityDuringGrip
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "PhysicsSettings", meta = (editcondition = "bU...
bool bSkipSettingSimulating
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "PhysicsSettings", meta = (editcondition = "bU...
float LinearMaxForceCoefficient
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "PhysicsSettings", meta = (editcondition = "bU...
float AngularMaxForceCoefficient
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "PhysicsSettings", meta = (editcondition = "bU...
USTRUCT(BlueprintType, Category = "VRExpansionLibrary")
bool bSetOwnerOnGrip
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "AdvancedGripSettings")
FBPAdvGripPhysicsSettings PhysicsSettings
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "AdvancedGripSettings")
bool bDisallowLerping
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "AdvancedGripSettings")
USTRUCT(BlueprintType, Category = "VRExpansionLibrary")
bool FillFrom(FBPActorPhysicsHandleInformation *HandleInfo)
bool FillTo(FBPActorPhysicsHandleInformation *HandleInfo) const
float CutoffSlope
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "FilterSettings")
void ResetSmoothingFilter()
FTransform RunFilterSmoothing(const FTransform &InRawValue, const float &InDeltaTime)
float MinCutoff
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "FilterSettings")
float DeltaCutoff
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "FilterSettings")
USTRUCT(BlueprintType, Category = "VRExpansionLibrary")
int32 VelocitySamples
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Samples")
USTRUCT(BlueprintType, Category = "VRExpansionLibrary")
USceneComponent * SecondaryAttachment
UPROPERTY(BlueprintReadOnly, Category = "SecondaryGripInfo")
FName SecondarySlotName
UPROPERTY(BlueprintReadWrite, Category = "SecondaryGripInfo")
EGripLerpState GripLerpState
float LerpToRate
UPROPERTY()
float SecondaryGripDistance
UPROPERTY(BlueprintReadOnly, NotReplicated, Category = "SecondaryGripInfo")
FORCEINLINE FBPSecondaryGripInfo & RepCopy(const FBPSecondaryGripInfo &Other)
bool bIsSlotGrip
UPROPERTY(BlueprintReadWrite, Category = "SecondaryGripInfo")
bool bHasSecondaryAttachment
UPROPERTY(BlueprintReadOnly, Category = "SecondaryGripInfo")
FTransform_NetQuantize SecondaryRelativeTransform
UPROPERTY(BlueprintReadOnly, Category = "SecondaryGripInfo")
FVector Position
UPROPERTY(Transient)
FRotator Rotation
UPROPERTY(Transient)
TMap< FPrimitiveSceneInfo *, int32 > Primitives
UGripMotionControllerComponent * Target
virtual FString DiagnosticMessage() override
virtual void ExecuteTick(float DeltaTime, enum ELevelTick TickType, ENamedThreads::Type CurrentThread, const FGraphEventRef &MyCompletionGraphEvent) override
virtual FName DiagnosticContext(bool bDetailed) override
FVector GripRenderThreadLastLocationForLateUpdate
float RenderSmoothingSpeed
FBPEuroLowPassFilterTrans RenderEuroSmoothingParams
FVector GripRenderThreadComponentScale
bool bRenderSmoothHandTracking
FTransform RenderLastSmoothRelativeTransform
FTransform GripRenderThreadProfileTransform
bool bRenderSmoothWithEuroLowPassFunction
float RenderLastDeltaTime
FTransform GripRenderThreadRelativeTransform