4#include "TimerManager.h"
5#include "Net/UnrealNetwork.h"
6#include "PhysicsReplication.h"
8#include "Net/Core/PushModel/PushModel.h"
34 SetReplicatingMovement(
true);
43 MinNetUpdateFrequency = 30.0f;
46void AGrippableActor::GetLifetimeReplicatedProps(TArray< class FLifetimeProperty > & OutLifetimeProps)
const
48 Super::GetLifetimeReplicatedProps(OutLifetimeProps);
58 DISABLE_REPLICATED_PRIVATE_PROPERTY(
AActor, AttachmentReplication);
60 FDoRepLifetimeParams AttachmentReplicationParams{ COND_Custom, REPNOTIFY_Always,
true };
85 DOREPLIFETIME_ACTIVE_OVERRIDE_PRIVATE_PROPERTY(
AActor, ReplicatedMovement, IsReplicatingMovement());
91 DOREPLIFETIME_ACTIVE_OVERRIDE_PRIVATE_PROPERTY(
AActor, AttachmentReplication, RootComponent && !RootComponent->GetIsReplicated());
101 UBlueprintGeneratedClass* BPClass = Cast<UBlueprintGeneratedClass>(GetClass());
102 if (BPClass !=
nullptr)
104 BPClass->InstancePreReplication(
this, ChangedPropertyTracker);
110 if (IsReplicatingMovement() || (RootComponent && RootComponent->GetAttachParent()))
112 bool bWasAttachmentModified =
false;
113 bool bWasRepMovementModified =
false;
121 FRepMovement& RepMovement = GetReplicatedMovement_Mutable();
123 UPrimitiveComponent* RootPrimComp = Cast<UPrimitiveComponent>(GetRootComponent());
124 if (RootPrimComp && RootPrimComp->IsSimulatingPhysics())
126 FRigidBodyState RBState;
127 RootPrimComp->GetRigidBodyState(RBState);
129 RepMovement.FillFrom(RBState,
this);
132 RepMovement.bRepPhysics = !RootPrimComp->IsWelded();
134 if (!RepMovement.bRepPhysics)
136 if (RootComponent->GetAttachParent() !=
nullptr)
151 bWasAttachmentModified =
true;
157 bWasRepMovementModified =
true;
159 else if (RootComponent !=
nullptr)
162 if (RootComponent->GetAttachParent() !=
nullptr)
177 bWasAttachmentModified =
true;
182 RepMovement.Location = FRepMovement::RebaseOntoZeroOrigin(RootComponent->GetComponentLocation(),
this);
183 RepMovement.Rotation = RootComponent->GetComponentRotation();
184 RepMovement.LinearVelocity = GetVelocity();
185 RepMovement.AngularVelocity = FVector::ZeroVector;
188 bWasRepMovementModified =
true;
191 bWasRepMovementModified = (bWasRepMovementModified || RepMovement.bRepPhysics);
192 RepMovement.bRepPhysics =
false;
196 if (bWasRepMovementModified)
201 if (bWasAttachmentModified ||
224 if (AttachParentComponent)
234 const bool bAlreadyAttached = (AttachParentComponent == RootComponent->GetAttachParent() &&
AttachmentWeldReplication.AttachSocket == RootComponent->GetAttachSocketName() && AttachParentComponent->GetAttachChildren().Contains(RootComponent));
235 if (bAlreadyAttached)
238 RootComponent->UpdateComponentToWorld(EUpdateTransformFlags::SkipPhysicsUpdate, ETeleportType::None);
242 FAttachmentTransformRules attachRules = FAttachmentTransformRules::KeepRelativeTransform;
251 DetachFromActor(FDetachmentTransformRules::KeepWorldTransform);
256 if (IsReplicatingMovement())
265 bool WroteSomething = Super::ReplicateSubobjects(Channel, Bunch, RepFlags);
271 if (Script && !Script->IsPendingKill())
273 WroteSomething |= Channel->ReplicateSubobject(Script, *Bunch, *RepFlags);
278 return WroteSomething;
296 Script->BeginPlay(
this);
380 if (OverridePrefix.IsNone())
381 bSecondarySlot ? OverridePrefix =
"VRGripS" : OverridePrefix =
"VRGripP";
405 if (UWorld * World = GetWorld())
418 GetWorld()->GetSubsystem<
UBucketUpdateSubsystem>()->RemoveObjectFromBucketByFunctionName(
this,
FName(TEXT(
"PollReplicationEvent")));
455 bool bWasLocallyOwned = HoldingController ? HoldingController->
IsLocallyControlled() :
false;
458 if (UPrimitiveComponent* PrimComp = Cast<UPrimitiveComponent>(GetRootComponent()))
460 if (PrimComp->IsSimulatingPhysics())
486 UWorld* OurWorld = GetWorld();
490 bool bRemoveBlocking =
false;
497 bRemoveBlocking =
true;
501 FTransform CurTransform = this->GetActorTransform();
503 if (!bRemoveBlocking)
509 if (UPrimitiveComponent * PrimComp = Cast<UPrimitiveComponent>(RootComponent))
519 if (PrimComp->RigidBodyIsAwake())
528 bRemoveBlocking =
true;
539 bool TimedBlockingRelease =
false;
541 AActor* TopOwner = GetOwner();
542 if (TopOwner !=
nullptr)
544 AActor* tempOwner = TopOwner->GetOwner();
549 TopOwner = tempOwner;
550 tempOwner = TopOwner->GetOwner();
555 if (APlayerState * PlayerState = PlayerController->PlayerState)
563 float clampedPing = FMath::Clamp(PlayerState->ExactPing * 0.001f, 0.0f, 1000.0f);
565 TimedBlockingRelease =
true;
570 if (!TimedBlockingRelease)
589 if (UWorld * OurWorld = GetWorld())
606 Script->EndPlay(EndPlayReason);
610 Super::EndPlay(EndPlayReason);
613bool AGrippableActor::Server_EndClientAuthReplication_Validate()
618void AGrippableActor::Server_EndClientAuthReplication_Implementation()
620 if (UWorld* World = GetWorld())
622 if (FPhysScene* PhysScene = World->GetPhysicsScene())
626 if (UPrimitiveComponent* RootPrim = Cast<UPrimitiveComponent>(GetRootComponent()))
628 PhysicsReplication->RemoveReplicatedTarget(RootPrim);
635bool AGrippableActor::Server_GetClientAuthReplication_Validate(
const FRepMovementVR & newMovement)
640void AGrippableActor::Server_GetClientAuthReplication_Implementation(
const FRepMovementVR & newMovement)
644 if (!newMovement.Location.ContainsNaN() && !newMovement.Rotation.ContainsNaN())
646 FRepMovement& MovementRep = GetReplicatedMovement_Mutable();
647 newMovement.
CopyTo(MovementRep);
663 const FRepAttachment ReplicationAttachment = GetAttachmentReplication();
664 if (!ReplicationAttachment.AttachParent)
671 if (RootComponent->IsSimulatingPhysics() != RepMove.bRepPhysics)
674 SyncReplicatedPhysicsSimulation();
681 Super::OnRep_ReplicateMovement();
692 Super::OnRep_ReplicatedMovement();
703 Super::PostNetReceivePhysicState();
708 Super::MarkComponentsAsPendingKill();
714 SubObject->MarkPendingKill();
725 Super::PreDestroyFromReplication();
732 OnSubobjectDestroyFromReplication(SubObject);
733 SubObject->PreDestroyFromReplication();
734 SubObject->MarkPendingKill();
741 if (ActorComp && !ActorComp->IsPendingKill() && ActorComp->GetClass()->ImplementsInterface(UVRGripInterface::StaticClass()))
742 ActorComp->PreDestroyFromReplication();
751 Super::BeginDestroy();
757 SubObject->MarkPendingKill();
766 Super::GetSubobjectsWithStableNamesForNetworking(ObjList);
774 ObjList.Add(SubObject);
EGripMovementReplicationSettings
UENUM(Blueprintable)
@ ForceClientSideMovement
ESecondaryGripType
UENUM(Blueprintable)
EGripCollisionType
UENUM(Blueprintable)
@ InteractiveCollisionWithPhysics
EGripLateUpdateSettings
UENUM(Blueprintable)
@ NotWhenCollidingOrDoubleGripping
EGripInterfaceTeleportBehavior
UENUM(Blueprintable)
UCLASS(Blueprintable, meta = (BlueprintSpawnableComponent), ClassGroup = (VRExpansionPlugin))
virtual void MarkComponentsAsPendingKill() override
bool bRepGripSettingsAndGameplayTags
UPROPERTY(EditAnywhere, Replicated, BlueprintReadWrite, Category = "VRGripInterface")
FGameplayTagContainer GameplayTags
UPROPERTY(EditAnywhere, Replicated, BlueprintReadWrite, Category = "GameplayTags")
virtual float GripBreakDistance_Implementation() override
TArray< class UVRGripScriptBase * > GripLogicScripts
UPROPERTY(EditAnywhere, Replicated, BlueprintReadOnly, Instanced, Category = "VRGripInterface")
virtual bool GetGripScripts_Implementation(TArray< UVRGripScriptBase * > &ArrayReference) override
FVRClientAuthReplicationData ClientAuthReplicationData
UPROPERTY(EditAnywhere, Replicated, BlueprintReadWrite, Category = "Replication")
void CeaseReplicationBlocking()
UFUNCTION(Category = "Networking")
virtual EGripLateUpdateSettings GripLateUpdateSetting_Implementation() override
virtual void GatherCurrentMovement() override
virtual bool SimulateOnDrop_Implementation() override
virtual void OnSecondaryGripRelease_Implementation(UGripMotionControllerComponent *GripOwningController, USceneComponent *ReleasingSecondaryGripComponent, const FBPActorGripInformation &GripInformation) override
virtual void OnChildGripRelease_Implementation(UGripMotionControllerComponent *ReleasingController, const FBPActorGripInformation &GripInformation, bool bWasSocketed=false) override
virtual void PreReplication(IRepChangedPropertyTracker &ChangedPropertyTracker) override
bool ShouldWeSkipAttachmentReplication(bool bConsiderHeld=true) const
virtual bool RequestsSocketing_Implementation(USceneComponent *&ParentToSocketTo, FName &OptionalSocketName, FTransform_NetQuantize &RelativeTransform) override
virtual void BeginPlay() override
void Server_GetClientAuthReplication(const FRepMovementVR &newMovement)
UFUNCTION(UnReliable, Server, WithValidation, Category = "Networking")
virtual void SetHeld_Implementation(UGripMotionControllerComponent *HoldingController, uint8 GripID, bool bIsHeld) override
virtual void PostNetReceivePhysicState() override
virtual bool AllowsMultipleGrips_Implementation() override
virtual void OnSecondaryUsed_Implementation() override
bool bReplicateGripScripts
UPROPERTY(EditAnywhere, Replicated, BlueprintReadWrite, Category = "VRGripInterface")
virtual void GetGripStiffnessAndDamping_Implementation(float &GripStiffnessOut, float &GripDampingOut) override
virtual EGripInterfaceTeleportBehavior TeleportBehavior_Implementation() override
void Server_EndClientAuthReplication()
UFUNCTION(Reliable, Server, WithValidation, Category = "Networking")
virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override
virtual void OnGrip_Implementation(UGripMotionControllerComponent *GrippingController, const FBPActorGripInformation &GripInformation) override
virtual void Native_NotifyThrowGripDelegates(UGripMotionControllerComponent *Controller, bool bGripped, const FBPActorGripInformation &GripInformation, bool bWasSocketed=false) override
bool ReplicateSubobjects(UActorChannel *Channel, class FOutBunch *Bunch, FReplicationFlags *RepFlags) override
virtual void OnInput_Implementation(FKey Key, EInputEvent KeyEvent) override
FVROnGripSignature OnSecondaryGripAdded
UPROPERTY(BlueprintAssignable, Category = "Grip Events")
virtual void OnRep_ReplicateMovement() override
virtual FBPAdvGripSettings AdvancedGripSettings_Implementation() override
bool PollReplicationEvent()
UFUNCTION()
FBPInterfaceProperties VRGripInterfaceSettings
UPROPERTY(EditAnywhere, Replicated, BlueprintReadWrite, Category = "VRGripInterface")
AGrippableActor(const FObjectInitializer &ObjectInitializer)
virtual void BeginDestroy() override
virtual void OnEndUsed_Implementation() override
virtual ESecondaryGripType SecondaryGripType_Implementation() override
virtual void OnRep_ReplicatedMovement() override
virtual void OnRep_AttachmentReplication() override
bool bAllowIgnoringAttachOnOwner
UPROPERTY(EditAnywhere, Replicated, BlueprintReadWrite, Category = "Replication")
bool RemoveFromClientReplicationBucket()
UFUNCTION(BlueprintCallable, Category = "Networking")
virtual void OnChildGrip_Implementation(UGripMotionControllerComponent *GrippingController, const FBPActorGripInformation &GripInformation) override
FVROnGripSignature OnSecondaryGripRemoved
UPROPERTY(BlueprintAssignable, Category = "Grip Events")
bool AddToClientReplicationBucket()
UFUNCTION(BlueprintCallable, Category = "Networking")
virtual void PreDestroyFromReplication() override
virtual void IsHeld_Implementation(TArray< FBPGripPair > &HoldingControllers, bool &bIsHeld) override
void SetDenyGripping(bool bDenyGripping)
UFUNCTION(BlueprintCallable, Category = "VRGripInterface")
virtual void ClosestGripSlotInRange_Implementation(FVector WorldLocation, bool bSecondarySlot, bool &bHadSlotInRange, FTransform &SlotWorldTransform, FName &SlotName, UGripMotionControllerComponent *CallingController=nullptr, FName OverridePrefix=NAME_None) override
FVROnDropSignature OnDropped
UPROPERTY(BlueprintAssignable, Category = "Grip Events")
virtual bool DenyGripping_Implementation(UGripMotionControllerComponent *GripInitiator=nullptr) override
virtual void OnGripRelease_Implementation(UGripMotionControllerComponent *ReleasingController, const FBPActorGripInformation &GripInformation, bool bWasSocketed=false) override
FVROnGripSignature OnGripped
UPROPERTY(BlueprintAssignable, Category = "Grip Events")
virtual void OnSecondaryGrip_Implementation(UGripMotionControllerComponent *GripOwningController, USceneComponent *SecondaryGripComponent, const FBPActorGripInformation &GripInformation) override
virtual void OnUsed_Implementation() override
FRepAttachmentWithWeld AttachmentWeldReplication
UPROPERTY(Replicated, ReplicatedUsing = OnRep_AttachmentReplication)
virtual void OnEndSecondaryUsed_Implementation() override
virtual void GetSubobjectsWithStableNamesForNetworking(TArray< UObject * > &ObjList) override
void SetGripPriority(int NewGripPriority)
UFUNCTION(BlueprintCallable, Category = "VRGripInterface")
virtual void TickGrip_Implementation(UGripMotionControllerComponent *GrippingController, const FBPActorGripInformation &GripInformation, float DeltaTime) override
virtual EGripMovementReplicationSettings GripMovementReplicationType_Implementation() override
virtual EGripCollisionType GetPrimaryGripType_Implementation(bool bIsSlot) override
UCLASS(Blueprintable, meta = (BlueprintSpawnableComponent), ClassGroup = MotionController)
bool IsLocallyControlled() const
static void GetGripSlotInRangeByTypeName(FName SlotType, AActor *Actor, FVector WorldLocation, float MaxRange, bool &bHadSlotInRange, FTransform &SlotWorldTransform, FName &SlotName, UGripMotionControllerComponent *QueryController=nullptr)
UFUNCTION(BlueprintPure, Category = "VRGrip", meta = (bIgnoreSelf = "true", DisplayName = "GetGripSlo...
UCLASS(NotBlueprintable, BlueprintType, EditInlineNew, DefaultToInstanced, Abstract,...
USTRUCT(BlueprintType, Category = "VRExpansionLibrary")
uint8 GripPriority
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "AdvancedGripSettings")
USTRUCT(BlueprintType, Category = "VRExpansionLibrary")
ESecondaryGripType SecondaryGripType
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRGripInterface")
bool bDenyGripping
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRGripInterface")
EGripCollisionType FreeDefaultGripType
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRGripInterface")
float ConstraintBreakDistance
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRGripInterface")
bool bAllowMultipleGrips
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRGripInterface")
float SecondarySlotRange
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRGripInterface")
EGripLateUpdateSettings LateUpdateSetting
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRGripInterface")
EGripCollisionType SlotDefaultGripType
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRGripInterface")
EGripInterfaceTeleportBehavior OnTeleportBehavior
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRGripInterface")
float ConstraintStiffness
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRGripInterface")
float PrimarySlotRange
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRGripInterface")
bool bIsHeld
UPROPERTY(BlueprintReadWrite, NotReplicated, Category = "VRGripInterface")
TArray< FBPGripPair > HoldingControllers
UPROPERTY(BlueprintReadWrite, NotReplicated, Category = "VRGripInterface")
float ConstraintDamping
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRGripInterface")
FBPAdvGripSettings AdvancedGripSettings
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRGripInterface|AdvancedGripSettings")
EGripMovementReplicationSettings MovementReplicationType
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRGripInterface")
bool bSimulateOnDrop
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRGripInterface")
bool bIsWelded
UPROPERTY()
void CopyTo(FRepMovement &other) const
bool GatherActorsMovement(AActor *OwningActor)
int32 UpdateRate
UPROPERTY(EditAnywhere, NotReplicated, BlueprintReadOnly, Category = "VRReplication",...
FTransform LastActorTransform
bool bUseClientAuthThrowing
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRReplication")
FTimerHandle ResetReplicationHandle
bool bIsCurrentlyClientAuth