From b6bff74b2fe4acbdee3e8a1a5c3a8c0a69d5005d Mon Sep 17 00:00:00 2001 From: Kris Helwig <helwig@vr.rwth-aachen.de> Date: Tue, 22 Apr 2025 17:04:50 +0200 Subject: [PATCH] Adds ResetToPlayerStart function --- .../Private/PointOfInterestManager.cpp | 21 +++++++++++++++++++ .../Public/PointOfInterestManager.h | 3 +++ 2 files changed, 24 insertions(+) diff --git a/Source/RWTHVRQuickStart/Private/PointOfInterestManager.cpp b/Source/RWTHVRQuickStart/Private/PointOfInterestManager.cpp index b761849..427c818 100644 --- a/Source/RWTHVRQuickStart/Private/PointOfInterestManager.cpp +++ b/Source/RWTHVRQuickStart/Private/PointOfInterestManager.cpp @@ -1,6 +1,7 @@ #include "PointOfInterestManager.h" #include "PointOfInterest.h" +#include "GameFramework/PlayerStart.h" #include "Kismet/GameplayStatics.h" #include "Logging/StructuredLog.h" @@ -27,6 +28,26 @@ void APointOfInterestManager::TickActor(float DeltaTime, enum ELevelTick TickTyp } } +void APointOfInterestManager::ResetToPlayerStart() +{ + APawn* Pawn = UGameplayStatics::GetPlayerPawn(GetWorld(), 0); + if (!Pawn) + { + UE_LOGFMT(POIManagerLog, Warning, "Attempted to move player pawn to PlayerStart but no pawn found to move."); + return; + } + TArray<AActor*> AllPlayerStarts; + UGameplayStatics::GetAllActorsOfClass(GetWorld(), APlayerStart::StaticClass(), AllPlayerStarts); + if (AllPlayerStarts.IsEmpty()) + { + UE_LOGFMT(POIManagerLog, Warning, "Attempted to move player pawn to PlayerStart but no PlayerStart found to move."); + return; + } + AActor* PlayerStart = AllPlayerStarts[0]; + Pawn->Controller->SetControlRotation(PlayerStart->GetActorRotation()); + Pawn->SetActorLocationAndRotation(PlayerStart->GetActorLocation(), PlayerStart->GetActorRotation()); +} + void APointOfInterestManager::AddPointOfInterest() { APointOfInterest* POI = static_cast<APointOfInterest*>(GetWorld()->SpawnActor(APointOfInterest::StaticClass())); diff --git a/Source/RWTHVRQuickStart/Public/PointOfInterestManager.h b/Source/RWTHVRQuickStart/Public/PointOfInterestManager.h index 1d6aede..a534217 100644 --- a/Source/RWTHVRQuickStart/Public/PointOfInterestManager.h +++ b/Source/RWTHVRQuickStart/Public/PointOfInterestManager.h @@ -20,6 +20,9 @@ public: virtual void TickActor(float DeltaTime, enum ELevelTick TickType, FActorTickFunction& ThisTickFunction) override; + UFUNCTION(CallInEditor, BlueprintCallable) + void ResetToPlayerStart(); + UFUNCTION(CallInEditor, BlueprintCallable, Category="Point Of Interest Manager") void AddPointOfInterest(); -- GitLab