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"
IOnlineSubsystem* Subsystem = IOnlineSubsystem::Get(ACCELBYTE_SUBSYSTEM);
if (!Subsystem)
{
UE_LOG(LogTemp, Error, TEXT("Failed to get AccelByte subsystem"));
return;
}
IOnlineIdentityPtr IdentityInterface = Subsystem->GetIdentityInterface();
Login with Email and Password
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);
}
});
IdentityInterface->AddOnLoginCompleteDelegate_Handle(0, LoginDelegate);
FOnlineAccountCredentials Credentials;
Credentials.Type = "AccelByte";
Credentials.Id = "user@example.com";
Credentials.Token = "password";
IdentityInterface->Login(0, Credentials);
Login with Device ID
For guest/anonymous login:
FOnlineAccountCredentials Credentials;
Credentials.Type = "AccelByte";
Credentials.Id = "";
Credentials.Token = "deviceId";
IdentityInterface->Login(0, Credentials);
Login with Platform Token
For Steam, PlayStation, Xbox, etc.:
FOnlineAccountCredentials Credentials;
Credentials.Type = "AccelByte";
Credentials.Id = "steam";
Credentials.Token = "platform_access_token";
IdentityInterface->Login(0, Credentials);
Working with Sessions
Create a Game Session
#include "Interfaces/OnlineSessionInterface.h"
IOnlineSessionPtr SessionInterface = Subsystem->GetSessionInterface();
FOnCreateSessionCompleteDelegate CreateDelegate;
CreateDelegate.BindLambda([](FName SessionName, bool bWasSuccessful)
{
if (bWasSuccessful)
{
UE_LOG(LogTemp, Log, TEXT("Session created successfully"));
}
});
SessionInterface->AddOnCreateSessionCompleteDelegate_Handle(CreateDelegate);
FOnlineSessionSettings SessionSettings;
SessionSettings.bIsLANMatch = false;
SessionSettings.bUsesPresence = false;
SessionSettings.bAllowJoinInProgress = true;
SessionSettings.NumPublicConnections = 4;
FName SessionName = NAME_GameSession;
SessionInterface->CreateSession(0, SessionName, SessionSettings);
Find Sessions
TSharedRef<FOnlineSessionSearch> SearchSettings = MakeShared<FOnlineSessionSearch>();
SearchSettings->MaxSearchResults = 10;
SearchSettings->bIsLanQuery = false;
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);
SessionInterface->FindSessions(0, SearchSettings);
Friends Management
Get Friends List
#include "Interfaces/OnlineFriendsInterface.h"
IOnlineFriendsPtr FriendsInterface = Subsystem->GetFriendsInterface();
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);
FriendsInterface->ReadFriendsList(0, "default");
Achievements
Query Achievements
#include "Interfaces/OnlineAchievementsInterface.h"
IOnlineAchievementsPtr AchievementsInterface = Subsystem->GetAchievementsInterface();
FOnQueryAchievementsCompleteDelegate QueryDelegate;
QueryDelegate.BindLambda([](const FUniqueNetId& PlayerId, bool bWasSuccessful)
{
if (bWasSuccessful)
{
UE_LOG(LogTemp, Log, TEXT("Achievements queried successfully"));
}
});
AchievementsInterface->AddOnQueryAchievementsCompleteDelegate_Handle(QueryDelegate);
TSharedPtr<const FUniqueNetId> UserId = IdentityInterface->GetUniquePlayerId(0);
AchievementsInterface->QueryAchievements(*UserId);
Cloud Save
Save User Data
#include "Interfaces/OnlineUserCloudInterface.h"
IOnlineUserCloudPtr UserCloudInterface = Subsystem->GetUserCloudInterface();
TArray<uint8> Data;
FString SaveData = TEXT("{ \"level\": 10, \"gold\": 500 }");
FTCHARToUTF8 Converter(*SaveData);
Data.Append((uint8*)Converter.Get(), Converter.Length());
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);
TSharedPtr<const FUniqueNetId> UserId = IdentityInterface->GetUniquePlayerId(0);
UserCloudInterface->WriteUserFile(*UserId, "SaveGame.json", Data);
Complete Example
Here's a complete example showing initialization and login:
#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;
};
#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;
}
FOnLoginCompleteDelegate LoginDelegate = FOnLoginCompleteDelegate::CreateUObject(
this, &UMyGameInstance::OnLoginComplete);
LoginDelegateHandle = Identity->AddOnLoginCompleteDelegate_Handle(0, LoginDelegate);
FOnlineAccountCredentials Credentials;
Credentials.Type = "AccelByte";
Credentials.Id = "user@example.com";
Credentials.Token = "password";
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());
}
else
{
UE_LOG(LogTemp, Error, TEXT("Login failed: %s"), *Error);
}
}
Common Patterns
Checking Login Status
IOnlineIdentityPtr Identity = Subsystem->GetIdentityInterface();
if (Identity->GetLoginStatus(0) == ELoginStatus::LoggedIn)
{
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);
return;
}
}
Next Steps
Best Practices
- Always use delegates - OSS operations are asynchronous
- Clear delegate handles - Prevent memory leaks by clearing delegates when done
- Check for null - Always validate subsystem and interface pointers
- Handle errors - Check bWasSuccessful in all callbacks
- Use proper LocalUserNum - Typically 0 for single-player, varies for split-screen