Removed LZs from Save System and Replaced with Last Location

This commit is contained in:
Rafal Swierczek 2024-02-26 17:57:39 +00:00
parent a2018e02ac
commit d45f659af9
2 changed files with 21 additions and 20 deletions

View File

@ -149,25 +149,26 @@ void ABountyHunterCharacter::EndPlay(const EEndPlayReason::Type EndPlayReason)
if (UGameplayStatics::GetCurrentLevelName(GetWorld()) != OpenWorldLevelName) return;
UEVGameInstance* GI = Cast<UEVGameInstance>(GetGameInstance());
if (!IsValid(GI->MainSaveGameInstanceRef)) return;
TArray<AActor*> LandingZones;
ALandingZone* ClosestLandingZone = nullptr;
double DistToClosestLandingZone;
UGameplayStatics::GetAllActorsOfClass(GetWorld(), ALandingZone::StaticClass(), LandingZones);
for (AActor* LZ_Actor : LandingZones)
{
ALandingZone* LZ = Cast<ALandingZone>(LZ_Actor);
double DistToLZ = FVector::Dist(LZ->GetExitTransform().GetLocation(), GetActorLocation());
if (!IsValid(ClosestLandingZone))
{
ClosestLandingZone = LZ;
DistToClosestLandingZone = DistToLZ;
continue;
}
ClosestLandingZone = DistToClosestLandingZone >= DistToLZ ? LZ : ClosestLandingZone;
DistToClosestLandingZone = DistToClosestLandingZone >= DistToLZ ? DistToLZ : DistToClosestLandingZone;
}
if (!IsValid(ClosestLandingZone)) return;
GI->MainSaveGameInstanceRef->PlayerOpenWorldSpawnTransformSave = ClosestLandingZone->GetExitTransform();
GI->MainSaveGameInstanceRef->PlayerOpenWorldSpawnTransformSave = GetActorTransform();
// TArray<AActor*> LandingZones;
// ALandingZone* ClosestLandingZone = nullptr;
// double DistToClosestLandingZone;
// UGameplayStatics::GetAllActorsOfClass(GetWorld(), ALandingZone::StaticClass(), LandingZones);
// for (AActor* LZ_Actor : LandingZones)
// {
// ALandingZone* LZ = Cast<ALandingZone>(LZ_Actor);
// double DistToLZ = FVector::Dist(LZ->GetExitTransform().GetLocation(), GetActorLocation());
// if (!IsValid(ClosestLandingZone))
// {
// ClosestLandingZone = LZ;
// DistToClosestLandingZone = DistToLZ;
// continue;
// }
// ClosestLandingZone = DistToClosestLandingZone >= DistToLZ ? LZ : ClosestLandingZone;
// DistToClosestLandingZone = DistToClosestLandingZone >= DistToLZ ? DistToLZ : DistToClosestLandingZone;
// }
// if (!IsValid(ClosestLandingZone)) return;
// GI->MainSaveGameInstanceRef->PlayerOpenWorldSpawnTransformSave = ClosestLandingZone->GetExitTransform();
UGameplayStatics::SaveGameToSlot(GI->MainSaveGameInstanceRef, "MainSave", 0);
}