
Unreal Engine Data Systems: API, Asset Manager, and GAS
Unreal Engine Data Systems
Modern game development requires robust data handling, from local persistence to remote API integration.
Save and Load Game C++
Unreal’s USaveGame is the backbone of persistence. The common pattern is:
- Try
LoadGameFromSlot. - If it doesn’t exist, create it with
CreateSaveGameObject. - Update values in memory as the user plays.
- Persist the final state with
SaveGameToSlot(often from an Apply button or a checkpoint).
YourSaveGameClass.h
#pragma once
#include "CoreMinimal.h"
#include "SettingsDataStruct.h"
#include "GameFramework/SaveGame.h"
#include "YourSaveGame.generated.h"
UCLASS()
class YOURGAME_API UYourSaveGame : public USaveGame
{
GENERATED_BODY()
public:
UPROPERTY(VisibleAnywhere, Category = "Save Game Data")
FSettingsDataStruct SettingsData;
};Load + Create (if missing)
const FString SlotName = TEXT("YourGameSlot");
UYourSaveGame* SaveGameData = Cast<UYourSaveGame>(UGameplayStatics::LoadGameFromSlot(SlotName, 0));
if (!SaveGameData)
{
SaveGameData = Cast<UYourSaveGame>(UGameplayStatics::CreateSaveGameObject(UYourSaveGame::StaticClass()));
}Save
if (SaveGameData)
{
SaveGameData->SettingsData.VsyncQuality = TEXT("on");
UGameplayStatics::SaveGameToSlot(SaveGameData, SlotName, 0);
}Tip: If you’re saving large data (inventories, world state), consider async save/load to avoid hitches.
Using DataTable C++
DataTables are the fastest way to move “tweakable values” out of code. A common workflow is to store default game settings (graphics/audio) in a CSV, then import it as a DataTable.
Example CSV
| Name | SceenResolution | ViewDistance | AntiAliasing | ShadowQuality | TextureQuality | VsyncQuality | MasterVolume | MusicVolume |
|---|---|---|---|---|---|---|---|---|
| ConfigData | 2560x1440 | Far | Epic | Ultra | Ultra | on | 1.0f | 1.0f |
| 1920x1080 | Medium | High | High | High | off | |||
| 1280x720 | Near | Medium | Medium | Medium | ||||
| 720x480 | Low | Low | Low |
Note: The first column must be named Name.
SettingsDataStruct.h
#pragma once
#include "Engine/DataTable.h"
#include "SettingsDataStruct.generated.h"
USTRUCT(BlueprintType)
struct FSettingsDataStruct : public FTableRowBase
{
GENERATED_USTRUCT_BODY()
public:
FSettingsDataStruct()
: ScreenResolution(TEXT("1920x1080"))
, ViewDistance(TEXT("Far"))
, AntiAliasing(TEXT("Epic"))
, ShadowQuality(TEXT("Ultra"))
, TextureQuality(TEXT("Ultra"))
, VsyncQuality(TEXT("on"))
, MasterVolume(1.0f)
, MusicVolume(1.0f)
{}
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Settings Data")
FString ScreenResolution;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Settings Data")
FString ViewDistance;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Settings Data")
FString AntiAliasing;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Settings Data")
FString ShadowQuality;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Settings Data")
FString TextureQuality;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Settings Data")
FString VsyncQuality;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Settings Data")
float MasterVolume;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Settings Data")
float MusicVolume;
};Import
- In Content Browser: right-click -> Import -> choose your CSV.
- When asked for the row struct: select
FSettingsDataStruct. - The resulting DataTable can be read in C++ or Blueprints.
API/Json Usage
Connecting your game to a web service allows for online leaderboards, remote profiles, or dynamic content.
First, add the required modules to your *.Build.cs:
PrivateDependencyModuleNames.AddRange(new string[] { "Http", "Json", "JsonUtilities" });HttpTest.h
#include "Http.h"
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "HttpTest.generated.h"
USTRUCT()
struct FPlayerData
{
GENERATED_BODY()
UPROPERTY()
FString title = "foo";
UPROPERTY()
FString body = "bar";
UPROPERTY()
int16 userId = 1;
};
UCLASS()
class API_API AHttpTest : public AActor
{
GENERATED_BODY()
private:
FHttpModule* Http;
void PostArea();
void OnProccessRequestComplete(FHttpRequestPtr Request, FHttpResponsePtr Response, bool Success);
public:
virtual void BeginPlay() override;
};HttpTest.cpp
void AHttpTest::BeginPlay()
{
Super::BeginPlay();
Http = &FHttpModule::Get();
PostArea();
}
void AHttpTest::PostArea()
{
// Create Request
TSharedRef<IHttpRequest, ESPMode::ThreadSafe> Request = Http->CreateRequest();
// Bind to callback
Request->OnProcessRequestComplete().BindUObject(this, &AHttpTest::OnProccessRequestComplete);
// --- GET Request ---
// Request->SetURL("https://jsonplaceholder.typicode.com/posts");
// Request->SetVerb("GET");
// --- POST Request ---
Request->SetURL("https://jsonplaceholder.typicode.com/posts");
Request->SetVerb("POST");
Request->SetHeader("Content-Type", TEXT("application/json"));
// Serialize Struct to JSON String
FString JsonString;
FPlayerData PlayerData;
FJsonObjectConverter::UStructToJsonObjectString(PlayerData, JsonString);
Request->SetContentAsString(JsonString);
Request->ProcessRequest();
}
void AHttpTest::OnProccessRequestComplete(FHttpRequestPtr Request, FHttpResponsePtr Response, bool Success)
{
if (Success)
{
UE_LOG(LogTemp, Warning, TEXT("%s"), *Response->GetContentAsString());
}
else
{
UE_LOG(LogTemp, Warning, TEXT("Request Failed!!!"));
}
}Asset Manager
The Asset Manager is a powerful system for discovering and loading assets like items, characters, or maps without blocking the game thread.
- Define Primary Asset Types: Use
FPrimaryAssetTypeto categorize your items. - Configuration: Update
DefaultEngine.inito set theAssetManagerClassName. - Loading: Use
StreamableManagerto load assets in the background.
// Retrieving items via Asset Manager
TArray<FPrimaryAssetId> IdList;
AssetManager.GetPrimaryAssetIdList(ItemType, IdList);
AssetManager.LoadPrimaryAssets(IdList, ...);Gameplay Ability Plugin
The Gameplay Ability System (GAS) is a robust framework for building combat mechanics and RPG systems.
- Attributes: Health, Mana, Stamina.
- Abilities: “Jump,” “FireBall,” “Dodge.”
- Gameplay Effects: Damage over time, Buffs, Debuffs.
For complex projects, GAS manages the replication and execution of these features automatically, ensuring consistency between server and client.