x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

C++ Create session not working like Blueprint node

Hello all!

I am currently working on implementing the sessions system into my game. With the blueprint nodes it worked as expected except that it lacks some functionality. So I decided to go for a C++ solution, however I can't quite get it to work. When I create a session with the BP node and start a listen server, my other client can find and join the session. But when I create and start a session and the server with C++ the client will not find it or won't load the map when joining.

Here is how the important code part looks like:

 AMenuPlayerController::AMenuPlayerController()
 {
     SessionSettings.bAllowJoinInProgress = true;
     SessionSettings.bUsesPresence = true;
     SessionSettings.bAllowJoinViaPresence = true;
 }
 
 void AMenuPlayerController::StartSession(bool bIsLANMatch, bool bShouldAdvertise, int32 NumPublicConnections)
 {
     if (bStartedSession) return;
 
     SessionSettings.bIsLANMatch = bIsLANMatch;
     SessionSettings.bShouldAdvertise = bShouldAdvertise;
     SessionSettings.NumPublicConnections = NumPublicConnections;
 
     if (PlayerState)
     {
         IOnlineSubsystem * OnlineSubsystem = IOnlineSubsystem::Get();
         if (OnlineSubsystem)
         {
             IOnlineSessionPtr SessionInterface = OnlineSubsystem->GetSessionInterface();
             if (SessionInterface.IsValid())
             {
                 DelegateHandle_CreateSessionComplete = SessionInterface->AddOnCreateSessionCompleteDelegate_Handle(OnCreateSessionCompleteDelegate);
                 SessionInterface->CreateSession(*PlayerState->UniqueId.GetUniqueNetId(), GameSessionName, SessionSettings);
             }
         }
     }
 }
 
 void AMenuPlayerController::StartServer(const FName & MapName)
 {
     if (!bStartedSession) return;
 
     NextMapName = MapName;
 
     IOnlineSubsystem * OnlineSubsystem = IOnlineSubsystem::Get();
     if (OnlineSubsystem)
     {
         IOnlineSessionPtr SessionInterface = OnlineSubsystem->GetSessionInterface();
         if (SessionInterface.IsValid())
         {
             DelegateHandle_StartSessionComplete = SessionInterface->AddOnStartSessionCompleteDelegate_Handle(OnStartSessionCompleteDelegate);
             SessionInterface->StartSession(GameSessionName);
         }
     }
 }
 
 void AMenuPlayerController::OnCreateSessionComplete(FName SessionName, bool bSuccessfull)
 {
     IOnlineSubsystem * OnlineSubsystem = IOnlineSubsystem::Get();
     if (OnlineSubsystem)
     {
         IOnlineSessionPtr SessionInterface = OnlineSubsystem->GetSessionInterface();
         if (SessionInterface.IsValid())
         {
             SessionInterface->ClearOnCreateSessionCompleteDelegate_Handle(DelegateHandle_CreateSessionComplete);
 
             if (bSuccessfull)
             {
                 bStartedSession = true;
             }
         }
     }
 }
 
 void AMenuPlayerController::OnStartSessionComplete(FName SessionName, bool bSuccessfull)
 {
     IOnlineSubsystem * OnlineSubsystem = IOnlineSubsystem::Get();
     if (OnlineSubsystem)
     {
         IOnlineSessionPtr SessionInterface = OnlineSubsystem->GetSessionInterface();
         if (SessionInterface.IsValid())
         {
             SessionInterface->ClearOnStartSessionCompleteDelegate_Handle(DelegateHandle_StartSessionComplete);
 
             if (bSuccessfull)
             {
                 UGameplayStatics::OpenLevel(this, NextMapName, true, TEXT("listen"));
             }
         }
     }
 }

Thanks in advance for you help!

Product Version: UE 4.8
Tags:
more ▼

asked Jul 07 '15 at 11:14 PM in C++ Programming

avatar image

Fluppi393
457 36 33 54

avatar image Fluppi393 Jul 13 '15 at 08:03 PM

Bumpi bump.

avatar image eXi Jul 13 '15 at 10:56 PM

I guess we, or at least i, need more information. Most of us haven't worked with C++ Server yet, and the Docs aren't that good. The ShooterGame is too packed with additional things to really understand how it works, so, you will need to debug it more.

Does creating the session work? Is the client able to find the session? Is the client really joining the session (can you see that on the server)? Is only the MapLoad failing?

Maybe also check the LOG. There should be some errors!

Because we need to know which part is failing to try to help you (:

avatar image Fluppi393 Jul 16 '15 at 01:15 PM

Hello, Creating the session seems to work as the CreateSessionCompleteDelegate is fired and bSuccessfull is true. However after opening a new map as a listen server I get the following warnings in the output log:

 LogOnline:Warning: NULL: No game present to join for session (Game)
 LogOnline:Warning: NULL: Can't start an online game for session (Game) that hasn't been created

So apparently after loading the map the session doesn't exist anylonger. Using the blueprint nodes to do pretty much the exact same thing works without those errors.

Any ideas what I did wrong here?

avatar image Fluppi393 Jul 24 '15 at 12:24 PM

Hello, I got a notification via e-mail about the last two comments on this topic and also on my profile page it says that somebody replied, but those last two comments are not being displayed right here which must be a bug of some sort.

However I know what you wrote from the e-mail. joeGraf mentioned that I forgot to enable join in progress, which he was right about but does not solve the problem unfortunatelly. alkor.isharioth commented that it could be due to the player controller being recreated at some point, but firstly it has to be destroyed and recreated as I use two different player controller classes in my main menu and the actual game. And secondly the create session will not return you a reference to a session which you have to store, I believe it is stored somewhere automatically. Calling the create session function really only initiates this process so it should be irrelevant from which class you call it.

Thank you for trying to help!

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question