A Demo Project for the UnrealEngineSDK
Loading...
Searching...
No Matches
VRGripScriptBase.h
Go to the documentation of this file.
1// Fill out your copyright notice in the Description page of Project Settings.
2
3#pragma once
4
5#include "CoreMinimal.h"
6#include "Engine/Engine.h"
7#include "UObject/Object.h"
8#include "VRBPDatatypes.h"
9#include "Components/PrimitiveComponent.h"
10#include "GameFramework/Actor.h"
11#include "Tickable.h"
12#include "Net/UnrealNetwork.h"
13
14#include "VRGripScriptBase.generated.h"
15
18
19UENUM(Blueprintable)
20enum class EGSTransformOverrideType : uint8
21{
24
25 /* Overrides the world transform */
27
28 /* Modifies the world transform*/
30};
31
32UCLASS(NotBlueprintable, BlueprintType, EditInlineNew, DefaultToInstanced, Abstract, ClassGroup = (VRExpansionPlugin), HideCategories = DefaultSettings)
33class VREXPANSIONPLUGIN_API UVRGripScriptBase : public UObject, public FTickableGameObject
34{
35 GENERATED_BODY()
36public:
37
38 UVRGripScriptBase(const FObjectInitializer& ObjectInitializer);
39
40 // Gets the first grip script of the specified type in this object, do NOT call this on tick, save out and store the reference given
41 UFUNCTION(BlueprintCallable, Category = "VRGripScript|Functions", meta = (WorldContext = "WorldContextObject", bIgnoreSelf = "true", DisplayName = "GetGripScriptByClass", ExpandEnumAsExecs = "Result"))
42 static UVRGripScriptBase* GetGripScriptByClass(UObject* WorldContextObject, TSubclassOf<UVRGripScriptBase> GripScriptClass, EBPVRResultSwitch& Result);
44 bool IsSupportedForNetworking() const override
45 {
46 return true;
47 //return bRequiresReplicationSupport || Super::IsSupportedForNetworking();
48 }
49 // I don't need to do this, there should be no dynamic script spawning and they are all name stable by default
50
51 // Returns if the script is currently active and should be used
52 bool IsScriptActive();
53
54 // Is currently active helper variable, returned from IsScriptActive()
55 UPROPERTY(BlueprintReadWrite, EditDefaultsOnly, Category = "GSSettings")
56 bool bIsActive;
58 // Returns if the script is going to modify the world transform of the grip
59 EGSTransformOverrideType GetWorldTransformOverrideType();
60
61 // Whether this script overrides or modifies the world transform
62 UPROPERTY(BlueprintReadWrite, EditDefaultsOnly, Category = "GSSettings")
63 EGSTransformOverrideType WorldTransformOverrideType;
64
65 // Returns if the script wants auto drop to be ignored
66 FORCEINLINE bool Wants_DenyAutoDrop()
67 {
68 return bDenyAutoDrop;
69 }
70
71 // Returns if we want to deny auto dropping
72 UPROPERTY(BlueprintReadWrite, EditDefaultsOnly, Category = "GSSettings")
73 bool bDenyAutoDrop;
74
75 // Returns if the script wants to force a drop
76 FORCEINLINE bool Wants_ToForceDrop()
77 {
78 return bForceDrop;
79 }
80
81 // Returns if we want to force a drop
82 UPROPERTY(BlueprintReadWrite, Category = "GSSettings")
83 bool bForceDrop;
85 // Flags the grip to be dropped as soon as possible
86 UFUNCTION(BlueprintCallable, Category = "VRGripScript")
87 void ForceGripToDrop()
88 {
89 bForceDrop = true;
90 }
91
92 // Returns if the script wants to deny late updates
93 FORCEINLINE bool Wants_DenyLateUpdates()
94 {
95 return bDenyLateUpdates;
96 }
97
98 // Returns if we want to inject changes prior to the physics handle
99 UPROPERTY(BlueprintReadWrite, EditDefaultsOnly, Category = "GSSettings")
100 bool bDenyLateUpdates;
102 // Returns if the script wants auto drop to be ignored
103 FORCEINLINE bool InjectPrePhysicsHandle()
104 {
105 return bInjectPrePhysicsHandle;
106 }
107
108 // Returns if we want to inject changes prior to the physics handle
109 UPROPERTY(BlueprintReadWrite, EditDefaultsOnly, Category = "GSSettings")
110 bool bInjectPrePhysicsHandle;
112 virtual void HandlePrePhysicsHandle(UGripMotionControllerComponent* GrippingController, const FBPActorGripInformation &GripInfo, FBPActorPhysicsHandleInformation * HandleInfo, FTransform & KinPose);
113
114 // Returns if we want to inject changes after the physics handle
115 FORCEINLINE bool InjectPostPhysicsHandle()
116 {
117 return bInjectPostPhysicsHandle;
119
120 // Returns if we want to inject changes after the physics handle
121 UPROPERTY(BlueprintReadWrite, EditDefaultsOnly, Category = "GSSettings")
122 bool bInjectPostPhysicsHandle;
123
124 virtual void HandlePostPhysicsHandle(UGripMotionControllerComponent* GrippingController, FBPActorPhysicsHandleInformation * HandleInfo);
125
126 // Returns if the script is currently active and should be used
127 UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "VRGripScript")
128 bool Wants_DenyTeleport(UGripMotionControllerComponent * Controller);
129 virtual bool Wants_DenyTeleport_Implementation(UGripMotionControllerComponent* Controller);
130
131 virtual void GetLifetimeReplicatedProps(TArray< class FLifetimeProperty > & OutLifetimeProps) const override;
132
133 // doesn't currently compile in editor builds, not sure why the linker is screwing up there but works elsewhere
134 //virtual void PreReplication(IRepChangedPropertyTracker & ChangedPropertyTracker);
135 virtual bool CallRemoteFunction(UFunction * Function, void * Parms, FOutParmRec * OutParms, FFrame * Stack) override;
136 virtual int32 GetFunctionCallspace(UFunction * Function, FFrame * Stack) override;
137
138 // FTickableGameObject functions
139
140
141 // If true then this scrip can tick when bAllowticking is true
142 UPROPERTY(BlueprintReadWrite, EditDefaultsOnly, Category = "TickSettings")
143 bool bCanEverTick;
144
145 // If true and we bCanEverTick, then will fire off the tick function
146 UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "TickSettings")
147 bool bAllowTicking;
148
149 // Set whether the grip script can tick or not
150 UFUNCTION(BlueprintCallable, Category = "TickSettings")
151 void SetTickEnabled(bool bTickEnabled);
152
159 virtual void Tick(float DeltaTime) override;
160 virtual bool IsTickable() const override;
161 virtual UWorld* GetTickableGameObjectWorld() const override;
162 virtual bool IsTickableInEditor() const;
163 virtual bool IsTickableWhenPaused() const override;
164 virtual ETickableTickType GetTickableTickType() const;
165 virtual TStatId GetStatId() const override;
166 virtual UWorld* GetWorld() const override;
167
168 // End tickable object information
169
170
171 // Returns the expected grip transform (relative * controller + addition)
172 UFUNCTION(BlueprintPure, Category = "VRGripScript")
173 FTransform GetGripTransform(const FBPActorGripInformation &Grip, const FTransform & ParentTransform);
174
175 // Returns the current world transform of the owning object (or root comp of if it is an actor)
176 UFUNCTION(BlueprintPure, Category = "VRGripScript")
177 FTransform GetParentTransform(bool bGetWorldTransform = true, FName BoneName = NAME_None);
178
179 // Returns the scene component of the parent, either being the parent itself or the root comp of it.
180 // Nullptr if there is no valid scene component
181 UFUNCTION(BlueprintCallable, Category = "VRGripScript")
182 USceneComponent* GetParentSceneComp();
183
184 // Returns the root body instance of the parent
185 FBodyInstance * GetParentBodyInstance(FName OptionalBoneName = NAME_None);
186
187 // Returns the parent component or actor to this
188 UFUNCTION(BlueprintPure, Category = "VRGripScript")
189 UObject * GetParent();
190
191 // Returns the owning actor
192 UFUNCTION(BlueprintPure, Category = "VRGripScript")
193 AActor * GetOwner();
195 // If the owning actor has authority on this connection
196 UFUNCTION(BlueprintPure, Category = "VRGripScript")
197 bool HasAuthority();
198
199 // If the owning actor is on the server on this connection
200 UFUNCTION(BlueprintPure, Category = "VRGripScript")
201 bool IsServer();
203 void EndPlay(const EEndPlayReason::Type EndPlayReason);
204
205 // Not all scripts will require this function, specific ones that use things like Lever logic however will. Best to call it.
206 // Grippables will automatically call this, however if you manually spawn a grip script during play or you make your own
207 // Interfaced grip object and give it grippables, YOU will be required to call this event on them.
208 UFUNCTION(BlueprintNativeEvent, Category = "VRGripScript")
209 void OnEndPlay(const EEndPlayReason::Type EndPlayReason);
210 virtual void OnEndPlay_Implementation(const EEndPlayReason::Type EndPlayReason);
211
212 void BeginPlay(UObject * CallingOwner);
213 bool bAlreadyNotifiedPlay = false;
214 virtual void PostInitProperties() override;
215
216 // Not all scripts will require this function, specific ones that use things like Lever logic however will. Best to call it.
217 // Grippables will automatically call this, however if you manually spawn a grip script during play or you make your own
218 // Interfaced grip object and give it grippables, YOU will be required to call this event on them.
219 UFUNCTION(BlueprintNativeEvent, Category = "VRGripScript")
220 void OnBeginPlay(UObject * CallingOwner);
221 virtual void OnBeginPlay_Implementation(UObject * CallingOwner);
222
223 // Overrides or Modifies the world transform with this grip script
224 UFUNCTION(BlueprintNativeEvent, Category = "VRGripScript")
225 bool GetWorldTransform(UGripMotionControllerComponent * GrippingController, float DeltaTime, UPARAM(ref) FTransform & WorldTransform, const FTransform &ParentTransform, UPARAM(ref) FBPActorGripInformation &Grip, AActor * actor, UPrimitiveComponent * root, bool bRootHasInterface, bool bActorHasInterface, bool bIsForTeleport);
226 virtual bool GetWorldTransform_Implementation(UGripMotionControllerComponent * OwningController, float DeltaTime, FTransform & WorldTransform, const FTransform &ParentTransform, FBPActorGripInformation &Grip, AActor * actor, UPrimitiveComponent * root, bool bRootHasInterface, bool bActorHasInterface, bool bIsForTeleport);
227
228 // Event triggered on the interfaced object when gripped
229 UFUNCTION(BlueprintNativeEvent, Category = "VRGripScript")
230 void OnGrip(UGripMotionControllerComponent * GrippingController, const FBPActorGripInformation & GripInformation);
231 virtual void OnGrip_Implementation(UGripMotionControllerComponent * GrippingController, const FBPActorGripInformation & GripInformation);
232
233 // Event triggered on the interfaced object when grip is released
234 UFUNCTION(BlueprintNativeEvent, Category = "VRGripScript")
235 void OnGripRelease(UGripMotionControllerComponent * ReleasingController, const FBPActorGripInformation & GripInformation, bool bWasSocketed = false);
236 virtual void OnGripRelease_Implementation(UGripMotionControllerComponent * ReleasingController, const FBPActorGripInformation & GripInformation, bool bWasSocketed = false);
237
238 // Event triggered on the interfaced object when secondary gripped
239 UFUNCTION(BlueprintNativeEvent, Category = "VRGripInterface")
240 void OnSecondaryGrip(UGripMotionControllerComponent * Controller, USceneComponent * SecondaryGripComponent, const FBPActorGripInformation & GripInformation);
241 virtual void OnSecondaryGrip_Implementation(UGripMotionControllerComponent * Controller, USceneComponent * SecondaryGripComponent, const FBPActorGripInformation & GripInformation);
242
243 // Event triggered on the interfaced object when secondary grip is released
244 UFUNCTION(BlueprintNativeEvent, Category = "VRGripInterface")
245 void OnSecondaryGripRelease(UGripMotionControllerComponent * Controller, USceneComponent * ReleasingSecondaryGripComponent, const FBPActorGripInformation & GripInformation);
246 virtual void OnSecondaryGripRelease_Implementation(UGripMotionControllerComponent * Controller, USceneComponent * ReleasingSecondaryGripComponent, const FBPActorGripInformation & GripInformation);
247
248
249
250 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)
251 {
252 return GetWorldTransform_Implementation(OwningController, DeltaTime, WorldTransform, ParentTransform, Grip, actor, root, bRootHasInterface, bActorHasInterface, bIsForTeleport);
253 }
254};
255
256
257UCLASS(Blueprintable, Abstract, ClassGroup = (VRExpansionPlugin), ShowCategories = DefaultSettings)
258class VREXPANSIONPLUGIN_API UVRGripScriptBaseBP : public UVRGripScriptBase
259{
260 GENERATED_BODY()
261public:
262
263 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) override
264 {
265 return GetWorldTransform(OwningController, DeltaTime, WorldTransform, ParentTransform, Grip, actor, root, bRootHasInterface, bActorHasInterface, bIsForTeleport);
266 }
267
268 virtual void Tick(float DeltaTime) override;
269
271 UFUNCTION(BlueprintImplementableEvent, meta = (DisplayName = "Tick"))
272 void ReceiveTick(float DeltaSeconds);
273};
EBPVRResultSwitch
UENUM()
EGSTransformOverrideType
UENUM(Blueprintable)
UCLASS(Blueprintable, meta = (BlueprintSpawnableComponent), ClassGroup = MotionController)
UINTERFACE(Blueprintable)
UCLASS(Blueprintable, Abstract, ClassGroup = (VRExpansionPlugin), ShowCategories = DefaultSettings)
void ReceiveTick(float DeltaSeconds)
UFUNCTION(BlueprintImplementableEvent, meta = (DisplayName = "Tick"))
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) override
UCLASS(NotBlueprintable, BlueprintType, EditInlineNew, DefaultToInstanced, Abstract,...
bool bInjectPostPhysicsHandle
UPROPERTY(BlueprintReadWrite, EditDefaultsOnly, Category = "GSSettings")
void OnBeginPlay(UObject *CallingOwner)
UFUNCTION(BlueprintNativeEvent, Category = "VRGripScript")
bool bDenyAutoDrop
UPROPERTY(BlueprintReadWrite, EditDefaultsOnly, Category = "GSSettings")
void OnEndPlay(const EEndPlayReason::Type EndPlayReason)
UFUNCTION(BlueprintNativeEvent, Category = "VRGripScript")
bool Wants_DenyTeleport(UGripMotionControllerComponent *Controller)
UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "VRGripScript")
void OnGripRelease(UGripMotionControllerComponent *ReleasingController, const FBPActorGripInformation &GripInformation, bool bWasSocketed=false)
UFUNCTION(BlueprintNativeEvent, Category = "VRGripScript")
void OnGrip(UGripMotionControllerComponent *GrippingController, const FBPActorGripInformation &GripInformation)
UFUNCTION(BlueprintNativeEvent, Category = "VRGripScript")
bool bForceDrop
UPROPERTY(BlueprintReadWrite, Category = "GSSettings")
FORCEINLINE bool Wants_DenyAutoDrop()
FORCEINLINE bool Wants_ToForceDrop()
FORCEINLINE bool InjectPrePhysicsHandle()
void OnSecondaryGripRelease(UGripMotionControllerComponent *Controller, USceneComponent *ReleasingSecondaryGripComponent, const FBPActorGripInformation &GripInformation)
UFUNCTION(BlueprintNativeEvent, Category = "VRGripInterface")
bool bAllowTicking
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "TickSettings")
bool bInjectPrePhysicsHandle
UPROPERTY(BlueprintReadWrite, EditDefaultsOnly, Category = "GSSettings")
void OnSecondaryGrip(UGripMotionControllerComponent *Controller, USceneComponent *SecondaryGripComponent, const FBPActorGripInformation &GripInformation)
UFUNCTION(BlueprintNativeEvent, Category = "VRGripInterface")
bool bDenyLateUpdates
UPROPERTY(BlueprintReadWrite, EditDefaultsOnly, Category = "GSSettings")
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)
FORCEINLINE bool InjectPostPhysicsHandle()
FORCEINLINE bool Wants_DenyLateUpdates()
bool IsSupportedForNetworking() const override
EGSTransformOverrideType WorldTransformOverrideType
UPROPERTY(BlueprintReadWrite, EditDefaultsOnly, Category = "GSSettings")
bool GetWorldTransform(UGripMotionControllerComponent *GrippingController, float DeltaTime, UPARAM(ref) FTransform &WorldTransform, const FTransform &ParentTransform, UPARAM(ref) FBPActorGripInformation &Grip, AActor *actor, UPrimitiveComponent *root, bool bRootHasInterface, bool bActorHasInterface, bool bIsForTeleport)
UFUNCTION(BlueprintNativeEvent, Category = "VRGripScript")
bool bIsActive
UPROPERTY(BlueprintReadWrite, EditDefaultsOnly, Category = "GSSettings")
bool bCanEverTick
UPROPERTY(BlueprintReadWrite, EditDefaultsOnly, Category = "TickSettings")
void ForceGripToDrop()
UFUNCTION(BlueprintCallable, Category = "VRGripScript")
USTRUCT(BlueprintType, Category = "VRExpansionLibrary")
USTRUCT(BlueprintType, Category = "VRExpansionLibrary")