Skip to content
Snippets Groups Projects
Commit b6bff74b authored by Kris Tabea Helwig's avatar Kris Tabea Helwig
Browse files

Adds ResetToPlayerStart function

parent 16faf273
No related branches found
No related tags found
1 merge request!1Implements `PointOfInterest`s
#include "PointOfInterestManager.h" #include "PointOfInterestManager.h"
#include "PointOfInterest.h" #include "PointOfInterest.h"
#include "GameFramework/PlayerStart.h"
#include "Kismet/GameplayStatics.h" #include "Kismet/GameplayStatics.h"
#include "Logging/StructuredLog.h" #include "Logging/StructuredLog.h"
...@@ -27,6 +28,26 @@ void APointOfInterestManager::TickActor(float DeltaTime, enum ELevelTick TickTyp ...@@ -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() void APointOfInterestManager::AddPointOfInterest()
{ {
APointOfInterest* POI = static_cast<APointOfInterest*>(GetWorld()->SpawnActor(APointOfInterest::StaticClass())); APointOfInterest* POI = static_cast<APointOfInterest*>(GetWorld()->SpawnActor(APointOfInterest::StaticClass()));
......
...@@ -20,6 +20,9 @@ public: ...@@ -20,6 +20,9 @@ public:
virtual void TickActor(float DeltaTime, enum ELevelTick TickType, FActorTickFunction& ThisTickFunction) override; virtual void TickActor(float DeltaTime, enum ELevelTick TickType, FActorTickFunction& ThisTickFunction) override;
UFUNCTION(CallInEditor, BlueprintCallable)
void ResetToPlayerStart();
UFUNCTION(CallInEditor, BlueprintCallable, Category="Point Of Interest Manager") UFUNCTION(CallInEditor, BlueprintCallable, Category="Point Of Interest Manager")
void AddPointOfInterest(); void AddPointOfInterest();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment