I try to make multiplayer game in C++ using Online Subsystem (ordinary subsystem, not Steam). I created 2 levels: MainMenu and Lobby. I set PIE Net Mode “Play Standalone” and 2 players. After that, using first player window, start session as listen server and after creating session and opening level tries to connect second player. The second player joins server, but while opening level editor crashes with same log when I try to create 2 listen server while PIE (Net Mode “Play Standalone”). I’m sure I create one listen server (use IOnlineSessionPtr::StartSession(NAME_GameSession) and UGameplayStatics::OpenLevel(GetWorld(), LevelName, true, FString("?listen"))) and tries to connect (use IOnlineSessionPtr::JoinSession(*LocalPlayer->GetPreferredUniqueNetId(), NAME_GameSession, SessionResult) and APlayerController::ClientTravel(ConnectString, TRAVEL_Absolute)). If I set a Net Mode “Play As Listen Server” and tries to open Lobby, level opens perfectly for both server and client.
Function for create session:
void UOnlineGameInstance::StartSession(){
IOnlineSessionPtr inter = Online::GetSessionInterface(GetWorld());
if (!inter.IsValid()) {
OnStartSessionCompleteEvent.Broadcast(false);
return;
}
StartSessionCompleteDelegateHandle = inter->AddOnStartSessionCompleteDelegate_Handle(StartSessionCompleteDelegate);
if (!inter->StartSession(NAME_GameSession)) {
inter->ClearOnStartSessionCompleteDelegate_Handle(StartSessionCompleteDelegateHandle);
OnStartSessionCompleteEvent.Broadcast(false);
}
}
Function on create session:
void UOnlineGameInstance::OnCreateSessionCompleted(FName SessionName, bool Successful){
IOnlineSessionPtr inter = Online::GetSessionInterface(GetWorld());
if (inter.IsValid()) {
inter->ClearOnCreateSessionCompleteDelegate_Handle(CreateSessionCompleteDelegateHandle);
}
OnCreateSessionCompleteEvent.Broadcast(Successful);
}
Function for open map on server (calls via delegate):
void UMenuUserWidget::OnCreateSession(bool Sucsess){
if (Sucsess) {
UGameplayStatics::OpenLevel(GetWorld(), LevelName, true, FString("?listen"));
}
}
Function to join session:
void UOnlineGameInstance::JoinGameSession(const FOnlineSessionSearchResult& SessionResult){
IOnlineSessionPtr inter = Online::GetSessionInterface(GetWorld());
if (!inter.IsValid()) {
OnJoinGameSessionCompleteEvent.Broadcast(FName(), UnknownError);
//OnJoinGameSessionCompleteEvent.Broadcast(FName(), EOnJoinSessionCompleteResult::UnknownError);
return;
}
JoinSessionCompleteDelegateHandle = inter->AddOnJoinSessionCompleteDelegate_Handle(JoinSessionCompleteDelegate);
ULocalPlayer* LocalPlayer = GetWorld()->GetFirstLocalPlayerFromController();
if (!inter->JoinSession(*LocalPlayer->GetPreferredUniqueNetId(), NAME_GameSession, SessionResult)){
inter->ClearOnJoinSessionCompleteDelegate_Handle(JoinSessionCompleteDelegateHandle);
OnJoinGameSessionCompleteEvent.Broadcast(FName(), UnknownError);
//OnJoinGameSessionCompleteEvent.Broadcast(FName(), EOnJoinSessionCompleteResult::UnknownError);
}
}
Function on join session:
void UOnlineGameInstance::OnJoinSessionCompleted(FName SessionName, EOnJoinSessionCompleteResult::Type Result){
IOnlineSessionPtr inter = Online::GetSessionInterface(GetWorld());
if (inter.IsValid()) {
inter->ClearOnJoinSessionCompleteDelegate_Handle(JoinSessionCompleteDelegateHandle);
}
TryTravelToCurrentSession();
TEnumAsByte<EUOnJoinSessionCompleteResult> res = (TEnumAsByte<EUOnJoinSessionCompleteResult>)Result;
OnJoinGameSessionCompleteEvent.Broadcast(SessionName, res);
//OnJoinGameSessionCompleteEvent.Broadcast(SessionName, Result);
}
Function to open lobby for client:
bool UOnlineGameInstance::TryTravelToCurrentSession(){
IOnlineSessionPtr inter = Online::GetSessionInterface(GetWorld());
if (!inter.IsValid()){
return false;
}
FString ConnectString;
if (!inter->GetResolvedConnectString(NAME_GameSession, ConnectString)){
return false;
}
APlayerController* PlayerController = GetWorld()->GetFirstPlayerController();
PlayerController->ClientTravel(ConnectString, TRAVEL_Absolute);
return true;
}
Error log in crash reporter:
LoginId:b390a636498bcdda5b6a57b5eeb7ab95
EpicAccountId:3db069b914574e50b9ddd58e0c105eee
Assertion failed: PIEInstanceID != INDEX_NONE [File:D:\build\++UE5\Sync\Engine\Source\Runtime\CoreUObject\Private\UObject\LazyObjectPtr.cpp] [Line: 22]
UnrealEditor_CoreUObject!FLazyObjectPtr::PossiblySerializeObjectGuid() [D:\build\++UE5\Sync\Engine\Source\Runtime\CoreUObject\Private\UObject\LazyObjectPtr.cpp:150]
UnrealEditor_CoreUObject!UObject::Serialize() [D:\build\++UE5\Sync\Engine\Source\Runtime\CoreUObject\Private\UObject\Obj.cpp:1461]
UnrealEditor_CoreUObject!UObject::Serialize() [D:\build\++UE5\Sync\Engine\Source\Runtime\CoreUObject\Private\UObject\Obj.cpp:1320]
UnrealEditor_Engine!AActor::Serialize() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\Actor.cpp:838]
UnrealEditor_Landscape!ALandscapeProxy::Serialize() [D:\build\++UE5\Sync\Engine\Source\Runtime\Landscape\Private\Landscape.cpp:2244]
UnrealEditor_CoreUObject!FLinkerLoad::Preload() [D:\build\++UE5\Sync\Engine\Source\Runtime\CoreUObject\Private\UObject\LinkerLoad.cpp:4388]
UnrealEditor_CoreUObject!EndLoad() [D:\build\++UE5\Sync\Engine\Source\Runtime\CoreUObject\Private\UObject\UObjectGlobals.cpp:1658]
UnrealEditor_CoreUObject!<lambda_c8710bcd35c9e247c18bb173ed0f9483>::operator()() [D:\build\++UE5\Sync\Engine\Source\Runtime\CoreUObject\Private\UObject\UObjectGlobals.cpp:1264]
UnrealEditor_CoreUObject!LoadPackageInternal() [D:\build\++UE5\Sync\Engine\Source\Runtime\CoreUObject\Private\UObject\UObjectGlobals.cpp:1366]
UnrealEditor_CoreUObject!LoadPackage() [D:\build\++UE5\Sync\Engine\Source\Runtime\CoreUObject\Private\UObject\UObjectGlobals.cpp:1520]
UnrealEditor_CoreUObject!LoadPackage() [D:\build\++UE5\Sync\Engine\Source\Runtime\CoreUObject\Private\UObject\UObjectGlobals.cpp:1500]
UnrealEditor_Engine!`anonymous namespace'::CreatePIEWorldByLoadingFromPackage() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\UnrealEngine.cpp:1082]
UnrealEditor_Engine!UEngine::LoadMap() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\UnrealEngine.cpp:13941]
UnrealEditor_Engine!UEngine::TickWorldTravel() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\UnrealEngine.cpp:13647]
UnrealEditor_UnrealEd!UEditorEngine::Tick() [D:\build\++UE5\Sync\Engine\Source\Editor\UnrealEd\Private\EditorEngine.cpp:1751]
UnrealEditor_UnrealEd!UUnrealEdEngine::Tick() [D:\build\++UE5\Sync\Engine\Source\Editor\UnrealEd\Private\UnrealEdEngine.cpp:474]
UnrealEditor!FEngineLoop::Tick() [D:\build\++UE5\Sync\Engine\Source\Runtime\Launch\Private\LaunchEngineLoop.cpp:5215]
UnrealEditor!GuardedMain() [D:\build\++UE5\Sync\Engine\Source\Runtime\Launch\Private\Launch.cpp:183]
UnrealEditor!GuardedMainWrapper() [D:\build\++UE5\Sync\Engine\Source\Runtime\Launch\Private\Windows\LaunchWindows.cpp:147]
UnrealEditor!LaunchWindowsStartup() [D:\build\++UE5\Sync\Engine\Source\Runtime\Launch\Private\Windows\LaunchWindows.cpp:283]
UnrealEditor!WinMain() [D:\build\++UE5\Sync\Engine\Source\Runtime\Launch\Private\Windows\LaunchWindows.cpp:330]
UnrealEditor!__scrt_common_main_seh() [d:\a01\_work\6\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288]
kernel32
ntdll
Editor log:
FlightProject.log (89.1 KB)