Loading...
Searching...
No Matches
Quick Start Guide

This guide will help you get started with the OnlineSubsystemAccelByte plugin for Unreal Engine.

Prerequisites

  • Unreal Engine 5.x or 4.27+
  • AccelByte Gaming Services account and namespace
  • Client credentials (Client ID and Client Secret)

Configuration

1. Enable the Plugin

Add the plugin to your .uproject file:

{
"Plugins": [
{
"Name": "OnlineSubsystemAccelByte",
"Enabled": true
}
]
}

2. Configure DefaultEngine.ini

Add the following to your Config/DefaultEngine.ini:

[OnlineSubsystem]
DefaultPlatformService=AccelByte
[OnlineSubsystemAccelByte]
bEnabled=true
[/Script/AccelByteUe4Sdk.AccelByteSettings]
ClientId=YourClientId
ClientSecret=YourClientSecret
Namespace=YourNamespace
PublisherNamespace=YourPublisherNamespace
BaseUrl=https://demo.accelbyte.io

User Authentication

Get the Online Subsystem

#include "OnlineSubsystem.h"
#include "OnlineSubsystemAccelByte.h"
#include "Interfaces/OnlineIdentityInterface.h"
// Get the AccelByte subsystem
IOnlineSubsystem* Subsystem = IOnlineSubsystem::Get(ACCELBYTE_SUBSYSTEM);
if (!Subsystem)
{
UE_LOG(LogTemp, Error, TEXT("Failed to get AccelByte subsystem"));
return;
}
// Get the Identity interface
IOnlineIdentityPtr IdentityInterface = Subsystem->GetIdentityInterface();

Login with Email and Password

// Set up login delegate
FOnLoginCompleteDelegate LoginDelegate;
LoginDelegate.BindLambda([](int32 LocalUserNum, bool bWasSuccessful, const FUniqueNetId& UserId, const FString& Error)
{
if (bWasSuccessful)
{
UE_LOG(LogTemp, Log, TEXT("Login successful! User ID: %s"), *UserId.ToString());
}
else
{
UE_LOG(LogTemp, Error, TEXT("Login failed: %s"), *Error);
}
});
// Add delegate to the interface
IdentityInterface->AddOnLoginCompleteDelegate_Handle(0, LoginDelegate);
// Create credentials
FOnlineAccountCredentials Credentials;
Credentials.Type = "AccelByte";
Credentials.Id = "user@example.com"; // Email or username
Credentials.Token = "password"; // Password
// Perform login
IdentityInterface->Login(0, Credentials);

Login with Device ID

For guest/anonymous login:

FOnlineAccountCredentials Credentials;
Credentials.Type = "AccelByte";
Credentials.Id = ""; // Empty for device login
Credentials.Token = "deviceId";
IdentityInterface->Login(0, Credentials);

Login with Platform Token

For Steam, PlayStation, Xbox, etc.:

FOnlineAccountCredentials Credentials;
Credentials.Type = "AccelByte";
Credentials.Id = "steam"; // Platform type: steam, ps4, ps5, xbl, etc.
Credentials.Token = "platform_access_token";
IdentityInterface->Login(0, Credentials);

Working with Sessions

Create a Game Session

#include "Interfaces/OnlineSessionInterface.h"
// Get Session interface
IOnlineSessionPtr SessionInterface = Subsystem->GetSessionInterface();
// Set up delegate
FOnCreateSessionCompleteDelegate CreateDelegate;
CreateDelegate.BindLambda([](FName SessionName, bool bWasSuccessful)
{
if (bWasSuccessful)
{
UE_LOG(LogTemp, Log, TEXT("Session created successfully"));
}
});
SessionInterface->AddOnCreateSessionCompleteDelegate_Handle(CreateDelegate);
// Configure session settings
FOnlineSessionSettings SessionSettings;
SessionSettings.bIsLANMatch = false;
SessionSettings.bUsesPresence = false;
SessionSettings.bAllowJoinInProgress = true;
SessionSettings.NumPublicConnections = 4;
// Create the session
FName SessionName = NAME_GameSession;
SessionInterface->CreateSession(0, SessionName, SessionSettings);

Find Sessions

// Set up search settings
TSharedRef<FOnlineSessionSearch> SearchSettings = MakeShared<FOnlineSessionSearch>();
SearchSettings->MaxSearchResults = 10;
SearchSettings->bIsLanQuery = false;
// Set up delegate
FOnFindSessionsCompleteDelegate FindDelegate;
FindDelegate.BindLambda([SearchSettings](bool bWasSuccessful)
{
if (bWasSuccessful)
{
for (const FOnlineSessionSearchResult& Result : SearchSettings->SearchResults)
{
UE_LOG(LogTemp, Log, TEXT("Found session: %s"), *Result.GetSessionIdStr());
}
}
});
SessionInterface->AddOnFindSessionsCompleteDelegate_Handle(FindDelegate);
// Start searching
SessionInterface->FindSessions(0, SearchSettings);

Friends Management

Get Friends List

#include "Interfaces/OnlineFriendsInterface.h"
// Get Friends interface
IOnlineFriendsPtr FriendsInterface = Subsystem->GetFriendsInterface();
// Set up delegate
FOnReadFriendsListComplete ReadDelegate;
ReadDelegate.BindLambda([](int32 LocalUserNum, bool bWasSuccessful, const FString& ListName, const FString& ErrorStr)
{
if (bWasSuccessful)
{
UE_LOG(LogTemp, Log, TEXT("Friends list loaded successfully"));
}
});
FriendsInterface->AddOnReadFriendsListCompleteDelegate_Handle(0, ReadDelegate);
// Read friends list
FriendsInterface->ReadFriendsList(0, "default");

Achievements

Query Achievements

#include "Interfaces/OnlineAchievementsInterface.h"
// Get Achievements interface
IOnlineAchievementsPtr AchievementsInterface = Subsystem->GetAchievementsInterface();
// Set up delegate
FOnQueryAchievementsCompleteDelegate QueryDelegate;
QueryDelegate.BindLambda([](const FUniqueNetId& PlayerId, bool bWasSuccessful)
{
if (bWasSuccessful)
{
UE_LOG(LogTemp, Log, TEXT("Achievements queried successfully"));
}
});
AchievementsInterface->AddOnQueryAchievementsCompleteDelegate_Handle(QueryDelegate);
// Query achievements
TSharedPtr<const FUniqueNetId> UserId = IdentityInterface->GetUniquePlayerId(0);
AchievementsInterface->QueryAchievements(*UserId);

Cloud Save

Save User Data

#include "Interfaces/OnlineUserCloudInterface.h"
// Get User Cloud interface
IOnlineUserCloudPtr UserCloudInterface = Subsystem->GetUserCloudInterface();
// Prepare data
TArray<uint8> Data;
FString SaveData = TEXT("{ \"level\": 10, \"gold\": 500 }");
FTCHARToUTF8 Converter(*SaveData);
Data.Append((uint8*)Converter.Get(), Converter.Length());
// Set up delegate
FOnWriteUserFileCompleteDelegate WriteDelegate;
WriteDelegate.BindLambda([](bool bWasSuccessful, const FUniqueNetId& UserId, const FString& FileName)
{
if (bWasSuccessful)
{
UE_LOG(LogTemp, Log, TEXT("Cloud save successful: %s"), *FileName);
}
});
UserCloudInterface->AddOnWriteUserFileCompleteDelegate_Handle(0, WriteDelegate);
// Write file
TSharedPtr<const FUniqueNetId> UserId = IdentityInterface->GetUniquePlayerId(0);
UserCloudInterface->WriteUserFile(*UserId, "SaveGame.json", Data);

Complete Example

Here's a complete example showing initialization and login:

// MyGameInstance.h
#pragma once
#include "CoreMinimal.h"
#include "Engine/GameInstance.h"
#include "Interfaces/OnlineIdentityInterface.h"
#include "MyGameInstance.generated.h"
UCLASS()
class MYGAME_API UMyGameInstance : public UGameInstance
{
GENERATED_BODY()
public:
virtual void Init() override;
private:
void LoginToAccelByte();
void OnLoginComplete(int32 LocalUserNum, bool bWasSuccessful, const FUniqueNetId& UserId, const FString& Error);
FDelegateHandle LoginDelegateHandle;
};
// MyGameInstance.cpp
#include "MyGameInstance.h"
#include "OnlineSubsystem.h"
#include "OnlineSubsystemAccelByte.h"
void UMyGameInstance::Init()
{
Super::Init();
LoginToAccelByte();
}
void UMyGameInstance::LoginToAccelByte()
{
IOnlineSubsystem* Subsystem = IOnlineSubsystem::Get(ACCELBYTE_SUBSYSTEM);
if (!Subsystem)
{
UE_LOG(LogTemp, Error, TEXT("AccelByte subsystem not found"));
return;
}
IOnlineIdentityPtr Identity = Subsystem->GetIdentityInterface();
if (!Identity.IsValid())
{
UE_LOG(LogTemp, Error, TEXT("Identity interface not found"));
return;
}
// Set up login delegate
FOnLoginCompleteDelegate LoginDelegate = FOnLoginCompleteDelegate::CreateUObject(
this, &UMyGameInstance::OnLoginComplete);
LoginDelegateHandle = Identity->AddOnLoginCompleteDelegate_Handle(0, LoginDelegate);
// Create credentials
FOnlineAccountCredentials Credentials;
Credentials.Type = "AccelByte";
Credentials.Id = "user@example.com";
Credentials.Token = "password";
// Login
Identity->Login(0, Credentials);
}
void UMyGameInstance::OnLoginComplete(int32 LocalUserNum, bool bWasSuccessful,
const FUniqueNetId& UserId, const FString& Error)
{
IOnlineSubsystem* Subsystem = IOnlineSubsystem::Get(ACCELBYTE_SUBSYSTEM);
if (Subsystem)
{
IOnlineIdentityPtr Identity = Subsystem->GetIdentityInterface();
Identity->ClearOnLoginCompleteDelegate_Handle(LocalUserNum, LoginDelegateHandle);
}
if (bWasSuccessful)
{
UE_LOG(LogTemp, Log, TEXT("Login successful! User ID: %s"), *UserId.ToString());
// Proceed with game logic
}
else
{
UE_LOG(LogTemp, Error, TEXT("Login failed: %s"), *Error);
// Handle login failure
}
}

Common Patterns

Checking Login Status

IOnlineIdentityPtr Identity = Subsystem->GetIdentityInterface();
if (Identity->GetLoginStatus(0) == ELoginStatus::LoggedIn)
{
// User is logged in
TSharedPtr<const FUniqueNetId> UserId = Identity->GetUniquePlayerId(0);
}

Logout

FOnLogoutCompleteDelegate LogoutDelegate;
LogoutDelegate.BindLambda([](int32 LocalUserNum, bool bWasSuccessful)
{
UE_LOG(LogTemp, Log, TEXT("Logout complete"));
});
Identity->AddOnLogoutCompleteDelegate_Handle(0, LogoutDelegate);
Identity->Logout(0);

Error Handling

Always check for success in delegate callbacks and handle errors appropriately:

void OnOperationComplete(bool bWasSuccessful, const FString& Error)
{
if (!bWasSuccessful)
{
UE_LOG(LogTemp, Error, TEXT("Operation failed: %s"), *Error);
// Show error to user or retry
return;
}
// Proceed with success logic
}

Next Steps

  • Explore the Classes section to see all available interfaces
  • Check specific interface documentation for detailed features
  • Visit the AccelByte Developer Portal for more examples and guides
  • Review the Unreal OSS documentation for standard OSS patterns

Best Practices

  1. Always use delegates - OSS operations are asynchronous
  2. Clear delegate handles - Prevent memory leaks by clearing delegates when done
  3. Check for null - Always validate subsystem and interface pointers
  4. Handle errors - Check bWasSuccessful in all callbacks
  5. Use proper LocalUserNum - Typically 0 for single-player, varies for split-screen