I use UE5.2.1. Player A called CreateSession(), while Player B called JoinSession(), and everything has been normal since then. But when Player A called DestroySession() and even closed the game, Player B did not receive any notification. Player B’s FOnDestroySessionCompleteDelegate will only be triggered when Player B calls DestroySession() itself.
In addition, FOnSessionParticipantJoinedDelegate, FOnSessionParticipantLeftDelegate, and FOnSessionParticipantsChangeDelegate were not triggered in both Player A and Player B.
Thanks.
void UMyGameInstanceSubsystem::OnCreateSessionComplete(FName SessionName, bool bWasSuccessful)
{
_onlineSession->ClearOnCreateSessionCompleteDelegate_Handle(_dhOnCreateSessionComplete);
if (bWasSuccessful)
{
_currentSessionName = SessionName;
Log(FString::Printf(TEXT("createsession %s success"), *SessionName.ToString()));
_dhOnSessionParticipantJoined = _onlineSession->AddOnSessionParticipantJoinedDelegate_Handle(_dlgOnSessionParticipantJoined);
_dhOnSessionParticipantLeft = _onlineSession->AddOnSessionParticipantLeftDelegate_Handle(_dlgOnSessionParticipantLeft);
_dhOnDestroySessionComplete = _onlineSession->AddOnDestroySessionCompleteDelegate_Handle(_dlgOnDestroySessionComplete);
_dhOnSessionParticipantsChange = _onlineSession->AddOnSessionParticipantsChangeDelegate_Handle(_dlgOnSessionParticipantsChange);
UWorld* world = GetWorld();
if (world)
{
if (!world->ServerTravel("/Game/Maps/Lobby?listen"))
{
LogError(TEXT("ServerTravel failed"));
}
}
}
else
{
_currentSessionName = "";
}
}
void UMyGameInstanceSubsystem::OnJoinSessionComplete(FName SessionName, EOnJoinSessionCompleteResult::Type result)
{
if (!_onlineSession.IsValid())
{
return;
}
_currentSessionName = SessionName;
_onlineSession->ClearOnJoinSessionCompleteDelegate_Handle(_dhOnJoinSessionComplete);
if (result == EOnJoinSessionCompleteResult::Success)
{
Log(TEXT("JoinSession success"));
_dhOnSessionParticipantJoined = _onlineSession->AddOnSessionParticipantJoinedDelegate_Handle(_dlgOnSessionParticipantJoined);
_dhOnSessionParticipantLeft = _onlineSession->AddOnSessionParticipantLeftDelegate_Handle(_dlgOnSessionParticipantLeft);
_dhOnDestroySessionComplete = _onlineSession->AddOnDestroySessionCompleteDelegate_Handle(_dlgOnDestroySessionComplete);
_dhOnSessionParticipantsChange = _onlineSession->AddOnSessionParticipantsChangeDelegate_Handle(_dlgOnSessionParticipantsChange);
}