Forcefully destroy sessions before connecting or creating new

pull/6/head
eyakm1 2 years ago
parent d7b7c46cd5
commit 8a4646bdb3

@ -11,7 +11,7 @@ void UGameOverWidget::NativeConstruct() {
ButtonToMenu->OnClicked.AddDynamic(this, &ThisClass::QuitCurrentSession); ButtonToMenu->OnClicked.AddDynamic(this, &ThisClass::QuitCurrentSession);
} }
void UGameOverWidget::QuitCurrentSession_Implementation() { void UGameOverWidget::QuitCurrentSession() {
const UGameInstance *GameInstance = UGameplayStatics::GetGameInstance( const UGameInstance *GameInstance = UGameplayStatics::GetGameInstance(
GetWorld()); GetWorld());
USessionsGameInstanceSubsystem *GameInstanceSubsystem = GameInstance->GetSubsystem USessionsGameInstanceSubsystem *GameInstanceSubsystem = GameInstance->GetSubsystem

@ -19,7 +19,7 @@ public:
UFUNCTION(Client, Reliable) UFUNCTION(Client, Reliable)
void SetWidgetText(bool HasWon); void SetWidgetText(bool HasWon);
UFUNCTION(Client, Reliable) UFUNCTION()
void QuitCurrentSession(); void QuitCurrentSession();
protected: protected:

@ -16,11 +16,17 @@ void UMainMenuWidget::NativeConstruct() {
} }
void UMainMenuWidget::OnHostOnlineGameButtonClicked() { void UMainMenuWidget::OnHostOnlineGameButtonClicked() {
// Ensure we have left any session
GetMyGameSubsystem()->DestroySession();
GetMyGameSubsystem()->CreateSession( GetMyGameSubsystem()->CreateSession(
"Lobby " + FString::FromInt(FMath::RandRange(1, 1e6)), 2, true); "Lobby " + FString::FromInt(FMath::RandRange(1, 1e6)), 2, true);
} }
void UMainMenuWidget::StartSessionWhenCreatingSessonComplete(bool bSuccess) { void UMainMenuWidget::StartSessionWhenCreatingSessonComplete(bool bSuccess) {
if (!bSuccess) {
return;
}
GetMyGameSubsystem()->StartSession(); GetMyGameSubsystem()->StartSession();
} }

@ -22,6 +22,9 @@ void USessionListWidget::NativeConstruct() {
MyGameInstanceSubsystem->OnJoinSessionCompleteEvent.AddUObject( MyGameInstanceSubsystem->OnJoinSessionCompleteEvent.AddUObject(
this, &ThisClass::OnJoinSessionSuccess); this, &ThisClass::OnJoinSessionSuccess);
// Ensure we have left any session
GetMyGameSubsystem()->DestroySession();
// Initiate search // Initiate search
MyGameInstanceSubsystem->FindSessions(10, true); MyGameInstanceSubsystem->FindSessions(10, true);
} }

Loading…
Cancel
Save