diff --git a/VIRTUOS_ExpansionPluginTests/Content/MainMenu/UI_Materials/M_UI_Liquid_Fill_Button.uasset b/VIRTUOS_ExpansionPluginTests/Content/MainMenu/UI_Materials/M_UI_Liquid_Fill_Button.uasset index 9227bf1..6c6f429 100644 --- a/VIRTUOS_ExpansionPluginTests/Content/MainMenu/UI_Materials/M_UI_Liquid_Fill_Button.uasset +++ b/VIRTUOS_ExpansionPluginTests/Content/MainMenu/UI_Materials/M_UI_Liquid_Fill_Button.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:6dde92852cd71f6dc10b38fdc6f97832511dac6b867cd7c4b51f0a897e33dd2e -size 177546 +oid sha256:dcfddac0c1e1472968260ba0faf59c6cc156211507ccd94f3914fdf8a4af7617 +size 181122 diff --git a/VIRTUOS_ExpansionPluginTests/Content/Maps/Map_MainMenu.umap b/VIRTUOS_ExpansionPluginTests/Content/Maps/Map_MainMenu.umap index 6261ca2..ecccbf0 100644 --- a/VIRTUOS_ExpansionPluginTests/Content/Maps/Map_MainMenu.umap +++ b/VIRTUOS_ExpansionPluginTests/Content/Maps/Map_MainMenu.umap @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:c7fbcd793cc181306472cb283d0a5d29673f19d8b655159f658766bd21afff06 +oid sha256:9d98681f69583541cb87f4085e82a5ba148ff8ac6968fa38b30c952bf3417f0d size 60883 diff --git a/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Private/CharacterMovementCompTypes.cpp b/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Private/CharacterMovementCompTypes.cpp index d9ec7ab..3ae2705 100644 --- a/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Private/CharacterMovementCompTypes.cpp +++ b/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Private/CharacterMovementCompTypes.cpp @@ -369,7 +369,7 @@ bool FVRCharacterNetworkMoveData::Serialize(UCharacterMovementComponent& Charact if (AVRBaseCharacter* BaseChar = Cast(CharacterOwner)) { - if (!BaseChar->VRMovementReference->bUseClientControlRotation) + if (BaseChar->VRMovementReference && !BaseChar->VRMovementReference->bUseClientControlRotation) { bRepRollAndPitch = (Roll != 0 || Pitch != 0); } diff --git a/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Private/GripMotionControllerComponent.cpp b/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Private/GripMotionControllerComponent.cpp index a674394..2009dcc 100644 --- a/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Private/GripMotionControllerComponent.cpp +++ b/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Private/GripMotionControllerComponent.cpp @@ -6718,25 +6718,15 @@ bool UGripMotionControllerComponent::SetGripConstraintStiffnessAndDamping(const } else { - if (VRSettings.bUseChaosTranslationScalers) - { - Stiffness *= VRSettings.LinearDriveStiffnessScale; - Damping *= VRSettings.LinearDriveDampingScale; - AngularStiffness *= VRSettings.AngularDriveStiffnessScale; - AngularDamping *= VRSettings.AngularDriveDampingScale; - } - else - { - auto CVarLinearDriveStiffnessScale = IConsoleManager::Get().FindConsoleVariable(TEXT("p.Chaos.JointConstraint.LinearDriveStiffnessScale")); - auto CVarLinearDriveDampingScale = IConsoleManager::Get().FindConsoleVariable(TEXT("p.Chaos.JointConstraint.LinaearDriveDampingScale")); - auto CVarAngularDriveStiffnessScale = IConsoleManager::Get().FindConsoleVariable(TEXT("p.Chaos.JointConstraint.AngularDriveStiffnessScale")); - auto CVarAngularDriveDampingScale = IConsoleManager::Get().FindConsoleVariable(TEXT("p.Chaos.JointConstraint.AngularDriveDampingScale")); + auto CVarLinearDriveStiffnessScale = IConsoleManager::Get().FindConsoleVariable(TEXT("p.Chaos.JointConstraint.LinearDriveStiffnessScale")); + auto CVarLinearDriveDampingScale = IConsoleManager::Get().FindConsoleVariable(TEXT("p.Chaos.JointConstraint.LinaearDriveDampingScale")); + auto CVarAngularDriveStiffnessScale = IConsoleManager::Get().FindConsoleVariable(TEXT("p.Chaos.JointConstraint.AngularDriveStiffnessScale")); + auto CVarAngularDriveDampingScale = IConsoleManager::Get().FindConsoleVariable(TEXT("p.Chaos.JointConstraint.AngularDriveDampingScale")); - Stiffness *= CVarLinearDriveStiffnessScale->GetFloat(); - Damping *= CVarLinearDriveDampingScale->GetFloat(); - AngularStiffness *= CVarAngularDriveStiffnessScale->GetFloat(); - AngularDamping *= CVarAngularDriveDampingScale->GetFloat(); - } + Stiffness *= CVarLinearDriveStiffnessScale->GetFloat(); + Damping *= CVarLinearDriveDampingScale->GetFloat(); + AngularStiffness *= CVarAngularDriveStiffnessScale->GetFloat(); + AngularDamping *= CVarAngularDriveDampingScale->GetFloat(); } AngularMaxForce = (float)FMath::Clamp((double)AngularStiffness * (double)Grip->AdvancedGripSettings.PhysicsSettings.AngularMaxForceCoefficient, 0, (double)MAX_FLT); diff --git a/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Private/GripScripts/GS_GunTools.cpp b/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Private/GripScripts/GS_GunTools.cpp index 884fd33..21f2762 100644 --- a/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Private/GripScripts/GS_GunTools.cpp +++ b/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Private/GripScripts/GS_GunTools.cpp @@ -513,8 +513,11 @@ void UGS_GunTools::GetVirtualStockTarget(UGripMotionControllerComponent * Grippi { if (AVRBaseCharacter * vrOwner = Cast(GrippingController->GetOwner())) { - CameraComponent = vrOwner->VRReplicatedCamera; - return; + if (vrOwner->VRReplicatedCamera) + { + CameraComponent = vrOwner->VRReplicatedCamera; + return; + } } else { diff --git a/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Private/GripScripts/VRGripScriptBase.cpp b/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Private/GripScripts/VRGripScriptBase.cpp index fdb052d..2b91220 100644 --- a/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Private/GripScripts/VRGripScriptBase.cpp +++ b/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Private/GripScripts/VRGripScriptBase.cpp @@ -9,8 +9,13 @@ #include "Components/PrimitiveComponent.h" #include "GameFramework/Actor.h" #include "Net/UnrealNetwork.h" +#include "Net/Core/PushModel/PushModel.h" #include "Engine/NetDriver.h" +#if UE_WITH_IRIS +#include "Iris/ReplicationSystem/ReplicationFragmentUtil.h" +#endif // UE_WITH_IRIS + UVRGripScriptBase::UVRGripScriptBase(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer) @@ -69,6 +74,18 @@ UVRGripScriptBase* UVRGripScriptBase::GetGripScriptByClass(UObject* WorldContext return nullptr; } +#if UE_WITH_IRIS +void UVRGripScriptBase::RegisterReplicationFragments(UE::Net::FFragmentRegistrationContext& Context, UE::Net::EFragmentRegistrationFlags RegistrationFlags) +{ + using namespace UE::Net; + + Super::RegisterReplicationFragments(Context, RegistrationFlags); + + // Build descriptors and allocate PropertyReplicationFragments for this object + FReplicationFragmentUtil::CreateAndRegisterFragmentsForObject(this, Context, RegistrationFlags); +} +#endif // UE_WITH_IRIS + void UVRGripScriptBase::GetLifetimeReplicatedProps(TArray< class FLifetimeProperty > & OutLifetimeProps) const { // Uobject has no replicated props @@ -80,6 +97,56 @@ void UVRGripScriptBase::GetLifetimeReplicatedProps(TArray< class FLifetimeProper { BPClass->GetLifetimeBlueprintReplicationList(OutLifetimeProps); } + + FDoRepLifetimeParams SharedParams; + SharedParams.bIsPushBased = true; + + DOREPLIFETIME_WITH_PARAMS(UVRGripScriptBase, bReplicates, SharedParams); +} + +void UVRGripScriptBase::SetIsReplicated(bool bShouldReplicate) +{ + if (GetIsReplicated() != bShouldReplicate) + { + bReplicates = bShouldReplicate; + + FBoolProperty* BoolProperty = CastField(this->GetClass()->FindPropertyByName("bReplicates")); + MARK_PROPERTY_DIRTY(this, BoolProperty); + //MARK_PROPERTY_DIRTY_FROM_NAME(UVRGripScriptBase, bReplicates, this); + + // Remove us from the subobject replication list if we need to be + if (AActor* OwningActor = Cast(GetParent())) + { + if (OwningActor->IsUsingRegisteredSubObjectList()) + { + if (bReplicates) + { + if (!OwningActor->IsReplicatedSubObjectRegistered(this)) + { + OwningActor->AddReplicatedSubObject(this); + } + } + else if(OwningActor->IsReplicatedSubObjectRegistered(this)) + { + OwningActor->RemoveReplicatedSubObject(this); + } + } + } + else if (UActorComponent* OwningComp = Cast(GetParent())) + { + if (bReplicates) + { + if (!OwningComp->IsReplicatedSubObjectRegistered(this)) + { + OwningComp->AddReplicatedSubObject(this); + } + } + else if (OwningComp->IsReplicatedSubObjectRegistered(this)) + { + OwningComp->RemoveReplicatedSubObject(this); + } + } + } } void UVRGripScriptBase::Tick(float DeltaTime) @@ -320,14 +387,73 @@ UWorld* UVRGripScriptBase::GetWorld() const void UVRGripScriptBase::EndPlay(const EEndPlayReason::Type EndPlayReason) { + // Remove us from the subobject replication list if we need to be + if (AActor* OwningActor = Cast(GetParent())) + { + if (OwningActor->IsUsingRegisteredSubObjectList()) + { + OwningActor->RemoveReplicatedSubObject(this); + } + } + else if (UActorComponent* OwningComp = Cast(GetParent())) + { + if (OwningComp->IsUsingRegisteredSubObjectList()) + { + OwningComp->RemoveReplicatedSubObject(this); + } + } + OnEndPlay(EndPlayReason); } +void UVRGripScriptBase::BeginDestroy() +{ + Super::BeginDestroy(); + + if (bReplicates) + { + // Remove us from the subobject replication list if we need to be + if (AActor* OwningActor = Cast(GetParent())) + { + if (OwningActor->IsUsingRegisteredSubObjectList()) + { + OwningActor->RemoveReplicatedSubObject(this); + } + } + else if (UActorComponent* OwningComp = Cast(GetParent())) + { + if (OwningComp->IsUsingRegisteredSubObjectList()) + { + OwningComp->RemoveReplicatedSubObject(this); + } + } + } +} + void UVRGripScriptBase::BeginPlay(UObject * CallingOwner) { if (bAlreadyNotifiedPlay) return; + if (bReplicates) + { + // Register us to the subobject replication list if we need to be + if (AActor* OwningActor = Cast(CallingOwner)) + { + if (OwningActor->IsUsingRegisteredSubObjectList()) + { + OwningActor->AddReplicatedSubObject(this, ReplicationCondition); + } + } + else if (UActorComponent* OwningComp = Cast(CallingOwner)) + { + if (OwningComp->IsUsingRegisteredSubObjectList()) + { + OwningComp->AddReplicatedSubObject(this, ReplicationCondition); + } + } + } + bAlreadyNotifiedPlay = true; // Notify the subscripts about begin play @@ -338,14 +464,17 @@ void UVRGripScriptBase::PostInitProperties() { Super::PostInitProperties(); - //Called in game, when World exist . BeginPlay will not be called in editor - if (GetWorld()) + if (bReplicates) { - if (AActor* Owner = GetOwner()) + //Called in game, when World exist . BeginPlay will not be called in editor + if (GetWorld()) { - if (Owner->IsActorInitialized()) + if (AActor* Owner = GetOwner()) { - BeginPlay(GetOwner()); + if (Owner->IsActorInitialized()) + { + BeginPlay(GetParent()); + } } } } diff --git a/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Private/Grippables/GrippableActor.cpp b/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Private/Grippables/GrippableActor.cpp index d572da3..0e30a65 100644 --- a/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Private/Grippables/GrippableActor.cpp +++ b/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Private/Grippables/GrippableActor.cpp @@ -311,7 +311,7 @@ bool AGrippableActor::ReplicateSubobjects(UActorChannel* Channel, class FOutBunc { bool WroteSomething = Super::ReplicateSubobjects(Channel, Bunch, RepFlags); - if (bReplicateGripScripts) + if (bReplicateGripScripts && !IsUsingRegisteredSubObjectList()) { for (UVRGripScriptBase* Script : GripLogicScripts) { diff --git a/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Private/Grippables/GrippableBoxComponent.cpp b/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Private/Grippables/GrippableBoxComponent.cpp index 9cc70c6..235959a 100644 --- a/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Private/Grippables/GrippableBoxComponent.cpp +++ b/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Private/Grippables/GrippableBoxComponent.cpp @@ -73,7 +73,7 @@ bool UGrippableBoxComponent::ReplicateSubobjects(UActorChannel* Channel, class F { bool WroteSomething = Super::ReplicateSubobjects(Channel, Bunch, RepFlags); - if (bReplicateGripScripts) + if (bReplicateGripScripts && !IsUsingRegisteredSubObjectList()) { for (UVRGripScriptBase* Script : GripLogicScripts) { diff --git a/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Private/Grippables/GrippableCapsuleComponent.cpp b/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Private/Grippables/GrippableCapsuleComponent.cpp index 3fe4901..bbb8853 100644 --- a/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Private/Grippables/GrippableCapsuleComponent.cpp +++ b/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Private/Grippables/GrippableCapsuleComponent.cpp @@ -69,7 +69,7 @@ bool UGrippableCapsuleComponent::ReplicateSubobjects(UActorChannel* Channel, cla { bool WroteSomething = Super::ReplicateSubobjects(Channel, Bunch, RepFlags); - if (bReplicateGripScripts) + if (bReplicateGripScripts && !IsUsingRegisteredSubObjectList()) { for (UVRGripScriptBase* Script : GripLogicScripts) { diff --git a/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Private/Grippables/GrippableSkeletalMeshComponent.cpp b/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Private/Grippables/GrippableSkeletalMeshComponent.cpp index 6e9dfad..c9781fa 100644 --- a/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Private/Grippables/GrippableSkeletalMeshComponent.cpp +++ b/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Private/Grippables/GrippableSkeletalMeshComponent.cpp @@ -70,7 +70,7 @@ bool UGrippableSkeletalMeshComponent::ReplicateSubobjects(UActorChannel* Channel { bool WroteSomething = Super::ReplicateSubobjects(Channel, Bunch, RepFlags); - if (bReplicateGripScripts) + if (bReplicateGripScripts && !IsUsingRegisteredSubObjectList()) { for (UVRGripScriptBase* Script : GripLogicScripts) { diff --git a/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Private/Grippables/GrippableSphereComponent.cpp b/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Private/Grippables/GrippableSphereComponent.cpp index 3cebb3c..3e22391 100644 --- a/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Private/Grippables/GrippableSphereComponent.cpp +++ b/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Private/Grippables/GrippableSphereComponent.cpp @@ -68,7 +68,7 @@ bool UGrippableSphereComponent::ReplicateSubobjects(UActorChannel* Channel, clas { bool WroteSomething = Super::ReplicateSubobjects(Channel, Bunch, RepFlags); - if (bReplicateGripScripts) + if (bReplicateGripScripts && !IsUsingRegisteredSubObjectList()) { for (UVRGripScriptBase* Script : GripLogicScripts) { diff --git a/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Private/Grippables/GrippableStaticMeshActor.cpp b/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Private/Grippables/GrippableStaticMeshActor.cpp index 623d7d7..3ca4bde 100644 --- a/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Private/Grippables/GrippableStaticMeshActor.cpp +++ b/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Private/Grippables/GrippableStaticMeshActor.cpp @@ -306,7 +306,7 @@ bool AGrippableStaticMeshActor::ReplicateSubobjects(UActorChannel* Channel, clas { bool WroteSomething = Super::ReplicateSubobjects(Channel, Bunch, RepFlags); - if (bReplicateGripScripts) + if (bReplicateGripScripts && !IsUsingRegisteredSubObjectList()) { for (UVRGripScriptBase* Script : GripLogicScripts) { diff --git a/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Private/Grippables/GrippableStaticMeshComponent.cpp b/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Private/Grippables/GrippableStaticMeshComponent.cpp index dafe174..77ca8fe 100644 --- a/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Private/Grippables/GrippableStaticMeshComponent.cpp +++ b/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Private/Grippables/GrippableStaticMeshComponent.cpp @@ -69,7 +69,7 @@ bool UGrippableStaticMeshComponent::ReplicateSubobjects(UActorChannel* Channel, { bool WroteSomething = Super::ReplicateSubobjects(Channel, Bunch, RepFlags); - if (bReplicateGripScripts) + if (bReplicateGripScripts && !IsUsingRegisteredSubObjectList()) { for (UVRGripScriptBase* Script : GripLogicScripts) { diff --git a/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Private/Grippables/HandSocketComponent.cpp b/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Private/Grippables/HandSocketComponent.cpp index 6ae26ca..dfbdd58 100644 --- a/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Private/Grippables/HandSocketComponent.cpp +++ b/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Private/Grippables/HandSocketComponent.cpp @@ -90,6 +90,69 @@ UAnimSequence* UHandSocketComponent::GetTargetAnimation() return HandTargetAnimation; } +void UHandSocketComponent::GetAllHandSocketComponents(TArray& OutHandSockets) +{ + for (TObjectIterator It; It; ++It) + { + UHandSocketComponent* HandSocket = *It; + if (IsValid(HandSocket) && !HandSocket->IsTemplate()) + { + OutHandSockets.Add(HandSocket); + } + } +} + +bool UHandSocketComponent::GetAllHandSocketComponentsInRange(FVector SearchFromWorldLocation, float SearchRange, TArray& OutHandSockets) +{ + float SearchDistSq = FMath::Square(SearchRange); + + UHandSocketComponent* HandSocket = nullptr; + FTransform HandSocketTrans; + for (TObjectIterator It; It; ++It) + { + HandSocket = *It; + if (IsValid(HandSocket) && !HandSocket->IsTemplate()) + { + HandSocketTrans = HandSocket->GetRelativeTransform() * HandSocket->GetOwner()->GetActorTransform(); + if (FVector::DistSquared(HandSocketTrans.GetLocation(), SearchFromWorldLocation) <= SearchDistSq) + { + OutHandSockets.Add(HandSocket); + } + } + } + + return OutHandSockets.Num() > 0; +} + +UHandSocketComponent* UHandSocketComponent::GetClosestHandSocketComponentInRange(FVector SearchFromWorldLocation, float SearchRange) +{ + float SearchDistSq = FMath::Square(SearchRange); + UHandSocketComponent* ClosestHandSocket = nullptr; + float LastDist = 0.0f; + float DistSq = 0.0f; + + bool bFoundOne = false; + UHandSocketComponent* HandSocket = nullptr; + FTransform HandSocketTrans; + for (TObjectIterator It; It; ++It) + { + HandSocket = *It; + if (IsValid(HandSocket) && !HandSocket->IsTemplate()) + { + HandSocketTrans = HandSocket->GetRelativeTransform() * HandSocket->GetOwner()->GetActorTransform(); + DistSq = FVector::DistSquared(HandSocketTrans.GetLocation(), SearchFromWorldLocation); + if (DistSq <= SearchDistSq && (!bFoundOne || DistSq < LastDist)) + { + bFoundOne = true; + ClosestHandSocket = HandSocket; + LastDist = DistSq; + } + } + } + + return ClosestHandSocket; +} + bool UHandSocketComponent::GetAnimationSequenceAsPoseSnapShot(UAnimSequence* InAnimationSequence, FPoseSnapshot& OutPoseSnapShot, USkeletalMeshComponent* TargetMesh, bool bSkipRootBone, bool bFlipHand) { if (InAnimationSequence) diff --git a/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Private/Interactibles/VRLeverComponent.cpp b/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Private/Interactibles/VRLeverComponent.cpp index 93093d8..f6a63a0 100644 --- a/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Private/Interactibles/VRLeverComponent.cpp +++ b/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Private/Interactibles/VRLeverComponent.cpp @@ -677,8 +677,8 @@ void UVRLeverComponent::CalculateCurrentAngle(FTransform & CurrentTransform) FullCurrentAngle = FMath::RadiansToDegrees(FMath::Acos(FVector::DotProduct(UpVec, FVector::UpVector))); CurrentLeverAngle = FMath::RoundToFloat(FullCurrentAngle); - AllCurrentLeverAngles.Roll = FMath::Sign(UpVec.Y) * FMath::RadiansToDegrees(FMath::Acos(FVector::DotProduct(FVector(0.0f, UpVec.Y, UpVec.Z), FVector::UpVector))); - AllCurrentLeverAngles.Pitch = FMath::Sign(UpVec.X) * FMath::RadiansToDegrees(FMath::Acos(FVector::DotProduct(FVector(UpVec.X, 0.0f, UpVec.Z), FVector::UpVector))); + AllCurrentLeverAngles.Roll = FMath::Sign(UpVec.Y) * FMath::RadiansToDegrees(FMath::Acos(FVector::DotProduct(FVector(0.0f, UpVec.Y, UpVec.Z).GetSafeNormal(), FVector::UpVector))); + AllCurrentLeverAngles.Pitch = FMath::Sign(UpVec.X) * FMath::RadiansToDegrees(FMath::Acos(FVector::DotProduct(FVector(UpVec.X, 0.0f, UpVec.Z).GetSafeNormal(), FVector::UpVector))); if (bBlendAxisValuesByAngleThreshold) { diff --git a/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Private/ParentRelativeAttachmentComponent.cpp b/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Private/ParentRelativeAttachmentComponent.cpp index 4dbb9ed..6dc37e9 100644 --- a/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Private/ParentRelativeAttachmentComponent.cpp +++ b/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Private/ParentRelativeAttachmentComponent.cpp @@ -50,7 +50,7 @@ void UParentRelativeAttachmentComponent::InitializeComponent() Super::InitializeComponent(); // Update our tracking - if (!bUseFeetLocation && IsValid(AttachChar)) // New case to early out and with less calculations + if (!bUseFeetLocation && IsValid(AttachChar) && IsValid(AttachChar->VRReplicatedCamera)) // New case to early out and with less calculations { SetRelativeTransform(AttachChar->VRReplicatedCamera->GetRelativeTransform()); } diff --git a/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Private/ReplicatedVRCameraComponent.cpp b/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Private/ReplicatedVRCameraComponent.cpp index 88cc9d7..6e45633 100644 --- a/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Private/ReplicatedVRCameraComponent.cpp +++ b/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Private/ReplicatedVRCameraComponent.cpp @@ -204,7 +204,7 @@ void UReplicatedVRCameraComponent::UpdateTracking(float DeltaTime) Position.Y = 0.0f; FRotator StoredCameraRotOffset = FRotator::ZeroRotator; - if (AttachChar->VRMovementReference->GetReplicatedMovementMode() == EVRConjoinedMovementModes::C_VRMOVE_Seated) + if (AttachChar->VRMovementReference && AttachChar->VRMovementReference->GetReplicatedMovementMode() == EVRConjoinedMovementModes::C_VRMOVE_Seated) { AttachChar->SeatInformation.InitialRelCameraTransform.Rotator(); } @@ -244,7 +244,7 @@ void UReplicatedVRCameraComponent::RunNetworkedSmoothing(float DeltaTime) if (AttachChar && !AttachChar->bRetainRoomscale) { FRotator StoredCameraRotOffset = FRotator::ZeroRotator; - if (AttachChar->VRMovementReference->GetReplicatedMovementMode() == EVRConjoinedMovementModes::C_VRMOVE_Seated) + if (AttachChar->VRMovementReference && AttachChar->VRMovementReference->GetReplicatedMovementMode() == EVRConjoinedMovementModes::C_VRMOVE_Seated) { AttachChar->SeatInformation.InitialRelCameraTransform.Rotator(); } @@ -470,7 +470,7 @@ void UReplicatedVRCameraComponent::HandleXRCamera() Position.X = 0.0f; Position.Y = 0.0f; //FRotator OffsetRotator = - if (AttachChar->VRMovementReference->GetReplicatedMovementMode() != EVRConjoinedMovementModes::C_VRMOVE_Seated) + if (AttachChar->VRMovementReference && AttachChar->VRMovementReference->GetReplicatedMovementMode() != EVRConjoinedMovementModes::C_VRMOVE_Seated) { AttachChar->SeatInformation.InitialRelCameraTransform.Rotator(); @@ -521,7 +521,7 @@ void UReplicatedVRCameraComponent::OnRep_ReplicatedCameraTransform() CameraPosition.Y = 0; FRotator StoredCameraRotOffset = FRotator::ZeroRotator; - if (AttachChar->VRMovementReference->GetReplicatedMovementMode() == EVRConjoinedMovementModes::C_VRMOVE_Seated) + if (AttachChar->VRMovementReference && AttachChar->VRMovementReference->GetReplicatedMovementMode() == EVRConjoinedMovementModes::C_VRMOVE_Seated) { AttachChar->SeatInformation.InitialRelCameraTransform.Rotator(); } diff --git a/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Private/VRBaseCharacter.cpp b/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Private/VRBaseCharacter.cpp index 6b81d1c..bbf298b 100644 --- a/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Private/VRBaseCharacter.cpp +++ b/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Private/VRBaseCharacter.cpp @@ -54,7 +54,7 @@ AVRBaseCharacter::AVRBaseCharacter(const FObjectInitializer& ObjectInitializer) cap->SetCollisionResponseToChannel(ECollisionChannel::ECC_WorldStatic, ECollisionResponse::ECR_Block); } - NetSmoother = CreateDefaultSubobject(AVRBaseCharacter::SmoothingSceneParentComponentName); + NetSmoother = CreateOptionalDefaultSubobject(AVRBaseCharacter::SmoothingSceneParentComponentName); if (NetSmoother) { NetSmoother->SetupAttachment(RootComponent); @@ -69,17 +69,17 @@ AVRBaseCharacter::AVRBaseCharacter(const FObjectInitializer& ObjectInitializer) } } - VRProxyComponent = CreateDefaultSubobject(AVRBaseCharacter::VRProxyComponentName); + VRProxyComponent = CreateOptionalDefaultSubobject(AVRBaseCharacter::VRProxyComponentName); if (NetSmoother && VRProxyComponent) { VRProxyComponent->SetupAttachment(NetSmoother); } - VRReplicatedCamera = CreateDefaultSubobject(AVRBaseCharacter::ReplicatedCameraComponentName); + VRReplicatedCamera = CreateOptionalDefaultSubobject(AVRBaseCharacter::ReplicatedCameraComponentName); if (VRReplicatedCamera) { //VRReplicatedCamera->bOffsetByHMD = false; - VRReplicatedCamera->SetupAttachment(VRProxyComponent); + VRReplicatedCamera->SetupAttachment(VRProxyComponent ? VRProxyComponent : NetSmoother ? NetSmoother : RootComponent); VRReplicatedCamera->OverrideSendTransform = &AVRBaseCharacter::Server_SendTransformCamera; } @@ -90,11 +90,11 @@ AVRBaseCharacter::AVRBaseCharacter(const FObjectInitializer& ObjectInitializer) //AddTickPrerequisiteComponent(this->GetCharacterMovement()); } - ParentRelativeAttachment = CreateDefaultSubobject(AVRBaseCharacter::ParentRelativeAttachmentComponentName); + ParentRelativeAttachment = CreateOptionalDefaultSubobject(AVRBaseCharacter::ParentRelativeAttachmentComponentName); if (ParentRelativeAttachment && VRReplicatedCamera) { // Moved this to be root relative as the camera late updates were killing how it worked - ParentRelativeAttachment->SetupAttachment(VRProxyComponent); + ParentRelativeAttachment->SetupAttachment(VRProxyComponent ? VRProxyComponent : NetSmoother ? NetSmoother : RootComponent); //ParentRelativeAttachment->bOffsetByHMD = false; ParentRelativeAttachment->AddTickPrerequisiteComponent(VRReplicatedCamera); @@ -104,10 +104,10 @@ AVRBaseCharacter::AVRBaseCharacter(const FObjectInitializer& ObjectInitializer) } } - LeftMotionController = CreateDefaultSubobject(AVRBaseCharacter::LeftMotionControllerComponentName); + LeftMotionController = CreateOptionalDefaultSubobject(AVRBaseCharacter::LeftMotionControllerComponentName); if (IsValid(LeftMotionController)) { - LeftMotionController->SetupAttachment(VRProxyComponent); + LeftMotionController->SetupAttachment(VRProxyComponent ? VRProxyComponent : NetSmoother ? NetSmoother : RootComponent); //LeftMotionController->MotionSource = FXRMotionControllerBase::LeftHandSourceId; LeftMotionController->SetTrackingMotionSource(IMotionController::LeftHandSourceId); //LeftMotionController->Hand = EControllerHand::Left; @@ -118,10 +118,10 @@ AVRBaseCharacter::AVRBaseCharacter(const FObjectInitializer& ObjectInitializer) LeftMotionController->OverrideSendTransform = &AVRBaseCharacter::Server_SendTransformLeftController; } - RightMotionController = CreateDefaultSubobject(AVRBaseCharacter::RightMotionControllerComponentName); + RightMotionController = CreateOptionalDefaultSubobject(AVRBaseCharacter::RightMotionControllerComponentName); if (IsValid(RightMotionController)) { - RightMotionController->SetupAttachment(VRProxyComponent); + RightMotionController->SetupAttachment(VRProxyComponent ? VRProxyComponent : NetSmoother ? NetSmoother : RootComponent); //RightMotionController->MotionSource = FXRMotionControllerBase::RightHandSourceId; RightMotionController->SetTrackingMotionSource(IMotionController::RightHandSourceId); //RightMotionController->Hand = EControllerHand::Right; @@ -680,6 +680,9 @@ void AVRBaseCharacter::InitSeatedModeTransition() void AVRBaseCharacter::TickSeatInformation(float DeltaTime) { + if (!VRReplicatedCamera) + return; + float LastThresholdScaler = SeatInformation.CurrentThresholdScaler; bool bLastOverThreshold = SeatInformation.bIsOverThreshold; @@ -779,7 +782,7 @@ bool AVRBaseCharacter::SetSeatedMode(USceneComponent * SeatParent, bool bSetSeat // Automate the intial relative camera transform for this mode // I think we can remove the initial value alltogether eventually right? - if (!bRetainRoomscale) + if (!bRetainRoomscale && VRReplicatedCamera) { InitialRelCameraTransform = FTransform(VRReplicatedCamera->ReplicatedCameraTransform.Rotation, VRReplicatedCamera->ReplicatedCameraTransform.Position, VRReplicatedCamera->GetComponentScale()); } @@ -909,7 +912,7 @@ FVector AVRBaseCharacter::SetActorRotationVR(FRotator NewRot, bool bUseYawOnly, NewRot.Roll = 0.0f; } - if (bAccountForHMDRotation) + if (bAccountForHMDRotation && VRReplicatedCamera) { NewRotation = UVRExpansionFunctionLibrary::GetHMDPureYaw_I(VRReplicatedCamera->GetRelativeRotation()); NewRotation = (NewRot.Quaternion() * NewRotation.Quaternion().Inverse()).Rotator(); @@ -944,7 +947,7 @@ FVector AVRBaseCharacter::SetActorLocationAndRotationVR(FVector NewLoc, FRotator NewRot.Roll = 0.0f; } - if (bAccountForHMDRotation) + if (bAccountForHMDRotation && VRReplicatedCamera) { NewRotation = UVRExpansionFunctionLibrary::GetHMDPureYaw_I(VRReplicatedCamera->GetRelativeRotation());//bUseControllerRotationYaw && OwningController ? OwningController->GetControlRotation() : GetActorRotation(); NewRotation = (NewRot.Quaternion() * NewRotation.Quaternion().Inverse()).Rotator(); @@ -1201,4 +1204,4 @@ void AVRBaseCharacter::StopNavigationMovement() // not ignore OnRequestFinished notify that's going to be sent out due to this call pathComp->AbortMove(*this, FPathFollowingResultFlags::MovementStop | FPathFollowingResultFlags::ForcedScript); } -} \ No newline at end of file +} diff --git a/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Private/VRBaseCharacterMovementComponent.cpp b/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Private/VRBaseCharacterMovementComponent.cpp index b980428..32854cf 100644 --- a/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Private/VRBaseCharacterMovementComponent.cpp +++ b/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Private/VRBaseCharacterMovementComponent.cpp @@ -2017,8 +2017,11 @@ void UVRBaseCharacterMovementComponent::SmoothCorrection(const FVector& OldLocat // I am currently skipping smoothing on rotation operations if ((!OldRotation.Equals(NewRotation, 1e-5f)))// || Velocity.IsNearlyZero())) { - BaseVRCharacterOwner->NetSmoother->SetRelativeLocation(BaseVRCharacterOwner->bRetainRoomscale ? FVector::ZeroVector : BaseVRCharacterOwner->VRRootReference->GetTargetHeightOffset()); - //BaseVRCharacterOwner->NetSmoother->SetRelativeLocation(FVector::ZeroVector); + if (BaseVRCharacterOwner->NetSmoother) + { + BaseVRCharacterOwner->NetSmoother->SetRelativeLocation(BaseVRCharacterOwner->bRetainRoomscale ? FVector::ZeroVector : BaseVRCharacterOwner->VRRootReference->GetTargetHeightOffset()); + //BaseVRCharacterOwner->NetSmoother->SetRelativeLocation(FVector::ZeroVector); + } UpdatedComponent->SetWorldLocationAndRotation(NewLocation, NewRotation, false, nullptr, GetTeleportType()); ClientData->MeshTranslationOffset = FVector::ZeroVector; ClientData->MeshRotationOffset = ClientData->MeshRotationTarget; @@ -2152,7 +2155,7 @@ void UVRBaseCharacterMovementComponent::SmoothClientPosition_UpdateVRVisuals() if (ClientData) { - if (NetworkSmoothingMode == ENetworkSmoothingMode::Linear) + if (NetworkSmoothingMode == ENetworkSmoothingMode::Linear && BaseVRCharacterOwner->NetSmoother) { // Erased most of the code here, check back in later const USceneComponent* MeshParent = BaseVRCharacterOwner->NetSmoother->GetAttachParent(); @@ -2167,7 +2170,7 @@ void UVRBaseCharacterMovementComponent::SmoothClientPosition_UpdateVRVisuals() FVector HeightOffset = (BaseVRCharacterOwner->bRetainRoomscale ? FVector::ZeroVector : BaseVRCharacterOwner->VRRootReference->GetTargetHeightOffset()); BaseVRCharacterOwner->NetSmoother->SetRelativeLocation(NewRelLocation + HeightOffset); } - else if (NetworkSmoothingMode == ENetworkSmoothingMode::Exponential) + else if (NetworkSmoothingMode == ENetworkSmoothingMode::Exponential && BaseVRCharacterOwner->NetSmoother) { const USceneComponent* MeshParent = BaseVRCharacterOwner->NetSmoother->GetAttachParent(); FVector MeshParentScale = MeshParent != nullptr ? MeshParent->GetComponentScale() : FVector(1.0f, 1.0f, 1.0f); diff --git a/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Private/VRRootComponent.cpp b/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Private/VRRootComponent.cpp index d6d57eb..f50a237 100644 --- a/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Private/VRRootComponent.cpp +++ b/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Private/VRRootComponent.cpp @@ -423,11 +423,14 @@ void UVRRootComponent::BeginPlay() Super::BeginPlay(); if(AVRBaseCharacter * vrOwner = Cast(this->GetOwner())) - { - TargetPrimitiveComponent = vrOwner->VRReplicatedCamera; - owningVRChar = vrOwner; - //VRCameraCollider = vrOwner->VRCameraCollider; - return; + { + if (vrOwner->VRReplicatedCamera) + { + TargetPrimitiveComponent = vrOwner->VRReplicatedCamera; + owningVRChar = vrOwner; + //VRCameraCollider = vrOwner->VRCameraCollider; + return; + } } else { @@ -456,7 +459,7 @@ void UVRRootComponent::SetTrackingPaused(bool bPaused) void UVRRootComponent::UpdateCharacterCapsuleOffset() { - if (owningVRChar && !owningVRChar->bRetainRoomscale) + if (owningVRChar && !owningVRChar->bRetainRoomscale && owningVRChar->NetSmoother) { if (!FMath::IsNearlyEqual(LastCapsuleHalfHeight, CapsuleHalfHeight)) { @@ -485,11 +488,13 @@ void UVRRootComponent::TickComponent(float DeltaTime, enum ELevelTick TickType, } UVRBaseCharacterMovementComponent * CharMove = nullptr; + bool bRetainRoomscale = true; // Need these for passing physics updates to character movement if (IsValid(owningVRChar)) { CharMove = Cast(owningVRChar->GetCharacterMovement()); + bRetainRoomscale = owningVRChar->bRetainRoomscale; } if (IsLocallyControlled()) @@ -539,7 +544,7 @@ void UVRRootComponent::TickComponent(float DeltaTime, enum ELevelTick TickType, // Skip this if not retaining roomscale as we use higher initial fidelity // And we can rep the values at full precision if we want too - if (owningVRChar->bRetainRoomscale) + if (bRetainRoomscale) { // Pre-Process this for network sends curCameraLoc.X = FMath::RoundToFloat(curCameraLoc.X * 100.f) / 100.f; @@ -549,14 +554,14 @@ void UVRRootComponent::TickComponent(float DeltaTime, enum ELevelTick TickType, // Can adjust the relative tolerances to remove jitter and some update processing - if (!owningVRChar->bRetainRoomscale || (!curCameraLoc.Equals(lastCameraLoc, 0.01f) || !curCameraRot.Equals(lastCameraRot, 0.01f))) + if (!bRetainRoomscale || (!curCameraLoc.Equals(lastCameraLoc, 0.01f) || !curCameraRot.Equals(lastCameraRot, 0.01f))) { // Also calculate vector of movement for the movement component FVector LastPosition = OffsetComponentToWorld.GetLocation(); bCalledUpdateTransform = false; - if (owningVRChar->bRetainRoomscale) + if (bRetainRoomscale) { // If the character movement doesn't exist or is not active/ticking if (!CharMove || !CharMove->IsComponentTickEnabled() || !CharMove->IsActive()) @@ -578,7 +583,7 @@ void UVRRootComponent::TickComponent(float DeltaTime, enum ELevelTick TickType, Params.bFindInitialOverlaps = true; bool bBlockingHit = false; - if (bUseWalkingCollisionOverride && owningVRChar->bRetainRoomscale) + if (bUseWalkingCollisionOverride && bRetainRoomscale) { FVector TargetWorldLocation = OffsetComponentToWorld.GetLocation(); bool bAllowWalkingCollision = false; @@ -608,9 +613,9 @@ void UVRRootComponent::TickComponent(float DeltaTime, enum ELevelTick TickType, bHadRelativeMovement = true; // Not supporting walking collision override currently with new pawn setup - if (bHadRelativeMovement || !owningVRChar->bRetainRoomscale) + if (bHadRelativeMovement || (owningVRChar && !owningVRChar->bRetainRoomscale)) { - if (owningVRChar->bRetainRoomscale) + if (bRetainRoomscale) { DifferenceFromLastFrame = OffsetComponentToWorld.GetLocation() - LastPosition; lastCameraLoc = curCameraLoc; @@ -756,7 +761,10 @@ void UVRRootComponent::SetSimulatePhysics(bool bSimulate) { if (AVRCharacter* OwningCharacter = Cast(GetOwner())) { - OwningCharacter->NetSmoother->SetRelativeLocation(FVector(0.f,0.f, -this->GetUnscaledCapsuleHalfHeight())); + if (OwningCharacter->NetSmoother) + { + OwningCharacter->NetSmoother->SetRelativeLocation(FVector(0.f,0.f, -this->GetUnscaledCapsuleHalfHeight())); + } } this->AddWorldOffset(this->GetComponentRotation().RotateVector(FVector(0.f, 0.f, this->GetScaledCapsuleHalfHeight())), false, nullptr, ETeleportType::TeleportPhysics); } @@ -764,7 +772,10 @@ void UVRRootComponent::SetSimulatePhysics(bool bSimulate) { if (AVRCharacter* OwningCharacter = Cast(GetOwner())) { - OwningCharacter->NetSmoother->SetRelativeLocation(FVector(0.f, 0.f, 0)); + if (OwningCharacter->NetSmoother) + { + OwningCharacter->NetSmoother->SetRelativeLocation(FVector(0.f, 0.f, 0)); + } } this->AddWorldOffset(this->GetComponentRotation().RotateVector(FVector(0.f, 0.f, -this->GetScaledCapsuleHalfHeight())), false, nullptr, ETeleportType::TeleportPhysics); } diff --git a/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Private/VRStereoWidgetComponent.cpp b/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Private/VRStereoWidgetComponent.cpp index 40fdba1..cbe63e9 100644 --- a/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Private/VRStereoWidgetComponent.cpp +++ b/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Private/VRStereoWidgetComponent.cpp @@ -576,28 +576,31 @@ void UVRStereoWidgetComponent::TickComponent(float DeltaTime, enum ELevelTick Ti bool bHandledTransform = false; if (AVRBaseCharacter* BaseVRChar = Cast(mpawn)) { - if (USceneComponent* CameraParent = BaseVRChar->VRReplicatedCamera->GetAttachParent()) + if (BaseVRChar->VRReplicatedCamera) { - FTransform DeltaTrans = FTransform::Identity; - if (!BaseVRChar->bRetainRoomscale) + if (USceneComponent* CameraParent = BaseVRChar->VRReplicatedCamera->GetAttachParent()) { - FVector HMDLoc; - FQuat HMDRot; - GEngine->XRSystem->GetCurrentPose(IXRTrackingSystem::HMDDeviceId, HMDRot, HMDLoc); - - HMDLoc.Z = 0.0f; - - if (AVRCharacter* VRChar = Cast(mpawn)) + FTransform DeltaTrans = FTransform::Identity; + if (!BaseVRChar->bRetainRoomscale) { - HMDLoc += UVRExpansionFunctionLibrary::GetHMDPureYaw_I(HMDRot.Rotator()).RotateVector(FVector(VRChar->VRRootReference->VRCapsuleOffset.X, VRChar->VRRootReference->VRCapsuleOffset.Y, 0.0f)); + FVector HMDLoc; + FQuat HMDRot; + GEngine->XRSystem->GetCurrentPose(IXRTrackingSystem::HMDDeviceId, HMDRot, HMDLoc); + + HMDLoc.Z = 0.0f; + + if (AVRCharacter* VRChar = Cast(mpawn)) + { + HMDLoc += UVRExpansionFunctionLibrary::GetHMDPureYaw_I(HMDRot.Rotator()).RotateVector(FVector(VRChar->VRRootReference->VRCapsuleOffset.X, VRChar->VRRootReference->VRCapsuleOffset.Y, 0.0f)); + } + + DeltaTrans = FTransform(FQuat::Identity, HMDLoc, FVector(1.0f)); } - DeltaTrans = FTransform(FQuat::Identity, HMDLoc, FVector(1.0f)); + Transform = OffsetTransform.GetRelativeTransform(CameraParent->GetComponentTransform()); + Transform = (FTransform(FRotator(0.f, -180.f, 0.f)) * Transform) * DeltaTrans; + bHandledTransform = true; } - - Transform = OffsetTransform.GetRelativeTransform(CameraParent->GetComponentTransform()); - Transform = (FTransform(FRotator(0.f, -180.f, 0.f)) * Transform) * DeltaTrans; - bHandledTransform = true; } } else if (UCameraComponent* Camera = mpawn->FindComponentByClass()) diff --git a/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Public/GripScripts/VRGripScriptBase.h b/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Public/GripScripts/VRGripScriptBase.h index 36989ab..8effe62 100644 --- a/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Public/GripScripts/VRGripScriptBase.h +++ b/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Public/GripScripts/VRGripScriptBase.h @@ -55,6 +55,27 @@ public: UPROPERTY(BlueprintReadWrite, EditDefaultsOnly, Category = "GSSettings") bool bIsActive; +private: + // If we should replicate, if false we will never be added to our parents list. + UPROPERTY(Replicated, EditDefaultsOnly, BlueprintReadOnly, Category = "GSSettings|Replication", meta = (AllowPrivateAccess = "true")) + bool bReplicates = false; +public: + + /** Enable or disable replication. This is the equivalent of RemoteRole for actors (only a bool is required for components) */ + UFUNCTION(BlueprintCallable, Category = "Components") + void SetIsReplicated(bool ShouldReplicate); + + /** Returns whether replication is enabled or not. */ + UFUNCTION(BlueprintCallable, Category = "Components") + bool GetIsReplicated() const + { + return bReplicates; + } + + // Replication Condition (If using subobject replication list) + UPROPERTY(BlueprintReadWrite, EditDefaultsOnly, Category = "GSSettings|Replication") + TEnumAsByte ReplicationCondition = ELifetimeCondition::COND_None; + // Returns if the script is going to modify the world transform of the grip EGSTransformOverrideType GetWorldTransformOverrideType(); @@ -128,8 +149,13 @@ public: bool Wants_DenyTeleport(UGripMotionControllerComponent * Controller); virtual bool Wants_DenyTeleport_Implementation(UGripMotionControllerComponent* Controller); +#if UE_WITH_IRIS + /** Register all replication fragments */ + virtual void RegisterReplicationFragments(UE::Net::FFragmentRegistrationContext& Context, UE::Net::EFragmentRegistrationFlags RegistrationFlags) override; +#endif // UE_WITH_IRIS + virtual void GetLifetimeReplicatedProps(TArray< class FLifetimeProperty > & OutLifetimeProps) const override; - + // doesn't currently compile in editor builds, not sure why the linker is screwing up there but works elsewhere //virtual void PreReplication(IRepChangedPropertyTracker & ChangedPropertyTracker); virtual bool CallRemoteFunction(UFunction * Function, void * Parms, FOutParmRec * OutParms, FFrame * Stack) override; @@ -200,6 +226,7 @@ public: UFUNCTION(BlueprintPure, Category = "VRGripScript") bool IsServer(); + virtual void BeginDestroy(); void EndPlay(const EEndPlayReason::Type EndPlayReason); // Not all scripts will require this function, specific ones that use things like Lever logic however will. Best to call it. diff --git a/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Public/Grippables/HandSocketComponent.h b/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Public/Grippables/HandSocketComponent.h index bec4db0..e539d08 100644 --- a/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Public/Grippables/HandSocketComponent.h +++ b/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Public/Grippables/HandSocketComponent.h @@ -161,10 +161,10 @@ public: bool bDisabled; /*** - /* If true then the hand socket will be locked in place during gameplay and not moved with the actor (saving performance) - /* Generally you want this unless you are moving a hand socket manually during play for custom grip offsetting logic - /* If you need the relative location of the hand socket for game logic, get the LockedRelativeTransform variable if bLockInPlace is enabled. - /* Defaulted off currently for bug testing + // If true then the hand socket will be locked in place during gameplay and not moved with the actor (saving performance) + // Generally you want this unless you are moving a hand socket manually during play for custom grip offsetting logic + // If you need the relative location of the hand socket for game logic, get the LockedRelativeTransform variable if bLockInPlace is enabled. + // Defaulted off currently for bug testing ***/ UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Hand Socket Data|Control") bool bLockInPlace; @@ -232,6 +232,26 @@ public: UFUNCTION(BlueprintCallable, Category = "Hand Socket Data", meta = (bIgnoreSelf = "true")) static bool GetAnimationSequenceAsPoseSnapShot(UAnimSequence * InAnimationSequence, FPoseSnapshot& OutPoseSnapShot, USkeletalMeshComponent* TargetMesh = nullptr, bool bSkipRootBone = false, bool bFlipHand = false); + + /** + * Gets all hand socket components in the entire level (this is a slow operation, DO NOT run this on tick) + */ + UFUNCTION(BlueprintCallable, Category = "Hand Socket Data") + static void GetAllHandSocketComponents(TArray& OutHandSockets); + + /** + * Gets all hand socket components within a set range of a world location (this is a slow operation, DO NOT run this on tick) + */ + UFUNCTION(BlueprintCallable, Category = "Hand Socket Data") + static bool GetAllHandSocketComponentsInRange(FVector SearchFromWorldLocation, float SearchRange, TArray& OutHandSockets); + + /** + * Gets the closest hand socket component within a set range of a world location (this is a slow operation, DO NOT run this on tick) + * Must check the output for validity + */ + UFUNCTION(BlueprintCallable, Category = "Hand Socket Data") + static UHandSocketComponent* GetClosestHandSocketComponentInRange(FVector SearchFromWorldLocation, float SearchRange); + // Returns the target relative transform of the hand //UFUNCTION(BlueprintCallable, Category = "Hand Socket Data") FTransform GetHandRelativePlacement(); diff --git a/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Public/VRRootComponent.h b/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Public/VRRootComponent.h index 7c81303..fd18e20 100644 --- a/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Public/VRRootComponent.h +++ b/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/Public/VRRootComponent.h @@ -108,7 +108,7 @@ protected: public: - void BeginPlay() override; + virtual void BeginPlay() override; virtual void InitializeComponent() override; bool IsLocallyControlled() const; @@ -200,7 +200,7 @@ public: bool bHadRelativeMovement; FPrimitiveSceneProxy* CreateSceneProxy() override; - void TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction) override; + virtual void TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction) override; virtual void UpdatePhysicsVolume(bool bTriggerNotifiers) override; diff --git a/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/VRExpansionPlugin.Build.cs b/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/VRExpansionPlugin.Build.cs index 23c324d..c4976b7 100644 --- a/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/VRExpansionPlugin.Build.cs +++ b/VIRTUOS_ExpansionPluginTests/Plugins/VRExpansionPlugin/VRExpansionPlugin/Source/VRExpansionPlugin/VRExpansionPlugin.Build.cs @@ -15,6 +15,7 @@ public class VRExpansionPlugin : ModuleRules //bEnforceIWYU = true; PublicDefinitions.Add("WITH_VR_EXPANSION=1"); + SetupIrisSupport(Target); // To detect VR Preview, not built out in packaged builds if (Target.bBuildEditor == true)