Epic Online Services

An guide to OnlineSubsystem: Epic Online Services

  • Introduction

    Guide is, among other sources, inspired by Sneaky Kitty Game Dev's tutorial series on Epic Online Services, purpose is to combine knowledge over here and convey it in written language.

Setup

First of all you will have to download Epic Online Services SDK, type is programming language „C“, version preferably the latest. Subsequently extract the Zip on your Desktop, open the Samples.sln with your favourite Integrated Development Environment, build AuthAndFriends. After that unfold AuthAndFriends and lookout for SampleConstants.h.

Now go to Developer Portal, click Create Product, name it whatever you want. Click on your newly created Product and head down to Product Settings, there you see three IDs & your GameName. Paste your Product ID, Sandbox ID, Deployment ID & GameName, step by step into SampleConstants.h. Client Credentials ID & ClientCredentialsSecret remains blank, it's going to be generated in the next step.

In your Product Settings tab, click on Clients, look for Client Policies. Click Add New Client Policy, name it whatever you want. As your Client Policy Type pick Custom, its advisable to enable User required, check all selectable features as well as allowed actions. Next up, Add New Client, in the Client Policy field pick the one you just created, other option(s) can be ignored still.

Once again in the Developer Portal, on the left side, click Epic Account Services. If there is no Application created already, create one. Click on Permissions, enable Online Presence and Friends. After that click on Linked Clients, pick your Client.

Return to your Samples.sln, press Debug — an AuthAndFriends window should appear. On the right side click Account Portal → Log In. An web page is going to pop-up and request Permission, click Continue to App and Allow. Done! All the just taken steps confirm us that our product and all the needed information is working & ready, we can now move on to the next point.

Epic Online Services

For the sake of making life easier I've created an basic downloadable Epic Online Services project prototype which we will use as base from now on, it has login implemented already too, it gives you a decent head start to begin tinkering. In order to get the project started you have to fill out the missing SDK Credentials in DefaultEngine. Once opened try it out and press Play to Login.

Authentication (Optional)

At this section we are going to use the Developer Authentication Tool to make the login process less repetitive, result will be that Epic Games remembers your account thus you wont have to Login everytime you press Play to test out new functions. It's a time-saver method basically.

Open the Dev Auth Tool you find in the Epic Online Services project prototype folder. For Port use „8081“, Login, pick an name, you will use that name here & in the future, so remember it.

You will have to edit that piece of code..

void UEOSGameInstance::Login() { if (OnlineSubsystem) { if (IOnlineIdentityPtr Identity = OnlineSubsystem->GetIdentityInterface()) { FOnlineAccountCredentials Credentials; Credentials.Id = FString(""); Credentials.Token = FString(""); Credentials.Type = FString("accountportal"); Identity->OnLoginCompleteDelegates->AddUObject(this, &UEOSGameInstance::OnLoginComplete); Identity->Login(0, Credentials); } } }

Complete Credentials.Id = FString();, to Credentials.Id = FString("127.0.0.1:8081");, complete Credentials.Token = FString("YourName"); with your name, replace Credentials.Type = FString("accountportal"); with Credentials.Type = FString("developer");.

EOSPlus (Optional)

Soon..

Create Session
void UEOSGameInstance::CreateSession();
void UEOSGameInstance::CreateSession() { if (bIsLoggedIn) { if (OnlineSubsystem) { if (IOnlineSessionPtr SessionPtr = OnlineSubsystem->GetSessionInterface()) { FOnlineSessionSettings SessionSettings; SessionSettings.bIsDedicated = false; SessionSettings.bShouldAdvertise = true; SessionSettings.bIsLANMatch = false; SessionSettings.NumPublicConnections = 5; SessionSettings.bAllowJoinInProgress = true; SessionSettings.bAllowJoinViaPresence = true; SessionSettings.bUsesPresence = true; SessionSettings.bUseLobbiesIfAvailable = true; SessionSettings.Set(SEARCH_KEYWORDS, FString("YTTutorialLobby"), EOnlineDataAdvertisementType::ViaOnlineService); SessionPtr->OnCreateSessionCompleteDelegates.AddUObject(this, &UEOSGameInstance::OnCreateSessionComplete); SessionPtr->CreateSession(0, TestSessionName, SessionSettings); } } } else { UE_LOG(LogTemp, Error, TEXT("Cannot Create Session: Not Logged In")); } }
void OnCreateSessionComplete(FName SessionName, bool bWasSuccessful);
void UEOSGameInstance::OnCreateSessionComplete(FName SessionName, bool bWasSuccessful) { UE_LOG(LogTemp, Warning, TEXT("OnCreateSessionComplete: %d"), bWasSuccessful); if (OnlineSubsystem) { if (IOnlineSessionPtr SessionPtr = OnlineSubsystem->GetSessionInterface()) { SessionPtr->ClearOnCreateSessionCompleteDelegates(this); GetWorld()->ServerTravel(FString("ThirdPersonExampleMap?listen"), false); } } }
Destroy Session
void DestroySession();
void UEOSGameInstance::DestroySession() { if (bIsLoggedIn) { if (OnlineSubsystem) { if (IOnlineSessionPtr SessionPtr = OnlineSubsystem->GetSessionInterface()) { SessionPtr->OnDestroySessionCompleteDelegates.AddUObject(this, &UEOSGameInstance::OnDestroySessionComplete); SessionPtr->DestroySession(TestSessionName); } } } }
void OnDestroySessionComplete(FName SessionName, bool bWasSuccessful);
void UEOSGameInstance::OnDestroySessionComplete(FName SessionName, bool bWasSuccessful) { if (OnlineSubsystem) { if (IOnlineSessionPtr SessionPtr = OnlineSubsystem->GetSessionInterface()) { SessionPtr->ClearOnDestroySessionCompleteDelegates(this); } } }
Get Friends
void GetAllFriends();
void UEOSGameInstance::GetAllFriends() { if (bIsLoggedIn) { if (OnlineSubsystem) { if (IOnlineFriendsPtr FriendsPtr = OnlineSubsystem->GetFriendsInterface()) { FriendsPtr->ReadFriendsList(0, FString(""), FOnReadFriendsListComplete::CreateUObject(this, &UEOSGameInstance::OnGetAllFriendsComplete)); } } } }
void OnGetAllFriendsComplete(int32 LocalUserNum, bool bWasSuccessful, const FString& ListName, const FString& ErrorStr);
void UEOSGameInstance::OnGetAllFriendsComplete(int32 LocalUserNum, bool bWasSuccessful, const FString& ListName, const FString& ErrorStr) { if (bWasSuccessful) { if (OnlineSubsystem) { if (IOnlineFriendsPtr FriendsPtr = OnlineSubsystem->GetFriendsInterface()) { TArray<TSharedRef<FOnlineFriend>> FriendsList; if (FriendsPtr->GetFriendsList(0, ListName, FriendsList)) { for (TSharedRef<FOnlineFriend> Friend : FriendsList) { FString FriendName = Friend.Get().GetRealName(); UE_LOG(LogTemp, Warning, TEXT("Friend: %s"), *FriendName); } } } } } }
Show Invite UI
void ShowInviteUI();
void UEOSGameInstance::ShowInviteUI() { if (bIsLoggedIn) { if (OnlineSubsystem) { if (IOnlineExternalUIPtr UIPtr = OnlineSubsystem->GetExternalUIInterface()) { UIPtr->ShowInviteUI(0, TestSessionName); } } } }
Show Friends UI
void ShowFriendsUI();
void UEOSGameInstance::ShowFriendsUI() { if (bIsLoggedIn) { if (OnlineSubsystem) { if (IOnlineExternalUIPtr UIPtr = OnlineSubsystem->GetExternalUIInterface()) { UIPtr->ShowFriendsUI(0); } } } }

Help

You are seeking support on getting Epic Online Services and & or Online Subsystem running for your game? EOS Help or Unreal Slackers, Forums, AnswerHub, Sneaky Kitty Tutorials, Flopperam & The Aphix Community can be your go-to!

Code Snippets

In case you are looking out for Code Examples, there a few repositories which make use of or expose Epic Online Services & Online Subsystem, those are: EOSYTTutorial, AdvancedSessionsPlugin and OnlineSubsystemUtils.

Epic Account Services

Soon..

Updated ago
Plugins
Extended Docs
Online