Course contentsShow
← Unreal Engine Game Development
Lesson 219 of 8803. C++ and UObject ArchitectureFree lesson

Optimizing Data Persistence with UPROPERTY Specifiers

You will master property specifiers like EditAnywhere and SaveGame to control how engine variables interact with the editor interface and serialization system.

In this lesson, you will learn how to leverage specific UPROPERTY specifiers to control how your C++ variables appear in the editor and how they are automatically handled by Unreal’s serialization system for save games.

Controlling Editor Visibility vs. Persistence

When you create a variable in C++, it is invisible to Unreal’s reflection system by default. By marking it with UPROPERTY(), you register it with the engine. However, not every variable needs to be tweaked by a designer or saved to disk.

The EditAnywhere specifier is your primary tool for Editor Usability. It tells Unreal that this variable should be editable in the Details panel, regardless of whether the object is a placed instance or a blueprint asset. This is vital for data persistence during the design phase—changes made in the editor are saved into the asset files, essentially "persisting" your configuration before the game ever runs.

The SaveGame Specifier

While EditAnywhere manages editor persistence, the SaveGame specifier manages runtime persistence. When you use the SaveGame flag, you are instructing Unreal’s serialization system that this variable is a candidate for storage.

UCLASS()
class AMyPlayerCharacter : public ACharacter
{
    GENERATED_BODY()

public:
    // Designers can change this in the editor, and it's saved with the asset
    UPROPERTY(EditAnywhere, Category = "Player Stats")
    float BaseHealth;

    // This variable is marked for inclusion in SaveGame serialization
    UPROPERTY(SaveGame)
    float CurrentExperience;
};

Why This Matters for Optimization

You might wonder why we don’t just mark everything as SaveGame. Serialization is not free; every variable marked with SaveGame must be processed by the engine’s binary writer/reader during save and load operations. By explicitly tagging only the variables that need to persist, you minimize the size of your save files and reduce the CPU overhead during disk I/O.

By combining these specifiers, you keep your code clean, your designers productive, and your save system performant. Use EditAnywhere to define your object's starting state and SaveGame to track only the critical data that must survive between play sessions.

Key Takeaway: Use EditAnywhere to expose properties for editor-time configuration, and reserve SaveGame exclusively for runtime variables that must be persisted to disk to keep your serialization processes lightweight.