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);
}
void UGameOverWidget::QuitCurrentSession_Implementation() {
void UGameOverWidget::QuitCurrentSession() {
const UGameInstance *GameInstance = UGameplayStatics::GetGameInstance(
GetWorld());
USessionsGameInstanceSubsystem *GameInstanceSubsystem = GameInstance->GetSubsystem

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

@ -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();
}

@ -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);
}

Loading…
Cancel
Save