diff --git a/Source/TurnBasedTutorial/BattleMode/GameOverWidget.cpp b/Source/TurnBasedTutorial/BattleMode/GameOverWidget.cpp index e6c1180..4e25a46 100644 --- a/Source/TurnBasedTutorial/BattleMode/GameOverWidget.cpp +++ b/Source/TurnBasedTutorial/BattleMode/GameOverWidget.cpp @@ -11,7 +11,7 @@ void UGameOverWidget::NativeConstruct() { ButtonToMenu->OnClicked.AddDynamic(this, &ThisClass::QuitCurrentSession); } -void UGameOverWidget::QuitCurrentSession_Implementation() { +void UGameOverWidget::QuitCurrentSession() { const UGameInstance *GameInstance = UGameplayStatics::GetGameInstance( GetWorld()); USessionsGameInstanceSubsystem *GameInstanceSubsystem = GameInstance->GetSubsystem diff --git a/Source/TurnBasedTutorial/BattleMode/GameOverWidget.h b/Source/TurnBasedTutorial/BattleMode/GameOverWidget.h index 2a28630..82402fe 100644 --- a/Source/TurnBasedTutorial/BattleMode/GameOverWidget.h +++ b/Source/TurnBasedTutorial/BattleMode/GameOverWidget.h @@ -19,7 +19,7 @@ public: UFUNCTION(Client, Reliable) void SetWidgetText(bool HasWon); - UFUNCTION(Client, Reliable) + UFUNCTION() void QuitCurrentSession(); protected: diff --git a/Source/TurnBasedTutorial/MainMenu/MainMenuWidget.cpp b/Source/TurnBasedTutorial/MainMenu/MainMenuWidget.cpp index 3a13569..0baf22f 100644 --- a/Source/TurnBasedTutorial/MainMenu/MainMenuWidget.cpp +++ b/Source/TurnBasedTutorial/MainMenu/MainMenuWidget.cpp @@ -16,11 +16,17 @@ void UMainMenuWidget::NativeConstruct() { } void UMainMenuWidget::OnHostOnlineGameButtonClicked() { + // Ensure we have left any session + GetMyGameSubsystem()->DestroySession(); + GetMyGameSubsystem()->CreateSession( "Lobby " + FString::FromInt(FMath::RandRange(1, 1e6)), 2, true); } void UMainMenuWidget::StartSessionWhenCreatingSessonComplete(bool bSuccess) { + if (!bSuccess) { + return; + } GetMyGameSubsystem()->StartSession(); } diff --git a/Source/TurnBasedTutorial/MainMenu/SessionListWidget.cpp b/Source/TurnBasedTutorial/MainMenu/SessionListWidget.cpp index a6794f9..af32814 100644 --- a/Source/TurnBasedTutorial/MainMenu/SessionListWidget.cpp +++ b/Source/TurnBasedTutorial/MainMenu/SessionListWidget.cpp @@ -22,6 +22,9 @@ void USessionListWidget::NativeConstruct() { MyGameInstanceSubsystem->OnJoinSessionCompleteEvent.AddUObject( this, &ThisClass::OnJoinSessionSuccess); + // Ensure we have left any session + GetMyGameSubsystem()->DestroySession(); + // Initiate search MyGameInstanceSubsystem->FindSessions(10, true); }