Hi, I was trying to make a multiplayer system along with a tutorial but in the JoinSession section my game crashes.
Here is my code:
void AMultiplayerShooterCharacter::OnFindSessionComplete(bool bWasSuccessful)
{
if(!OnlineSessionInterface.IsValid()) return;
if(bWasSuccessful && SearchSettings->SearchResults.Num() > 0)
{
if(GEngine)
{
GEngine->AddOnScreenDebugMessage(
-1,
15.f,
FColor::Green,
FString::Printf(TEXT("Sessions Found:"))
);
}
for (auto Result : SearchSettings->SearchResults)
{
FString Id = Result.GetSessionIdStr();
FString User = Result.Session.OwningUserName;
FString MatchType;
Result.Session.SessionSettings.Get(FName("MatchType"),MatchType);
if(MatchType == FString("FreeForAll"))
{
if (GEngine)
{
GEngine->AddOnScreenDebugMessage(
-1,
15.f,
FColor::Cyan,
FString::Printf(TEXT("Joining Match Type: %s ..."), *MatchType)
);
}
OnlineSessionInterface->AddOnJoinSessionCompleteDelegate_Handle(OnSessionJoinedDelegate);
ULocalPlayer* LocalPlayer = GetWorld()->GetFirstLocalPlayerFromController();
OnlineSessionInterface->JoinSession(*LocalPlayer->GetPreferredUniqueNetId(), NAME_GameSession, Result); //Here the game crashes
}
if(GEngine)
{
GEngine->AddOnScreenDebugMessage(
-1,
15.f,
FColor::Blue,
FString::Printf(TEXT("ID: %s | Owner: %s"),*Id,*User)
);
}
}
}
else
{
if(GEngine)
{
GEngine->AddOnScreenDebugMessage(
-1,
15.f,
FColor::Red,
FString::Printf(TEXT("Couldn't find any session"))
);
}
}
}
It’s the Engine.ini content:
[/Script/EngineSettings.GameMapsSettings]
GameDefaultMap=/Game/ThirdPersonCPP/Maps/ThirdPersonExampleMap
EditorStartupMap=/Game/ThirdPersonCPP/Maps/ThirdPersonExampleMap
GlobalDefaultGameMode="/Script/MultiplayerTest.MultiplayerTestGameMode"
[/Script/IOSRuntimeSettings.IOSRuntimeSettings]
MinimumiOSVersion=IOS_12
[/Script/HardwareTargeting.HardwareTargetingSettings]
TargetedHardwareClass=Desktop
AppliedTargetedHardwareClass=Desktop
DefaultGraphicsPerformance=Maximum
AppliedDefaultGraphicsPerformance=Maximum
[/Script/Engine.Engine]
+ActiveGameNameRedirects=(OldGameName="TP_ThirdPerson",NewGameName="/Script/MultiplayerTest")
+ActiveGameNameRedirects=(OldGameName="/Script/TP_ThirdPerson",NewGameName="/Script/MultiplayerTest")
+ActiveClassRedirects=(OldClassName="TP_ThirdPersonGameMode",NewClassName="MultiplayerTestGameMode")
+ActiveClassRedirects=(OldClassName="TP_ThirdPersonCharacter",NewClassName="MultiplayerTestCharacter")
[/Script/Engine.GameEngine]
+NetDriverDefinitions=(DefName="GameNetDriver",DriverClassName="OnlineSubsystemSteam.SteamNetDriver",DriverClassNameFallback="OnlineSubsystemUtils.IpNetDriver")
[OnlineSubsystem]
DefaultPlatformService=Steam
[OnlineSubsystemSteam]
bEnabled=true
SteamDevAppId=480
bInitServerOnClient=true
[/Script/OnlineSubsystemSteam.SteamNetDriver]
NetConnectionClassName="OnlineSubsystemSteam.SteamNetConnection"
and the crash message:
in my tests every thing except joining was OK, the session creates and also when I search I can find the created session but when I try to join it crashes.
I will attach the corresponding files as well.
DefaultEngine.ini (1.4 KB)
MultiplayerTestCharacter.h (3.1 KB)
MultiplayerTestCharacter.cpp (11.8 KB)
MultiplayerTest.Build.cs (427 Bytes)