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"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

What class should I override to change session settings and how to add it?

for example I don't want anyone to be able to join the session if the game started, add some info like server/room name, current map and GameType/GameMode, stuff that's also set inside lobby (changed before game starts but after joining session) like game length and difficulty etc and you should be able to get all just from the session result without joining one

Product Version: UE 4.13
more ▼

asked Dec 02 '16 at 05:16 PM in C++ Programming

avatar image

25 11 13 15

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

1 answer: sort voted first

There's no need to override a class. SessionSettings is something like a dictionary so you can add any key value pair you want. So when you find a Session with a client, you can check the SessionSettings and the info you added will be there, so then you can do whatever you want based on it.

You can see eXi does it in this part of his tutorial about sessions.

 bool UNWGameInstance::HostSession(TSharedPtr<const FUniqueNetId> UserId, FName SessionName, bool bIsLAN, bool bIsPresence, int32 MaxNumPlayers)
     // Get the Online Subsystem to work with
     IOnlineSubsystem* const OnlineSub = IOnlineSubsystem::Get();
     if (OnlineSub)
         // Get the Session Interface, so we can call the "CreateSession" function on it
         IOnlineSessionPtr Sessions = OnlineSub->GetSessionInterface();
         if (Sessions.IsValid() && UserId.IsValid())
                 Fill in all the Session Settings that we want to use.
                 There are more with SessionSettings.Set(...);
                 For example the Map or the GameMode/Type.
             SessionSettings = MakeShareable(new FOnlineSessionSettings());
             SessionSettings->bIsLANMatch = bIsLAN;
             SessionSettings->bUsesPresence = bIsPresence;
             SessionSettings->NumPublicConnections = MaxNumPlayers;
             SessionSettings->NumPrivateConnections = 0;
             SessionSettings->bAllowInvites = true;
             SessionSettings->bAllowJoinInProgress = true;
             SessionSettings->bShouldAdvertise = true;
             SessionSettings->bAllowJoinViaPresence = true;
             SessionSettings->bAllowJoinViaPresenceFriendsOnly = false;
             SessionSettings->Set(SETTING_MAPNAME, FString("NewMap"), EOnlineDataAdvertisementType::ViaOnlineService);
             // Set the delegate to the Handle of the SessionInterface
             OnCreateSessionCompleteDelegateHandle = Sessions->AddOnCreateSessionCompleteDelegate_Handle(OnCreateSessionCompleteDelegate);
             // Our delegate should get called when this is complete (doesn't need to be successful!)
             return Sessions->CreateSession(*UserId, SessionName, *SessionSettings);
         GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Red, TEXT("No OnlineSubsytem found!"));
     return false;

See the "SessionSettings->Set(SETTING_MAPNAME, FString("NewMap"), EOnlineDataAdvertisementType::ViaOnlineService);" line?

He is doing it right there. You could do the same with any other piece of info. Also SessionSettings already has a boolean that prevents people from joining if the game has already started.

Hope this helps

more ▼

answered Dec 02 '16 at 05:25 PM

avatar image

717 18 6 26

avatar image aa1000 Dec 02 '16 at 05:41 PM

Thank you for your answer, how can I add extra custom keys like time though, just put a name and a value in the ->set function?

avatar image Rekenq Dec 02 '16 at 06:11 PM

Yup. And then when you find a session use the get function to retrieve the pair.

Here's the link to the FOnlineSessionSettings class. It's pretty straight forward https://docs.unrealengine.com/latest/INT/API/Runtime/OnlineSubsystem/FOnlineSessionSettings/index.html

avatar image aa1000 Dec 02 '16 at 06:30 PM

I read it but for example if I wanted SETTING_TIME instead of SETTING_MAPNAME and it takes a float instead of a String, where or how can I define that? In the GameInstance header and just use ->Set with it?

avatar image Rekenq Dec 02 '16 at 09:11 PM

Yeah you just pass the key value pair to the Set function, pretty sure you can put floats in there too, or you could construct a FOnlineSessionSetting object with the values you want and just pass that to your FOnlineSessionSetings Set function.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
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