Hi Epicfolk,
I’m working on an OSS Steam integration in UE4.27, and I’m hitting a snag:
I set up the online subsystem using the info here, and it seemed to be going smoothly. I’m able to create a session, search for it, and join the session using another Steam account on a different PC.
Once two players are in the session, I have a problem: session->RegisteredPlayers isn’t being updated. My understanding is that this array should contain a list of the SteamIds for all players in the session, but session->RegisteredPlayers.Num() returns 0, and I don’t see any other way to get the SteamIds of players in the session.
Also, I’ve set up delegates for these callbacks, but neither of the delegates fires for the session host when another player joins the session:
- OnSessionParticipantsChange
- OnRegisterPlayersComplete
Other pieces of information about the session like session->OwningUserId and session->GetSessionIdStr() return the correct value for all players, so I think the players have joined the session successfully. But I haven’t found a way to exchange the SteamIds!
Why I need the SteamIds: I’m trying to set up a P2P connection using SteamSockets, which requires the SteamIds for NAT punchthrough and starting the connection.
Any ideas I can try?
Abridged code snippets, in case they’re relevant:
//Called when clicking a button in the UI to create a new session
void UMultiplayerSessionsSubsystem::CreateSession(int32 NumPublicConnections, FString SessionName)
{
//Create a new session settings object
TSharedPtr<FOnlineSessionSettings> SessionSettings = MakeShareable(new FOnlineSessionSettings());
//Standard settings (creating as a lobby, with presence)
SessionSettings->bIsDedicated = false;
SessionSettings->NumPublicConnections = NumPublicConnections;
SessionSettings->bAllowJoinInProgress = true;
SessionSettings->bAllowJoinViaPresence = true;
SessionSettings->bIsLANMatch = false;
SessionSettings->bShouldAdvertise = true;
SessionSettings->bUsesPresence = true;
SessionSettings->Set(FName("SessionName"), SessionName, EOnlineDataAdvertisementType::ViaOnlineServiceAndPing);
SessionSettings->bUseLobbiesIfAvailable = true;
//Create the session
SessionInterface->CreateSession(*NetId, NAME_GameSession, *LastSessionSettings);
}
//Called when selecting a session to join (after doing a search for sessions)
void UMultiplayerSessionsSubsystem::JoinSession(const FOnlineSessionSearchResult& SessionResult)
{
//Note: after joining the session, the OnJoinSessionComplete callback is called for the joining player. But no callbacks are called for the session host, so the host doesn't know about the new player.
SessionInterface->JoinSession(*NetId, NAME_GameSession, SessionResult);
}
void UMultiplayerSessionSubsystem::PrintSessionData()
{
//Get the named session object (the session name is stored when joining, for lookup)
FNamedOnlineSession* session = SessionInterface->GetNamedSession(CurrentSessionName);
//Print info. This correctly prints GetSessionIdStr(), but shows 0 for RegisteredPlayers.Num()
GEngine->AddOnScreenDebugMessage(
-1,
15.f,
FColor::Green,
FString::Printf(TEXT("UMultiplayerSessionMenu::Tick --- net ids in session %s: %d), *session->GetSessionIdStr(), session->RegisteredPlayers.Num())
);
}