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