A Demo Project for the UnrealEngineSDK
Loading...
Searching...
No Matches
GrippableActor.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"
7#include "VRBPDatatypes.h"
8#include "VRGripInterface.h"
9#include "Engine/Engine.h"
11#include "GameplayTagContainer.h"
12#include "GameplayTagAssetInterface.h"
14#include "Engine/ActorChannel.h"
15#include "DrawDebugHelpers.h"
19#include "GrippableActor.generated.h"
20
24UCLASS(Blueprintable, meta = (BlueprintSpawnableComponent), ClassGroup = (VRExpansionPlugin))
25class VREXPANSIONPLUGIN_API AGrippableActor : public AActor, public IVRGripInterface, public IGameplayTagAssetInterface
26{
27 GENERATED_BODY()
29public:
30 AGrippableActor(const FObjectInitializer& ObjectInitializer);
31
33 virtual void BeginPlay() override;
34 virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
35
36 UPROPERTY(Replicated, ReplicatedUsing = OnRep_AttachmentReplication)
37 FRepAttachmentWithWeld AttachmentWeldReplication;
38
39 virtual void GatherCurrentMovement() override;
40
41 UPROPERTY(EditAnywhere, Replicated, BlueprintReadOnly, Instanced, Category = "VRGripInterface")
42 TArray<class UVRGripScriptBase *> GripLogicScripts;
44 // If true then the grip script array will be considered for replication, if false then it will not
45 // This is an optimization for when you have a lot of grip scripts in use, you can toggle this off in cases
46 // where the object will never have a replicating script
47 UPROPERTY(EditAnywhere, Replicated, BlueprintReadWrite, Category = "VRGripInterface")
48 bool bReplicateGripScripts;
49
50 bool ReplicateSubobjects(UActorChannel* Channel, class FOutBunch *Bunch, FReplicationFlags *RepFlags) override;
51 virtual void GetSubobjectsWithStableNamesForNetworking(TArray<UObject*>& ObjList) override;
52
53 // Sets the Deny Gripping variable on the FBPInterfaceSettings struct
54 UFUNCTION(BlueprintCallable, Category = "VRGripInterface")
55 void SetDenyGripping(bool bDenyGripping);
56
57 // Sets the grip priority on the FBPInterfaceSettings struct
58 UFUNCTION(BlueprintCallable, Category = "VRGripInterface")
59 void SetGripPriority(int NewGripPriority);
60
61 // Called when a object is gripped
62 // If you override the OnGrip event then you will need to call the parent implementation or this event will not fire!!
63 UPROPERTY(BlueprintAssignable, Category = "Grip Events")
64 FVROnGripSignature OnGripped;
66 // Called when a object is dropped
67 // If you override the OnGrip event then you will need to call the parent implementation or this event will not fire!!
68 UPROPERTY(BlueprintAssignable, Category = "Grip Events")
69 FVROnDropSignature OnDropped;
70
71 // Called when an object we hold is secondary gripped
72 // If you override the OnGrip event then you will need to call the parent implementation or this event will not fire!!
73 UPROPERTY(BlueprintAssignable, Category = "Grip Events")
74 FVROnGripSignature OnSecondaryGripAdded;
75
76 // Called when an object we hold is secondary dropped
77 // If you override the OnGrip event then you will need to call the parent implementation or this event will not fire!!
78 UPROPERTY(BlueprintAssignable, Category = "Grip Events")
79 FVROnGripSignature OnSecondaryGripRemoved;
80
81 // ------------------------------------------------
82 // Client Auth Throwing Data and functions
83 // ------------------------------------------------
84
85 UPROPERTY(EditAnywhere, Replicated, BlueprintReadWrite, Category = "Replication")
86 FVRClientAuthReplicationData ClientAuthReplicationData;
87
88 // Add this to client side physics replication (until coming to rest or timeout period is hit)
89 UFUNCTION(BlueprintCallable, Category = "Networking")
90 bool AddToClientReplicationBucket();
91
92 // Remove this from client side physics replication
93 UFUNCTION(BlueprintCallable, Category = "Networking")
94 bool RemoveFromClientReplicationBucket();
95
96 UFUNCTION()
97 bool PollReplicationEvent();
99 UFUNCTION(Category = "Networking")
100 void CeaseReplicationBlocking();
101
102 // Notify the server that we are no longer trying to run the throwing auth
103 UFUNCTION(Reliable, Server, WithValidation, Category = "Networking")
104 void Server_EndClientAuthReplication();
105
106 // Notify the server about a new movement rep
107 UFUNCTION(UnReliable, Server, WithValidation, Category = "Networking")
108 void Server_GetClientAuthReplication(const FRepMovementVR & newMovement);
109
110 // Returns if this object is currently client auth throwing
111 UFUNCTION(BlueprintPure, Category = "Networking")
112 FORCEINLINE bool IsCurrentlyClientAuthThrowing()
113 {
114 return ClientAuthReplicationData.bIsCurrentlyClientAuth;
115 }
116
117 // End client auth throwing data and functions //
118
119 // ------------------------------------------------
120 // Gameplay tag interface
121 // ------------------------------------------------
122
124 virtual void GetOwnedGameplayTags(FGameplayTagContainer& TagContainer) const override
125 {
126 TagContainer = GameplayTags;
127 }
128
130 UPROPERTY(EditAnywhere, Replicated, BlueprintReadWrite, Category = "GameplayTags")
131 FGameplayTagContainer GameplayTags;
132
133 // End Gameplay Tag Interface
134
135 virtual void PreReplication(IRepChangedPropertyTracker & ChangedPropertyTracker) override;
136
137 // Skips the attachment replication if we are locally owned and our grip settings say that we are a client authed grip.
138 UPROPERTY(EditAnywhere, Replicated, BlueprintReadWrite, Category = "Replication")
139 bool bAllowIgnoringAttachOnOwner;
140
141 // Should we skip attachment replication (vr settings say we are a client auth grip and our owner is locally controlled)
142 inline bool ShouldWeSkipAttachmentReplication(bool bConsiderHeld = true) const
143 {
144 if ((bConsiderHeld && !VRGripInterfaceSettings.bWasHeld) || GetNetMode() < ENetMode::NM_Client)
145 return false;
146
147 if (VRGripInterfaceSettings.MovementReplicationType == EGripMovementReplicationSettings::ClientSide_Authoritive ||
148 VRGripInterfaceSettings.MovementReplicationType == EGripMovementReplicationSettings::ClientSide_Authoritive_NoRep)
149 {
150 return HasLocalNetOwner();
151 }
152 else
153 return false;
154 }
155
156 // Handle fixing some bugs and issues with ReplicateMovement being off
157 virtual void OnRep_AttachmentReplication() override;
158 virtual void OnRep_ReplicateMovement() override;
159 virtual void OnRep_ReplicatedMovement() override;
160 virtual void PostNetReceivePhysicState() override;
161
162 // Debug printing of when the object is replication destroyed
163 /*virtual void OnSubobjectDestroyFromReplication(UObject *Subobject) override
164 {
165 Super::OnSubobjectDestroyFromReplication(Subobject);
166
167 GEngine->AddOnScreenDebugMessage(-1, 15.f, FColor::Red, FString::Printf(TEXT("Killed Object On Actor: x: %s"), *Subobject->GetName()));
168 }*/
169
170 // This isn't called very many places but it does come up
171 virtual void MarkComponentsAsPendingKill() override;
172
174 // Clean up our objects so that they aren't sitting around for GC
175 virtual void PreDestroyFromReplication() override;
176
177 // On Destroy clean up our objects
178 virtual void BeginDestroy() override;
179
180 UPROPERTY(EditAnywhere, Replicated, BlueprintReadWrite, Category = "VRGripInterface")
181 bool bRepGripSettingsAndGameplayTags;
182
183 UPROPERTY(EditAnywhere, Replicated, BlueprintReadWrite, Category = "VRGripInterface")
184 FBPInterfaceProperties VRGripInterfaceSettings;
185
186 // Set up as deny instead of allow so that default allows for gripping
187 // The GripInitiator is not guaranteed to be valid, check it for validity
188 virtual bool DenyGripping_Implementation(UGripMotionControllerComponent * GripInitiator = nullptr) override;
189
190 // How an interfaced object behaves when teleporting
191 virtual EGripInterfaceTeleportBehavior TeleportBehavior_Implementation() override;
192
193 // Should this object simulate on drop
194 virtual bool SimulateOnDrop_Implementation() override;
195
196 // Grip type to use
197 virtual EGripCollisionType GetPrimaryGripType_Implementation(bool bIsSlot) override;
198
199 // Secondary grip type
200 virtual ESecondaryGripType SecondaryGripType_Implementation() override;
201
202 // Define which movement repliation setting to use
203 virtual EGripMovementReplicationSettings GripMovementReplicationType_Implementation() override;
204
205 // Define the late update setting
206 virtual EGripLateUpdateSettings GripLateUpdateSetting_Implementation() override;
207
208 // What grip stiffness and damping to use if using a physics constraint
209 virtual void GetGripStiffnessAndDamping_Implementation(float& GripStiffnessOut, float& GripDampingOut) override;
210
211 // Get the advanced physics settings for this grip
212 virtual FBPAdvGripSettings AdvancedGripSettings_Implementation() override;
213
214 // What distance to break a grip at (only relevent with physics enabled grips
215 virtual float GripBreakDistance_Implementation() override;
216
217 // Get closest primary slot in range
218 virtual void ClosestGripSlotInRange_Implementation(FVector WorldLocation, bool bSecondarySlot, bool& bHadSlotInRange, FTransform& SlotWorldTransform, FName& SlotName, UGripMotionControllerComponent* CallingController = nullptr, FName OverridePrefix = NAME_None) override;
219
220 // Check if an object allows multiple grips at one time
221 virtual bool AllowsMultipleGrips_Implementation() override;
222
223 // Returns if the object is held and if so, which controllers are holding it
224 virtual void IsHeld_Implementation(TArray<FBPGripPair>& HoldingControllers, bool& bIsHeld) override;
225
226 // Sets is held, used by the plugin
227 virtual void SetHeld_Implementation(UGripMotionControllerComponent* HoldingController, uint8 GripID, bool bIsHeld) override;
228
229 // Interface function used to throw the delegates that is invisible to blueprints so that it can't be overridden
230 virtual void Native_NotifyThrowGripDelegates(UGripMotionControllerComponent* Controller, bool bGripped, const FBPActorGripInformation& GripInformation, bool bWasSocketed = false) override;
231
232 // Returns if the object wants to be socketed
233 virtual bool RequestsSocketing_Implementation(USceneComponent*& ParentToSocketTo, FName& OptionalSocketName, FTransform_NetQuantize& RelativeTransform) override;
234
235 // Get grip scripts
236 virtual bool GetGripScripts_Implementation(TArray<UVRGripScriptBase*>& ArrayReference) override;
237
238 // Events //
239
240 // Event triggered each tick on the interfaced object when gripped, can be used for custom movement or grip based logic
241 virtual void TickGrip_Implementation(UGripMotionControllerComponent* GrippingController, const FBPActorGripInformation& GripInformation, float DeltaTime) override;
242
243 // Event triggered on the interfaced object when gripped
244 virtual void OnGrip_Implementation(UGripMotionControllerComponent* GrippingController, const FBPActorGripInformation& GripInformation) override;
245
246 // Event triggered on the interfaced object when grip is released
247 virtual void OnGripRelease_Implementation(UGripMotionControllerComponent* ReleasingController, const FBPActorGripInformation& GripInformation, bool bWasSocketed = false) override;
248
249 // Event triggered on the interfaced object when child component is gripped
250 virtual void OnChildGrip_Implementation(UGripMotionControllerComponent* GrippingController, const FBPActorGripInformation& GripInformation) override;
251
252 // Event triggered on the interfaced object when child component is released
253 virtual void OnChildGripRelease_Implementation(UGripMotionControllerComponent* ReleasingController, const FBPActorGripInformation& GripInformation, bool bWasSocketed = false) override;
254
255 // Event triggered on the interfaced object when secondary gripped
256 virtual void OnSecondaryGrip_Implementation(UGripMotionControllerComponent* GripOwningController, USceneComponent* SecondaryGripComponent, const FBPActorGripInformation& GripInformation) override;
257
258 // Event triggered on the interfaced object when secondary grip is released
259 virtual void OnSecondaryGripRelease_Implementation(UGripMotionControllerComponent* GripOwningController, USceneComponent* ReleasingSecondaryGripComponent, const FBPActorGripInformation& GripInformation) override;
260
261 // Interaction Functions
262
263 // Call to use an object
264 virtual void OnUsed_Implementation() override;
265
266 // Call to stop using an object
267 virtual void OnEndUsed_Implementation() override;
268
269 // Call to use an object
270 virtual void OnSecondaryUsed_Implementation() override;
271
272 // Call to stop using an object
273 virtual void OnEndSecondaryUsed_Implementation() override;
274
275 // Call to send an action event to the object
276 virtual void OnInput_Implementation(FKey Key, EInputEvent KeyEvent) override;
277};
EGripMovementReplicationSettings
UENUM(Blueprintable)
ESecondaryGripType
UENUM(Blueprintable)
EGripCollisionType
UENUM(Blueprintable)
EGripLateUpdateSettings
UENUM(Blueprintable)
EGripInterfaceTeleportBehavior
UENUM(Blueprintable)
UCLASS(Blueprintable, meta = (BlueprintSpawnableComponent), ClassGroup = (VRExpansionPlugin))
bool bRepGripSettingsAndGameplayTags
UPROPERTY(EditAnywhere, Replicated, BlueprintReadWrite, Category = "VRGripInterface")
virtual void GetOwnedGameplayTags(FGameplayTagContainer &TagContainer) const override
FGameplayTagContainer GameplayTags
UPROPERTY(EditAnywhere, Replicated, BlueprintReadWrite, Category = "GameplayTags")
TArray< class UVRGripScriptBase * > GripLogicScripts
UPROPERTY(EditAnywhere, Replicated, BlueprintReadOnly, Instanced, Category = "VRGripInterface")
FVRClientAuthReplicationData ClientAuthReplicationData
UPROPERTY(EditAnywhere, Replicated, BlueprintReadWrite, Category = "Replication")
bool ShouldWeSkipAttachmentReplication(bool bConsiderHeld=true) const
void Server_GetClientAuthReplication(const FRepMovementVR &newMovement)
UFUNCTION(UnReliable, Server, WithValidation, Category = "Networking")
bool bReplicateGripScripts
UPROPERTY(EditAnywhere, Replicated, BlueprintReadWrite, Category = "VRGripInterface")
void Server_EndClientAuthReplication()
UFUNCTION(Reliable, Server, WithValidation, Category = "Networking")
FVROnGripSignature OnSecondaryGripAdded
UPROPERTY(BlueprintAssignable, Category = "Grip Events")
FBPInterfaceProperties VRGripInterfaceSettings
UPROPERTY(EditAnywhere, Replicated, BlueprintReadWrite, Category = "VRGripInterface")
bool bAllowIgnoringAttachOnOwner
UPROPERTY(EditAnywhere, Replicated, BlueprintReadWrite, Category = "Replication")
FVROnGripSignature OnSecondaryGripRemoved
UPROPERTY(BlueprintAssignable, Category = "Grip Events")
FVROnDropSignature OnDropped
UPROPERTY(BlueprintAssignable, Category = "Grip Events")
FORCEINLINE bool IsCurrentlyClientAuthThrowing()
UFUNCTION(BlueprintPure, Category = "Networking")
FVROnGripSignature OnGripped
UPROPERTY(BlueprintAssignable, Category = "Grip Events")
FRepAttachmentWithWeld AttachmentWeldReplication
UPROPERTY(Replicated, ReplicatedUsing = OnRep_AttachmentReplication)
virtual void Native_NotifyThrowGripDelegates(UGripMotionControllerComponent *Controller, bool bGripped, const FBPActorGripInformation &GripInformation, bool bWasSocketed=false)
UCLASS(Blueprintable, meta = (BlueprintSpawnableComponent), ClassGroup = MotionController)
UCLASS(NotBlueprintable, BlueprintType, EditInlineNew, DefaultToInstanced, Abstract,...
USTRUCT(BlueprintType, Category = "VRExpansionLibrary")
USTRUCT(BlueprintType, Category = "VRExpansionLibrary")
USTRUCT(BlueprintType, Category = "VRExpansionLibrary")
USTRUCT(BlueprintType, Category = "VRExpansionLibrary")
USTRUCT(BlueprintType, Category = "VRExpansionLibrary|TransformNetQuantize", meta = (HasNativeMake = ...