Bugfix Player Respawn Defaulting to Player Start over Allocated Respawn Location Randomly

This commit is contained in:
Rafal Swierczek 2024-04-11 14:11:22 +01:00
parent 6c2b3d7f29
commit 4ff9305583
4 changed files with 23 additions and 12 deletions

View File

@ -13,6 +13,7 @@ void AMainBountyClass::IncrementBountyCheckpoint()
if (AOpenWorldCheckpoint* OWCP = Cast<AOpenWorldCheckpoint>(BountyCheckpoints[0])) if (AOpenWorldCheckpoint* OWCP = Cast<AOpenWorldCheckpoint>(BountyCheckpoints[0]))
{ {
OpenWorldRespawnTransform = OWCP->GetRespawnTransform(); OpenWorldRespawnTransform = OWCP->GetRespawnTransform();
Ow_RespawnTransform.Broadcast(OpenWorldRespawnTransform);
OpenWorldCheckpointClasses.RemoveAt(0); OpenWorldCheckpointClasses.RemoveAt(0);
} }
// FString TipToDisplay = ""; // FString TipToDisplay = "";
@ -51,6 +52,8 @@ void AMainBountyClass::SpawnOpenWorldCheckpoint()
BountyCheckpoints.Add(GetWorld()->SpawnActor<ACheckpointClass>(OpenWorldCheckpointClass, Loc, Rot, SpawnParameters)); BountyCheckpoints.Add(GetWorld()->SpawnActor<ACheckpointClass>(OpenWorldCheckpointClass, Loc, Rot, SpawnParameters));
} }
ActivateFirstCheckpoint(); ActivateFirstCheckpoint();
if (BountyCheckpoints.IsEmpty() || BountyCheckpoints[0] == nullptr) return;
Ow_RespawnTransform.Broadcast(OpenWorldRespawnTransform);
} }
void AMainBountyClass::SpawnCheckpoints() void AMainBountyClass::SpawnCheckpoints()

View File

@ -35,6 +35,8 @@ struct FMainBountyStruct
UTexture2D* Floorplan = nullptr; UTexture2D* Floorplan = nullptr;
}; };
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(F_OW_RespawnTransform, FTransform, RespawnTransform);
UCLASS() UCLASS()
class ENDLESSVENDETTA_API AMainBountyClass : public ABountyClass class ENDLESSVENDETTA_API AMainBountyClass : public ABountyClass
{ {
@ -66,6 +68,9 @@ public:
UPROPERTY(EditDefaultsOnly, Category = "Bounty") UPROPERTY(EditDefaultsOnly, Category = "Bounty")
FMainBountyStruct MainBountyStruct; FMainBountyStruct MainBountyStruct;
// Used to Update Open World Respawn in the Bounty Hunter Character
F_OW_RespawnTransform Ow_RespawnTransform;
// ------------------- METHODS --------------------------------- // ------------------- METHODS ---------------------------------
private: private:
// Overrides to Display Correct Tip for Checkpoint // Overrides to Display Correct Tip for Checkpoint

View File

@ -21,6 +21,7 @@ void ABountyHunterCharacter::SpawnMainBounty(UEVGameInstance* GI)
const FAttachmentTransformRules AttachmentTransformRules(EAttachmentRule::SnapToTarget, true); const FAttachmentTransformRules AttachmentTransformRules(EAttachmentRule::SnapToTarget, true);
CurrentMainBounty->AttachToComponent(GetRootComponent(), AttachmentTransformRules); CurrentMainBounty->AttachToComponent(GetRootComponent(), AttachmentTransformRules);
CurrentMainBounty->CheckpointActivated.AddDynamic(this, &ABountyHunterCharacter::DisplayCheckpointTip); CurrentMainBounty->CheckpointActivated.AddDynamic(this, &ABountyHunterCharacter::DisplayCheckpointTip);
CurrentMainBounty->Ow_RespawnTransform.AddDynamic(this, &ABountyHunterCharacter::SetOpenWorldRespawnTransform);
MainBountyStruct = CurrentMainBounty->MainBountyStruct; MainBountyStruct = CurrentMainBounty->MainBountyStruct;
if (UGameplayStatics::GetCurrentLevelName(GetWorld()) != OpenWorldLevelName) if (UGameplayStatics::GetCurrentLevelName(GetWorld()) != OpenWorldLevelName)
{ {
@ -136,9 +137,9 @@ void ABountyHunterCharacter::BeginPlay()
SpawnSideBounties(GI); SpawnSideBounties(GI);
if (GI->MainSaveGameInstanceRef->PlayerOpenWorldSpawnTransformSave.GetLocation() != FVector(0 ,0 ,0)) if (GI->MainSaveGameInstanceRef->PlayerOpenWorldSpawnTransformSave.GetLocation() != FVector(0 ,0 ,0))
{ {
FTransform SpawnTransfrom = GI->MainSaveGameInstanceRef->PlayerOpenWorldSpawnTransformSave; OpenWorldRespawnTransform = GI->MainSaveGameInstanceRef->PlayerOpenWorldSpawnTransformSave;
SetActorTransform(SpawnTransfrom); SetActorTransform(OpenWorldRespawnTransform);
Cast<APlayerController>(GetController())->SetControlRotation(SpawnTransfrom.GetRotation().Rotator()); Cast<APlayerController>(GetController())->SetControlRotation(OpenWorldRespawnTransform.GetRotation().Rotator());
} }
} }
} }
@ -152,8 +153,6 @@ void ABountyHunterCharacter::SetupPlayerInputComponent(UInputComponent* PlayerIn
EnhancedInputComponent->BindAction(PauseMenuAction, ETriggerEvent::Started, this, &ABountyHunterCharacter::TogglePauseMenu); EnhancedInputComponent->BindAction(PauseMenuAction, ETriggerEvent::Started, this, &ABountyHunterCharacter::TogglePauseMenu);
} }
UE_LOG(LogTemp, Warning, TEXT("Setup player input on bounty hunter character"));
Super::SetupPlayerInputComponent(PlayerInputComponent); Super::SetupPlayerInputComponent(PlayerInputComponent);
} }
@ -165,13 +164,8 @@ void ABountyHunterCharacter::EndPlay(const EEndPlayReason::Type EndPlayReason)
UEVGameInstance* GI = Cast<UEVGameInstance>(GetGameInstance()); UEVGameInstance* GI = Cast<UEVGameInstance>(GetGameInstance());
if (!IsValid(GI->MainSaveGameInstanceRef)) return; if (!IsValid(GI->MainSaveGameInstanceRef)) return;
if (IsValid(CurrentMainBounty)) GI->MainSaveGameInstanceRef->OpenWorldCheckpointsClassesSave = CurrentMainBounty->GetOpenWorldCheckpointClasses(); if (IsValid(CurrentMainBounty)) GI->MainSaveGameInstanceRef->OpenWorldCheckpointsClassesSave = CurrentMainBounty->GetOpenWorldCheckpointClasses();
GI->MainSaveGameInstanceRef->PlayerOpenWorldSpawnTransformSave = OpenWorldRespawnTransform;
// if main bounty exists, save its locally stored open world respawn transform
// otherwise, store it as 0,0,0 which will make the player spawn at player start instead
FTransform EmptyTransform;
GI->MainSaveGameInstanceRef->PlayerOpenWorldSpawnTransformSave = IsValid(CurrentMainBounty) ? CurrentMainBounty->GetOpenWorldRespawnTransform() : EmptyTransform;
//GI->MainSaveGameInstanceRef->PlayerOpenWorldSpawnTransformSave = GetActorTransform();
UGameplayStatics::SaveGameToSlot(GI->MainSaveGameInstanceRef, "MainSave", 0); UGameplayStatics::SaveGameToSlot(GI->MainSaveGameInstanceRef, "MainSave", 0);
} }

View File

@ -48,6 +48,9 @@ class ENDLESSVENDETTA_API ABountyHunterCharacter : public AEndlessVendettaCharac
// Used to Check if all Main Bounties have been completed by the Bounties Tab // Used to Check if all Main Bounties have been completed by the Bounties Tab
bool CompletedMainBounties = false; bool CompletedMainBounties = false;
// Used to Decide Where in the Open World to Respawn the Player
FTransform OpenWorldRespawnTransform;
protected: protected:
public: public:
@ -85,6 +88,12 @@ protected:
UFUNCTION(BlueprintImplementableEvent) UFUNCTION(BlueprintImplementableEvent)
void DisplayCheckpointTip(const FString& NewCheckpointTip); void DisplayCheckpointTip(const FString& NewCheckpointTip);
UFUNCTION()
void SetOpenWorldRespawnTransform(FTransform RespawnTransform)
{
OpenWorldRespawnTransform = RespawnTransform;
}
// Overridden to Setup up Pause Menu Inputs // Overridden to Setup up Pause Menu Inputs
virtual void SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) override; virtual void SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) override;