C++ Usage
The Steam plugin provides a native C++ API with full parity to the Blueprint layer. All functionality available in Blueprints can be accessed from C++ with identical behavior and data structures.
The C++ API is modular. Each Steam subsystem is exposed through its own dedicated C++ library.
C++ API Structure
Each Steam feature area is represented by a separate *CPPLibrary header. Libraries are independent and can be included and used in any combination.
This means:
- There is no central entry point for all Steam functionality.
- Each library corresponds to one Steam subsystem.
- Only the required headers need to be included.
- The C++ API mirrors the Blueprint API of the same subsystem.
Available C++ Libraries
The plugin provides the following C++ libraries:
| Header file | Subsystem |
|---|---|
SteamAchievementsCPPLibrary.h |
Achievements |
SteamCloudSavesCPPLibrary.h |
Cloud Saves |
SteamFriendsCPPLibrary.h |
Friends |
SteamLeaderboardsCPPLibrary.h |
Leaderboards |
SteamLobbiesCPPLibrary.h |
Lobbies |
SteamOverlayCPPLibrary.h |
Overlay |
SteamPresenceCPPLibrary.h |
Rich Presence |
SteamScreenshotsCPPLibrary.h |
Screenshots |
SteamStatsCPPLibrary.h |
Stats |
SteamUserCPPLibrary.h |
User |
SteamUtilityCPPLibrary.h |
Utility |
Enable C++ Access
To access the Steam plugin from C++ code, the plugin module must be added to your project’s Build.cs file.
Open your project’s *.Build.cs file and add "PloxToolsSteam" to the public dependency modules list:
PublicDependencyModuleNames.AddRange(
new string[]
{
"Core",
"CoreUObject",
"Engine",
"PloxToolsSteam"
}
);
Once the module is added, you can include the plugin’s header in your C++ classes:
#include "SteamAchievementsCPPLibrary.h"
You can include any *CPPLibrary.h header depending on the Steam subsystem you want to use. To see the full list of available functions, open the corresponding header file in your IDE.
General Usage Pattern
All Steam C++ libraries follow the same usage principles, regardless of the subsystem.
Functions are exposed as static methods on the corresponding *CPPLibrary class. Depending on the operation, a function can be either synchronous or asynchronous.
Synchronous functions perform their work immediately and return a result directly. These are typically simple state checks or fire-and-forget operations.
Asynchronous functions return their results through native Unreal delegates. This applies to operations that require communication with Steam, such as queries, downloads, uploads, or data retrieval.
The overall usage pattern is consistent across all subsystems:
- Include the
*CPPLibraryheader for the required Steam subsystem. - Call the static function provided by that library.
- For asynchronous operations, bind native delegates to receive results.
- Handle success or failure inside delegate callbacks.
This consistency allows the same mental model to be applied when working with Achievements, Friends, Leaderboards, Lobbies, Cloud Saves, and other Steam features.
Examples
Below are minimal examples that demonstrate the two most common usage patterns when working with the Steam C++ API.
Synchronous Functions
Some functions are synchronous and return their result immediately. These functions do not use delegates and can be called directly.
A typical example is checking the current state of an achievement.
#include "SteamAchievementsCPPLibrary.h"
bool UMyClass::IsAchievementUnlocked(const FString& AchievementID)
{
return USteamAchievementsCPPLibrary::IsAchievementUnlocked(AchievementID);
}
#include "SteamFriendsCPPLibrary.h"
void UMyClass::CacheFriendInfo(int32 Index)
{
FSteamFriend Friend = USteamFriendsCPPLibrary::GetFriend(Index);
if (!Friend.UserID.IsValid()) return;
CachedFriendUserID = Friend.UserID;
CachedFriendName = Friend.PersonaName;
CachedFriendIsOnline = Friend.bIsOnline;
}
Asynchronous Functions
Most Steam operations are asynchronous and report their result through native Unreal delegates. These functions do not return a value directly.
A typical example is unlocking an achievement, which reports success or failure through callbacks.
#include "SteamAchievementsCPPLibrary.h"
void UMyClass::UnlockAchievement(const FString& AchievementID)
{
FOnSteamUnlockAchievementSuccessNative OnSuccess;
OnSuccess.BindLambda([]()
{
UE_LOG(LogTemp, Log, TEXT("Achievement unlocked"));
});
FOnSteamUnlockAchievementFailureNative OnFailure;
OnFailure.BindLambda([](const FString& Error)
{
UE_LOG(LogTemp, Error, TEXT("Failed to unlock achievement: %s"), *Error);
});
USteamAchievementsCPPLibrary::UnlockAchievement(AchievementID, OnSuccess, OnFailure);
}
Asynchronous functions can return complex objects or data through success delegates, which can then be cast and processed by the game.
#include "SteamCloudSavesCPPLibrary.h"
#include "MySaveGame.h"
void UMyClass::LoadGameFromCloud(const FString& FileName)
{
FOnSteamCloudLoadGameSuccessNative OnSuccess;
OnSuccess.BindLambda([](USaveGame* LoadedGame)
{
if (!LoadedGame) return;
UMySaveGame* SaveGame = Cast<UMySaveGame>(LoadedGame);
if (!SaveGame) return;
int32 PlayerLevel = SaveGame->PlayerLevel;
int32 Coins = SaveGame->Coins;
UE_LOG(LogTemp, Log, TEXT("Cloud save loaded. Level: %d, Coins: %d"), PlayerLevel, Coins );
});
FOnSteamCloudLoadGameFailureNative OnFailure;
OnFailure.BindLambda([](const FString& Error)
{
UE_LOG(LogTemp, Error, TEXT("Failed to load cloud save: %s"), *Error);
});
USteamCloudSavesCPPLibrary::LoadGameFromCloud(FileName, OnSuccess, OnFailure);
}
Summary
The Steam plugin exposes a modular C++ API with one library per Steam subsystem. All functions follow consistent synchronous or delegate-based asynchronous patterns. The same usage model applies across all subsystems.