diff --git a/Source/RWTHVRQuickStart/Private/PointOfInterestManager.cpp b/Source/RWTHVRQuickStart/Private/PointOfInterestManager.cpp index b761849041536395ff26e4572774b223d165ddcc..427c8189c140cedf758c64cedd108cb707c8e4fe 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 1d6aede8e6d0c3a2c614bf8b6d86d2ff7f6b4a91..a5342173f3f4a4a421e7f0b38d7fe89e4dbbe11b 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();