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