UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
MotionControllerComponent.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
7#include "IMotionController.h"
8#include "LateUpdateManager.h"
9#include "MotionControllerComponent.generated.h"
10
13class FSceneView;
16
17UCLASS(Blueprintable, meta = (BlueprintSpawnableComponent), ClassGroup = MotionController, MinimalAPI)
18class UMotionControllerComponent : public UPrimitiveComponent
19{
21
22
23 UPROPERTY(EditAnywhere, BlueprintReadWrite, BlueprintSetter = SetAssociatedPlayerIndex, Category = "MotionController")
25
27 UPROPERTY(EditAnywhere, BlueprintReadWrite, BlueprintSetter = SetTrackingMotionSource, Category = "MotionController")
28 FName MotionSource;
29
31 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "MotionController")
32 uint32 bDisableLowLatencyUpdate : 1;
33
35 UPROPERTY(BlueprintReadOnly, Category = "MotionController")
36 ETrackingStatus CurrentTrackingStatus;
37
39 UFUNCTION(BlueprintPure, Category = "MotionController")
40 bool IsTracked() const
41 {
42 return bTracked;
43 }
44
45 UFUNCTION(BlueprintSetter, meta = (DeprecatedFunction, DeprecationMessage = "Please use the Motion Source property instead of Hand"))
46 HEADMOUNTEDDISPLAY_API void SetTrackingSource(const EControllerHand NewSource);
47
48 UFUNCTION(BlueprintGetter, meta = (DeprecatedFunction, DeprecationMessage = "Please use the Motion Source property instead of Hand"))
49 HEADMOUNTEDDISPLAY_API EControllerHand GetTrackingSource() const;
50
51 UFUNCTION(BlueprintSetter)
52 HEADMOUNTEDDISPLAY_API void SetTrackingMotionSource(const FName NewSource);
53
54 HEADMOUNTEDDISPLAY_API FName GetTrackingMotionSource();
55
56 UFUNCTION(BlueprintSetter)
57 HEADMOUNTEDDISPLAY_API void SetAssociatedPlayerIndex(const int32 NewPlayer);
58
59 HEADMOUNTEDDISPLAY_API void TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
60 HEADMOUNTEDDISPLAY_API void BeginDestroy() override;
61
62public:
63 //~ UObject interface
64 HEADMOUNTEDDISPLAY_API virtual void Serialize(FArchive& Ar) override;
65
66 //~ UActorComponent interface
67 HEADMOUNTEDDISPLAY_API virtual void InitializeComponent() override;
68
69 // Delegate for activation of XRDeviceVisualizationComponent
72
73protected:
74 //~ Begin UActorComponent Interface.
75 HEADMOUNTEDDISPLAY_API virtual void CreateRenderState_Concurrent(FRegisterComponentContext* Context) override;
76 HEADMOUNTEDDISPLAY_API virtual void SendRenderTransform_Concurrent() override;
77 //~ End UActorComponent Interface.
78
79 // Cached Motion Controller that can be read by GetParameterValue. Only valid for the duration of OnMotionControllerUpdated
81
83 UFUNCTION(BlueprintImplementableEvent, Category = "Motion Controller Update")
84 HEADMOUNTEDDISPLAY_API void OnMotionControllerUpdated();
85
86 // Returns the value of a custom parameter on the current in use Motion Controller (see member InUseMotionController). Only valid for the duration of OnMotionControllerUpdated
87 UFUNCTION(BlueprintCallable, Category = "Motion Controller Update")
88 HEADMOUNTEDDISPLAY_API float GetParameterValue(FName InName, bool& bValueFound);
89
90 UFUNCTION(BlueprintCallable, Category = "Motion Controller Update")
91 HEADMOUNTEDDISPLAY_API FVector GetHandJointPosition(int jointIndex, bool& bValueFound);
92
94 UFUNCTION(BlueprintPure, Category = "Motion Controller Update")
95 HEADMOUNTEDDISPLAY_API bool GetLinearVelocity(FVector &OutLinearVelocity) const;
96
98 UFUNCTION(BlueprintPure, Category = "Motion Controller Update")
99 HEADMOUNTEDDISPLAY_API bool GetAngularVelocity(FRotator& OutAngularVelocity) const;
100
102 UFUNCTION(BlueprintPure, Category = "Motion Controller Update")
103 HEADMOUNTEDDISPLAY_API bool GetLinearAcceleration(FVector& OutLinearAcceleration) const;
104
105
107
109 bool bTracked;
110
112 bool bHasAuthority;
113
114 // Velocity and acceleration data for the motion controller, if available.
115 bool bProvidedLinearVelocity;
116 bool bProvidedAngularVelocity;
117 bool bProvidedLinearAcceleration;
118 // Note: these values are in tracking space, which is also the space relative to the parent of the motioncontroller component, and still need to be converted to unreal space by the TrackingToWorldTransform for use.
119 // They are in the unreal coordinate system and world scaled.
120 // Also we do not late-update these values.
122 FVector AngularVelocityAsAxisAndLength; // This vector represents an axis of rotation and its length is the magnitude of the rotation in radians per second. Be careful turning it into a quaternion because those cannot represent more than 0.5 revolution per second. See UHeadMountedDisplayFunctionLibrary::GetControllerTransformForTime2 for an example of how this can be turned into an FRotator without losing rotation speed beyond 180 degrees/second.
123 FVector LinearAcceleration;
124
126 UE_DEPRECATED(5.3, "PollControllerState has been deprecated. Please update to use PollControllerState_GameThread or PollControllerState_RenderThread, as appropriate.")
127 HEADMOUNTEDDISPLAY_API bool PollControllerState(FVector& Position, FRotator& Orientation, float WorldToMetersScale);
129 HEADMOUNTEDDISPLAY_API bool PollControllerState_RenderThread(FVector& Position, FRotator& Orientation, float WorldToMetersScale);
130
131 HEADMOUNTEDDISPLAY_API void OnModularFeatureUnregistered(const FName& Type, class IModularFeature* ModularFeature);
132 IMotionController* PolledMotionController_GameThread;
133 IMotionController* PolledMotionController_RenderThread;
134 bool bPolledHMD_GameThread;
135 bool bPolledHMD_RenderThread;
136 FCriticalSection PolledMotionControllerMutex; // Used to protect PolledMotionController_GameThread and bPolledHMD_GameThread which are written on the game thread and copied on the render thread.
137
138
139 FTransform RenderThreadRelativeTransform;
140 FVector RenderThreadComponentScale;
141
144 {
145 public:
147 virtual ~FViewExtension() {}
148
150 virtual void BeginRenderViewFamily(FSceneViewFamily& InViewFamily) override;
151 virtual void PreRenderViewFamily_RenderThread(FRDGBuilder& GraphBuilder, FSceneViewFamily& InViewFamily) override;
152 virtual int32 GetPriority() const override { return -10; }
153 virtual bool IsActiveThisFrame_Internal(const FSceneViewExtensionContext& Context) const;
154
155 protected:
157
161 };
163};
PlayerIndex
Definition AppleControllerInterface.h:24
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
UE::FPlatformRecursiveMutex FCriticalSection
Definition CriticalSection.h:53
ELevelTick
Definition EngineBaseTypes.h:70
ETrackingStatus
Definition IMotionController.h:16
EControllerHand
Definition InputCoreTypes.h:17
#define UPROPERTY(...)
UObject definition macros.
Definition ObjectMacros.h:744
#define UFUNCTION(...)
Definition ObjectMacros.h:745
#define GENERATED_UCLASS_BODY(...)
Definition ObjectMacros.h:768
#define UCLASS(...)
Definition ObjectMacros.h:776
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition Archive.h:1208
Definition SceneViewExtension.h:266
Definition LateUpdateManager.h:14
Definition NameTypes.h:617
Definition PrimitiveSceneInfo.h:266
Definition RenderGraphBuilder.h:49
Definition RHICommandList.h:4626
Definition ActorComponent.h:47
Definition SceneViewExtension.h:274
Definition SceneView.h:2212
Definition SceneView.h:1425
Definition IModularFeature.h:12
Definition IMotionController.h:48
Definition SharedPointer.h:692
Definition MotionControllerComponent.h:144
UMotionControllerComponent * MotionControllerComponent
Definition MotionControllerComponent.h:159
virtual ~FViewExtension()
Definition MotionControllerComponent.h:147
FLateUpdateManager LateUpdate
Definition MotionControllerComponent.h:160
virtual int32 GetPriority() const override
Definition MotionControllerComponent.h:152
Definition MotionControllerComponent.h:19
DECLARE_MULTICAST_DELEGATE_OneParam(FActivateVisualizationComponent, bool)
static HEADMOUNTEDDISPLAY_API FActivateVisualizationComponent OnActivateVisualizationComponent
Definition MotionControllerComponent.h:71
IMotionController * InUseMotionController
Definition MotionControllerComponent.h:80
TSharedPtr< FViewExtension, ESPMode::ThreadSafe > ViewExtension
Definition MotionControllerComponent.h:162
Definition EngineBaseTypes.h:571
Definition SceneViewExtensionContext.h:20