4#include "TimerManager.h"
5#include "Net/UnrealNetwork.h"
6#include "PhysicsReplication.h"
8#include "Net/Core/PushModel/PushModel.h"
12 : Super(ObjectInitializer)
19 Super::PreReplication(ChangedPropertyTracker);
27void UOptionalRepSkeletalMeshComponent::GetLifetimeReplicatedProps(TArray< class FLifetimeProperty >& OutLifetimeProps)
const
29 Super::GetLifetimeReplicatedProps(OutLifetimeProps);
56 SetReplicatingMovement(
true);
65 MinNetUpdateFrequency = 30.0f;
68void AGrippableSkeletalMeshActor::GetLifetimeReplicatedProps(TArray< class FLifetimeProperty >& OutLifetimeProps)
const
70 Super::GetLifetimeReplicatedProps(OutLifetimeProps);
80 DISABLE_REPLICATED_PRIVATE_PROPERTY(
AActor, AttachmentReplication);
82 FDoRepLifetimeParams AttachmentReplicationParams{ COND_Custom, REPNOTIFY_Always,
true };
106 DOREPLIFETIME_ACTIVE_OVERRIDE_PRIVATE_PROPERTY(
AActor, ReplicatedMovement, IsReplicatingMovement());
112 DOREPLIFETIME_ACTIVE_OVERRIDE_PRIVATE_PROPERTY(
AActor, AttachmentReplication, RootComponent && !RootComponent->GetIsReplicated());
122 UBlueprintGeneratedClass* BPClass = Cast<UBlueprintGeneratedClass>(GetClass());
123 if (BPClass !=
nullptr)
125 BPClass->InstancePreReplication(
this, ChangedPropertyTracker);
131 if (IsReplicatingMovement() || (RootComponent && RootComponent->GetAttachParent()))
133 bool bWasAttachmentModified =
false;
134 bool bWasRepMovementModified =
false;
142 FRepMovement& RepMovement = GetReplicatedMovement_Mutable();
144 UPrimitiveComponent* RootPrimComp = Cast<UPrimitiveComponent>(GetRootComponent());
145 if (RootPrimComp && RootPrimComp->IsSimulatingPhysics())
147 FRigidBodyState RBState;
148 RootPrimComp->GetRigidBodyState(RBState);
150 RepMovement.FillFrom(RBState,
this);
153 RepMovement.bRepPhysics = !RootPrimComp->IsWelded();
155 if (!RepMovement.bRepPhysics)
157 if (RootComponent->GetAttachParent() !=
nullptr)
172 bWasAttachmentModified =
true;
178 bWasRepMovementModified =
true;
180 else if (RootComponent !=
nullptr)
183 if (RootComponent->GetAttachParent() !=
nullptr)
198 bWasAttachmentModified =
true;
203 RepMovement.Location = FRepMovement::RebaseOntoZeroOrigin(RootComponent->GetComponentLocation(),
this);
204 RepMovement.Rotation = RootComponent->GetComponentRotation();
205 RepMovement.LinearVelocity = GetVelocity();
206 RepMovement.AngularVelocity = FVector::ZeroVector;
209 bWasRepMovementModified =
true;
212 bWasRepMovementModified = (bWasRepMovementModified || RepMovement.bRepPhysics);
213 RepMovement.bRepPhysics =
false;
216 if (bWasRepMovementModified)
221 if (bWasAttachmentModified ||
233 bool WroteSomething = Super::ReplicateSubobjects(Channel, Bunch, RepFlags);
239 if (Script && !Script->IsPendingKill())
241 WroteSomething |= Channel->ReplicateSubobject(Script, *Bunch, *RepFlags);
246 return WroteSomething;
269 Script->BeginPlay(
this);
352 if (OverridePrefix.IsNone())
353 bSecondarySlot ? OverridePrefix =
"VRGripS" : OverridePrefix =
"VRGripP";
377 if (UWorld* World = GetWorld())
390 GetWorld()->GetSubsystem<
UBucketUpdateSubsystem>()->RemoveObjectFromBucketByFunctionName(
this,
FName(TEXT(
"PollReplicationEvent")));
427 bool bWasLocallyOwned = HoldingController ? HoldingController->
IsLocallyControlled() :
false;
430 if (UPrimitiveComponent* PrimComp = Cast<UPrimitiveComponent>(GetRootComponent()))
432 if (PrimComp->IsSimulatingPhysics())
458 UWorld* OurWorld = GetWorld();
462 bool bRemoveBlocking =
false;
469 bRemoveBlocking =
true;
473 FTransform CurTransform = this->GetActorTransform();
475 if (!bRemoveBlocking)
481 if (UPrimitiveComponent* PrimComp = Cast<UPrimitiveComponent>(RootComponent))
491 if (PrimComp->RigidBodyIsAwake())
500 bRemoveBlocking =
true;
511 bool TimedBlockingRelease =
false;
513 AActor* TopOwner = GetOwner();
514 if (TopOwner !=
nullptr)
516 AActor* tempOwner = TopOwner->GetOwner();
521 TopOwner = tempOwner;
522 tempOwner = TopOwner->GetOwner();
527 if (APlayerState* PlayerState = PlayerController->PlayerState)
535 float clampedPing = FMath::Clamp(PlayerState->ExactPing * 0.001f, 0.0f, 1000.0f);
537 TimedBlockingRelease =
true;
542 if (!TimedBlockingRelease)
561 if (UWorld* OurWorld = GetWorld())
577 Script->EndPlay(EndPlayReason);
581 Super::EndPlay(EndPlayReason);
584bool AGrippableSkeletalMeshActor::Server_EndClientAuthReplication_Validate()
589void AGrippableSkeletalMeshActor::Server_EndClientAuthReplication_Implementation()
591 if (UWorld* World = GetWorld())
593 if (FPhysScene* PhysScene = World->GetPhysicsScene())
597 PhysicsReplication->RemoveReplicatedTarget(this->GetSkeletalMeshComponent());
603bool AGrippableSkeletalMeshActor::Server_GetClientAuthReplication_Validate(
const FRepMovementVR& newMovement)
608void AGrippableSkeletalMeshActor::Server_GetClientAuthReplication_Implementation(
const FRepMovementVR& newMovement)
612 if (!newMovement.Location.ContainsNaN() && !newMovement.Rotation.ContainsNaN())
614 FRepMovement& MovementRep = GetReplicatedMovement_Mutable();
615 newMovement.
CopyTo(MovementRep);
635 if (AttachParentComponent)
645 const bool bAlreadyAttached = (AttachParentComponent == RootComponent->GetAttachParent() &&
AttachmentWeldReplication.AttachSocket == RootComponent->GetAttachSocketName() && AttachParentComponent->GetAttachChildren().Contains(RootComponent));
646 if (bAlreadyAttached)
649 RootComponent->UpdateComponentToWorld(EUpdateTransformFlags::SkipPhysicsUpdate, ETeleportType::None);
653 FAttachmentTransformRules attachRules = FAttachmentTransformRules::KeepRelativeTransform;
662 DetachFromActor(FDetachmentTransformRules::KeepWorldTransform);
667 if (IsReplicatingMovement())
684 const FRepAttachment ReplicationAttachment = GetAttachmentReplication();
685 if (!ReplicationAttachment.AttachParent)
692 if (RootComponent->IsSimulatingPhysics() != RepMove.bRepPhysics)
695 SyncReplicatedPhysicsSimulation();
702 Super::OnRep_ReplicateMovement();
713 Super::OnRep_ReplicatedMovement();
724 Super::PostNetReceivePhysicState();
729 Super::MarkComponentsAsPendingKill();
735 SubObject->MarkPendingKill();
744 Super::PreDestroyFromReplication();
751 OnSubobjectDestroyFromReplication(SubObject);
752 SubObject->PreDestroyFromReplication();
753 SubObject->MarkPendingKill();
760 if (ActorComp && !ActorComp->IsPendingKill() && ActorComp->GetClass()->ImplementsInterface(UVRGripInterface::StaticClass()))
761 ActorComp->PreDestroyFromReplication();
769 Super::BeginDestroy();
775 SubObject->MarkPendingKill();
784 Super::GetSubobjectsWithStableNamesForNetworking(ObjList);
792 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, ChildCanTick), ClassGroup = (VRExpansionPl...
virtual void OnEndUsed_Implementation() override
virtual void IsHeld_Implementation(TArray< FBPGripPair > &HoldingControllers, bool &bIsHeld) override
FVROnGripSignature OnSecondaryGripAdded
UPROPERTY(BlueprintAssignable, Category = "Grip Events")
virtual bool GetGripScripts_Implementation(TArray< UVRGripScriptBase * > &ArrayReference) override
virtual void SetHeld_Implementation(UGripMotionControllerComponent *HoldingController, uint8 GripID, bool bIsHeld) override
void Server_GetClientAuthReplication(const FRepMovementVR &newMovement)
UFUNCTION(UnReliable, Server, WithValidation, Category = "Networking")
virtual void OnRep_AttachmentReplication() override
virtual void Native_NotifyThrowGripDelegates(UGripMotionControllerComponent *Controller, bool bGripped, const FBPActorGripInformation &GripInformation, bool bWasSocketed=false) override
virtual void OnEndSecondaryUsed_Implementation() override
bool ReplicateSubobjects(UActorChannel *Channel, class FOutBunch *Bunch, FReplicationFlags *RepFlags) override
FRepAttachmentWithWeld AttachmentWeldReplication
UPROPERTY(Replicated, ReplicatedUsing = OnRep_AttachmentReplication)
~AGrippableSkeletalMeshActor()
virtual EGripCollisionType GetPrimaryGripType_Implementation(bool bIsSlot) override
virtual void OnChildGrip_Implementation(UGripMotionControllerComponent *GrippingController, const FBPActorGripInformation &GripInformation) override
void SetGripPriority(int NewGripPriority)
UFUNCTION(BlueprintCallable, Category = "VRGripInterface")
void SetDenyGripping(bool bDenyGripping)
UFUNCTION(BlueprintCallable, Category = "VRGripInterface")
virtual ESecondaryGripType SecondaryGripType_Implementation() override
virtual EGripLateUpdateSettings GripLateUpdateSetting_Implementation() override
bool RemoveFromClientReplicationBucket()
UFUNCTION(BlueprintCallable, Category = "Networking")
virtual EGripInterfaceTeleportBehavior TeleportBehavior_Implementation() override
FBPInterfaceProperties VRGripInterfaceSettings
UPROPERTY(EditAnywhere, Replicated, BlueprintReadWrite, Category = "VRGripInterface")
virtual void ClosestGripSlotInRange_Implementation(FVector WorldLocation, bool bSecondarySlot, bool &bHadSlotInRange, FTransform &SlotWorldTransform, FName &SlotName, UGripMotionControllerComponent *CallingController=nullptr, FName OverridePrefix=NAME_None) override
bool bReplicateGripScripts
UPROPERTY(EditAnywhere, Replicated, BlueprintReadWrite, Category = "VRGripInterface")
virtual float GripBreakDistance_Implementation() override
AGrippableSkeletalMeshActor(const FObjectInitializer &ObjectInitializer)
virtual bool RequestsSocketing_Implementation(USceneComponent *&ParentToSocketTo, FName &OptionalSocketName, FTransform_NetQuantize &RelativeTransform) override
virtual void OnGrip_Implementation(UGripMotionControllerComponent *GrippingController, const FBPActorGripInformation &GripInformation) override
bool PollReplicationEvent()
UFUNCTION()
virtual void OnRep_ReplicateMovement() override
virtual void BeginDestroy() override
virtual EGripMovementReplicationSettings GripMovementReplicationType_Implementation() override
virtual void TickGrip_Implementation(UGripMotionControllerComponent *GrippingController, const FBPActorGripInformation &GripInformation, float DeltaTime) override
bool AddToClientReplicationBucket()
UFUNCTION(BlueprintCallable, Category = "Networking")
FVROnGripSignature OnGripped
UPROPERTY(BlueprintAssignable, Category = "Grip Events")
virtual bool DenyGripping_Implementation(UGripMotionControllerComponent *GripInitiator=nullptr) override
virtual void MarkComponentsAsPendingKill() override
virtual void OnSecondaryUsed_Implementation() override
virtual void OnChildGripRelease_Implementation(UGripMotionControllerComponent *ReleasingController, const FBPActorGripInformation &GripInformation, bool bWasSocketed=false) override
void Server_EndClientAuthReplication()
UFUNCTION(Reliable, Server, WithValidation, Category = "Networking")
virtual void PreReplication(IRepChangedPropertyTracker &ChangedPropertyTracker) override
virtual void PostNetReceivePhysicState() override
virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override
virtual bool AllowsMultipleGrips_Implementation() override
virtual void OnGripRelease_Implementation(UGripMotionControllerComponent *ReleasingController, const FBPActorGripInformation &GripInformation, bool bWasSocketed=false) override
bool bAllowIgnoringAttachOnOwner
UPROPERTY(EditAnywhere, Replicated, BlueprintReadWrite, Category = "Replication")
virtual void OnSecondaryGripRelease_Implementation(UGripMotionControllerComponent *GripOwningController, USceneComponent *ReleasingSecondaryGripComponent, const FBPActorGripInformation &GripInformation) override
virtual FBPAdvGripSettings AdvancedGripSettings_Implementation() override
virtual void GetSubobjectsWithStableNamesForNetworking(TArray< UObject * > &ObjList) override
virtual void OnRep_ReplicatedMovement() override
void CeaseReplicationBlocking()
UFUNCTION(Category = "Networking")
FGameplayTagContainer GameplayTags
UPROPERTY(EditAnywhere, Replicated, BlueprintReadWrite, Category = "GameplayTags")
virtual void PreDestroyFromReplication() override
FVROnGripSignature OnSecondaryGripRemoved
UPROPERTY(BlueprintAssignable, Category = "Grip Events")
FVRClientAuthReplicationData ClientAuthReplicationData
UPROPERTY(EditAnywhere, Replicated, BlueprintReadWrite, Category = "Replication")
bool bRepGripSettingsAndGameplayTags
UPROPERTY(EditAnywhere, Replicated, BlueprintReadWrite, Category = "VRGripInterface")
virtual void OnSecondaryGrip_Implementation(UGripMotionControllerComponent *GripOwningController, USceneComponent *SecondaryGripComponent, const FBPActorGripInformation &GripInformation) override
bool ShouldWeSkipAttachmentReplication(bool bConsiderHeld=true) const
TArray< class UVRGripScriptBase * > GripLogicScripts
UPROPERTY(EditAnywhere, Replicated, BlueprintReadOnly, Instanced, Category = "VRGripInterface")
virtual void OnInput_Implementation(FKey Key, EInputEvent KeyEvent) override
virtual void GetGripStiffnessAndDamping_Implementation(float &GripStiffnessOut, float &GripDampingOut) override
virtual bool SimulateOnDrop_Implementation() override
virtual void GatherCurrentMovement() override
virtual void BeginPlay() override
virtual void OnUsed_Implementation() override
FVROnDropSignature OnDropped
UPROPERTY(BlueprintAssignable, Category = "Grip Events")
UCLASS(Blueprintable, meta = (BlueprintSpawnableComponent), ClassGroup = MotionController)
bool IsLocallyControlled() const
UCLASS(Blueprintable, meta = (BlueprintSpawnableComponent, ChildCanTick), ClassGroup = (VRExpansionPl...
UOptionalRepSkeletalMeshComponent(const FObjectInitializer &ObjectInitializer)
virtual void PreReplication(IRepChangedPropertyTracker &ChangedPropertyTracker) override
bool bReplicateMovement
UPROPERTY(EditAnywhere, Replicated, BlueprintReadWrite, Category = "Component Replication")
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