Course contentsShow
← Unreal Engine Game Development
Lesson 129 of 8802. The Gameplay FrameworkFree lesson

Securing Persistent Data Against Tampering

You will implement validation checks on saved files to ensure that player progress data remains authentic and free from local modifications.

In this lesson, you will learn how to verify the authenticity of your saved data files to prevent players from manually editing them to cheat their progress.

When you serialize player data to disk, Unreal Engine saves it as a binary file. However, tech-savvy players can locate these files on their hard drives, open them, and modify values—like setting their "Gold" or "Level" to extreme numbers. Because the game simply reads whatever is in that file, it trusts the data blindly. To fix this, we need to implement a "checksum" or a validation stamp.

Implementing a Validation Hash

A simple way to secure your data is to generate a unique "hash" of your data when saving, and compare it against a new hash when loading. Think of a hash as a digital fingerprint: if the data inside the file changes by even one character, the fingerprint changes entirely.

When you save your data, calculate a hash based on the values of your variables and append that hash to the end of your save file.

// Pseudocode concept for a validation check
void UMySaveGame::VerifyData() {
    int32 CurrentChecksum = CalculateHash(PlayerData);
    
    // Compare the stored hash against the recalculated one
    if (StoredChecksum != CurrentChecksum) {
        // Data has been tampered with!
        ResetToDefaults();
    }
}

When the game loads, it performs the same calculation on the loaded variables. If the result matches the StoredChecksum you saved earlier, the data is authentic. If they don't match, you know the file has been tampered with. In this case, instead of loading the corrupted data, your code should trigger a failsafe, such as resetting the player’s progress to a clean state or logging an error.

By adding this layer, you ensure that the game logic—not the player's text editor—dictates the rules of your save system. Even if a player tries to change their gold value, the checksum will fail, and the game will recognize the file as invalid.

Key Takeaway: Always validate the integrity of your loaded data by comparing it against a calculated checksum, ensuring that only game-generated files are accepted.