diff --git a/Source/RWTHVRToolkit/Private/Core/ClientTransformReplication.cpp b/Source/RWTHVRToolkit/Private/Core/ClientTransformReplication.cpp index 0bce9302ae30860f0211918a620be91e9666ea21..011c83377dbcf497f2df887a00c4ec6250838275 100644 --- a/Source/RWTHVRToolkit/Private/Core/ClientTransformReplication.cpp +++ b/Source/RWTHVRToolkit/Private/Core/ClientTransformReplication.cpp @@ -26,8 +26,8 @@ void UClientTransformReplication::UpdateState(float DeltaTime) // Only do this if we actually replicate the actor if (GetIsReplicated()) { - const FVector Loc = OwningActor->GetActorLocation(); - const FRotator Rot = OwningActor->GetActorRotation(); + const FVector Loc = OwningActor->GetRootComponent()->GetRelativeLocation(); + const FRotator Rot = OwningActor->GetRootComponent()->GetRelativeRotation(); // Only update state if the local state changed if (!Loc.Equals(ReplicatedTransform.Position) || !Rot.Equals(ReplicatedTransform.Rotation)) diff --git a/Source/RWTHVRToolkit/Private/Interaction/Interactors/DirectInteractionComponent.cpp b/Source/RWTHVRToolkit/Private/Interaction/Interactors/DirectInteractionComponent.cpp index 18e515817875cb60c35090b4dbfb4300051b8dac..fac35ab8270c772dcd94b2b67d1808eb4f8b5bd5 100644 --- a/Source/RWTHVRToolkit/Private/Interaction/Interactors/DirectInteractionComponent.cpp +++ b/Source/RWTHVRToolkit/Private/Interaction/Interactors/DirectInteractionComponent.cpp @@ -70,6 +70,13 @@ void UDirectInteractionComponent::TickComponent(float DeltaTime, ELevelTick Tick // Call hover end events on all components that were previously in range, but not anymore for (UInteractableComponent* PrevInteractableComp : PreviousInteractableComponentsInRange) { + // It can happen that a previous component was destroyed + if (!PrevInteractableComp || !PrevInteractableComp->IsValidLowLevel()) + { + ComponentsToRemove.Add(PrevInteractableComp); // might have to use indices here + continue; + } + if (!CurrentInteractableCompsInRange.Contains(PrevInteractableComp)) { ComponentsToRemove.AddUnique(PrevInteractableComp); diff --git a/Source/RWTHVRToolkit/Private/Pawn/RWTHVRPawn.cpp b/Source/RWTHVRToolkit/Private/Pawn/RWTHVRPawn.cpp index bf5b24da956e845fd2c1f48d2dbb83fae5dfc9f9..d2a4b5ed39c154159dc68538d66bf8d2ac14cb9d 100644 --- a/Source/RWTHVRToolkit/Private/Pawn/RWTHVRPawn.cpp +++ b/Source/RWTHVRToolkit/Private/Pawn/RWTHVRPawn.cpp @@ -156,14 +156,18 @@ void ARWTHVRPawn::SetupPlayerInputComponent(UInputComponent* PlayerInputComponen if (ARWTHVRPlayerState* State = GetPlayerState<ARWTHVRPlayerState>()) { // Might not be properly synced yet? - const EPlayerType Type = State->GetPlayerType(); + EPlayerType Type = State->GetPlayerType(); // Don't do anything with the type if it's been set to clustertype or anything. // This is already being done when connecting to the server. const bool bClusterType = Type == EPlayerType::nDisplayPrimary || Type == EPlayerType::nDisplaySecondary; - if (!bClusterType && URWTHVRUtilities::IsHeadMountedMode()) + if (!bClusterType) { + if (URWTHVRUtilities::IsHeadMountedMode()) + Type = EPlayerType::HMD; + + UE_LOGFMT(Toolkit, Display, "Pawn: Requesting Player Type {T}...", StaticCast<int8>(Type)); // Could be too early to call this RPC... State->RequestSetPlayerType(Type); } diff --git a/Source/RWTHVRToolkit/Private/Utility/RWTHVRUtilities.cpp b/Source/RWTHVRToolkit/Private/Utility/RWTHVRUtilities.cpp index 0ac047f0c52247b45ec6d78170bf482b88eb6f05..af8fc1089e86f0bdaf6dd63dae95be908bf3fd3c 100644 --- a/Source/RWTHVRToolkit/Private/Utility/RWTHVRUtilities.cpp +++ b/Source/RWTHVRToolkit/Private/Utility/RWTHVRUtilities.cpp @@ -1,6 +1,7 @@ #include "Utility/RWTHVRUtilities.h" #include "AudioDevice.h" +#include "HeadMountedDisplayFunctionLibrary.h" #include "IHeadMountedDisplay.h" #include "IXRTrackingSystem.h" #include "Engine/Engine.h" @@ -16,12 +17,7 @@ DEFINE_LOG_CATEGORY(Toolkit); bool URWTHVRUtilities::IsDesktopMode() { return !IsRoomMountedMode() && !IsHeadMountedMode(); } -bool URWTHVRUtilities::IsHeadMountedMode() -{ - // In editor builds: checks for EdEngine->IsVRPreviewActive() - // In packaged builds: checks for `-vr` in commandline or bStartInVR in UGeneralProjectSettings - return FAudioDevice::CanUseVRAudioDevice(); -} +bool URWTHVRUtilities::IsHeadMountedMode() { return UHeadMountedDisplayFunctionLibrary::IsHeadMountedDisplayEnabled(); } bool URWTHVRUtilities::IsRoomMountedMode() { @@ -38,7 +34,7 @@ bool URWTHVRUtilities::IsPrimaryNode() return URWTHVRClusterUtilities::IsPrimaryNode(); #else return false; -#endif +#endif } float URWTHVRUtilities::GetEyeDistance() diff --git a/Source/RWTHVRToolkit/Public/Core/ClientTransformReplication.h b/Source/RWTHVRToolkit/Public/Core/ClientTransformReplication.h index ac364067efcca3c0c21a6ae940b25ece78914647..c31ed9bd3093670ab88e5c26e38f56a68b86c2f3 100644 --- a/Source/RWTHVRToolkit/Public/Core/ClientTransformReplication.h +++ b/Source/RWTHVRToolkit/Public/Core/ClientTransformReplication.h @@ -56,7 +56,10 @@ protected: // For now, directly apply the transforms: auto* OwningActor = GetOwner(); if (OwningActor && OwningActor->HasValidRootComponent()) - OwningActor->SetActorLocationAndRotation(ReplicatedTransform.Position, ReplicatedTransform.Rotation); + { + OwningActor->SetActorRelativeLocation(ReplicatedTransform.Position); + OwningActor->SetActorRelativeRotation(ReplicatedTransform.Rotation); + } } // Unreliable Server RPC that sends the transform from owning client to the server diff --git a/Source/RWTHVRToolkit/RWTHVRToolkit.Build.cs b/Source/RWTHVRToolkit/RWTHVRToolkit.Build.cs index a949553aaa90bd704c53e9ace2f749073a5441bf..3ca3534e7eb530fa1f3847c8cfc8d4fb18051875 100644 --- a/Source/RWTHVRToolkit/RWTHVRToolkit.Build.cs +++ b/Source/RWTHVRToolkit/RWTHVRToolkit.Build.cs @@ -38,7 +38,7 @@ public class RWTHVRToolkit : ModuleRules PrivateDependencyModuleNames.AddRange( new string[] { - "NetCore" + "NetCore", "XRBase" } ); if (Target.bBuildEditor == true)