All projects
Project 04 · Unity · C#

Scapegoat

Role: Save & Progression Systems

Scapegoat is a fast hack-and-slash game built around a blood-powered sword that lets you trade health for stronger attacks. I built its progression and persistence: the skill tree, including the editor tool the designers used to author it, and the save system.

Scapegoat key art: a chained sword with a living eye, standing among ruined pillars under a red sky

Project Overview

Project Type
Hack-and-slash action
Role
Save & Progression Systems
Team Size
14 people
Duration
4 weeks
Engine
Unity
Language
C#

Skill Tree

Goal. Progression the designers can author and rebalance without code changes, with every stat bonus resolved in one place.

Data

Each skill is a SkillNode ScriptableObject: name, description, icon, the stat it improves and by how much per level, a cost per level, a GUID, and its position in the editor. The length of the cost array is the number of levels, so adding a level means adding a price.

Nodes can also carry prerequisites and a trade-off (a penalty paired with the bonus). Both can be authored in the editor, but the final game didn’t use them, so they aren’t enforced at runtime.

Editor tool

Designers build the tree in a custom editor window, under Tools ▸ Skill Tree Editor:

  • Add Skill Node creates the asset and its GUID in one click.
  • Drag nodes to lay out the tree. Right-drag from one node to another to make it a prerequisite; connections are drawn as arrows, and clicking a connection’s handle removes it.
  • Selecting a node edits it in place, and renaming a skill renames its asset file too.
  • The prerequisite-points slider only allows reachable values. Its minimum and maximum come from walking the prerequisite graph, with cycle detection.
  • Deleting a node asks first, then removes it from every other node’s prerequisites.
Custom Unity editor window showing connected skill nodes
The skill tree editor window, with placeholder skills rather than the game’s own.

Buying upgrades

In the hub, a pentagram opens the upgrade menu. Each SkillButton reads its node and shows the next level’s cost (or “Max Level”) and the current level. A button can only be pressed when the player can afford it and it isn’t maxed. Buying deducts blood currency through an event, raises the level, recalculates the player’s stats and refreshes every button, since a purchase changes what the player can afford everywhere.

Wide view of the Scapegoat hub world with portals and a pentagram
The hub. Portals lead to the arenas; the pentagram opens the upgrade menu.
The upgrade menu in the final build
The upgrade menu in the final build, with the skills the designers had time to add.

Applying stats

ApplyUpgrades() is the only place upgrades turn into stats. It sums every unlocked node’s bonus per stat type in one pass, then writes each total to the player. The bonuses are added, so the order of the nodes doesn’t matter. A new stat is one enum value and one switch case; a new skill is just a new asset.

public void ApplyUpgrades()
{
    Dictionary<SkillTypes, float> upgrades = new Dictionary<SkillTypes, float>();
    foreach (SkillNode node in _skillNodes)
    {
        if (node.currentLevel > 0)
        {
            upgrades[node.skillTypePositive] =
                upgrades.GetValueOrDefault(node.skillTypePositive, 0f)
                + node.percentageIncrease * node.currentLevel;
        }
    }

    foreach (SkillTypes type in upgrades.Keys)
    {
        switch (type)
        {
            case SkillTypes.AttackDamage:
                _attackModifier = _baseAttackModifier + upgrades[type];
                break;
            case SkillTypes.MaximumHealth:
                _maxHealth = _baseMaxHealth * (1 + upgrades[type]);
                _currentHealth = _maxHealth;
                break;
            case SkillTypes.BloodlettingRegenerationRate:
                _bloodlettingRegenerationRate =
                    _baseBloodlettingRegenerationRate + upgrades[type];
                break;
            case SkillTypes.HealthCostOfUsingTheSword:
                _healthCostOfUsingTheSword =
                    _baseHealthCostOfUsingTheSword - upgrades[type];
                break;
            case SkillTypes.BloodlettingGainPerAttack:
                _bloodlettingGainPerAttack =
                    _baseBloodlettingGainPerAttack + upgrades[type];
                break;
        }
    }
}
From m_PlayerStats.cs, with the disabled trade-off line removed.
Scapegoat combat: the player surrounded by enemies
Combat in an arena.

Save System

Goal. Persistence that any feature can join without touching the save code, with save files you can read while debugging.

Design

Anything that needs saving implements one interface:

public interface ISave
{
    void LoadData(GameData data);

    void SaveData(ref GameData data);
}
SaveManager
A singleton that finds every ISave component in the scene at startup, inactive ones included. It’s the single entry point for New Game, Save and Load.
FileDataHandler
Writes GameData as JSON to persistentDataPath/<profile>/saveData.json, creating folders as needed. An optional XOR pass obfuscates the file; with it off, saves are plain JSON you can read and edit while debugging.
GameData
A flat container: the blood currency, plus serializable dictionaries keyed by ID for skill levels and unlocked portals.

Flow

public void SaveGame()
{
    foreach (ISave saveComponent in _saveComponents)
    {
        saveComponent.SaveData(ref _gameData);
    }

    _fileDataHandler.Save(_gameData, selectedProfileID);
}

public void LoadGame()
{
    _gameData = _fileDataHandler.Load(selectedProfileID);
    // if no saved game data, create new game data
    if (_gameData == null)
    {
        NewGame();
        return;
    }

    // Load data into save components
    foreach (ISave saveComponent in _saveComponents)
    {
        saveComponent.LoadData(_gameData);
    }
}
From SaveManager.cs, with debug logging removed.

If there’s no save yet, NewGame() creates fresh data, saves it once and loads it back, so every component starts from the same defaults.

Scapegoat start menu with an option to continue from a save
With a save on disk, the start menu offers to continue where you left off.

Skill levels in the save

Skill levels are stored by each node’s GUID, not its name or file, so designers can rename and reorganise skills without breaking existing saves. After loading, ApplyUpgrades() rebuilds the stats from the restored levels.

public void LoadData(GameData data)
{
    LoadAllSkillNodes();
    _skillNodes.ForEach(node => node.currentLevel = 0);
    foreach (SkillNode node in _skillNodes)
    {
        if (data.skillTree.TryGetValue(node.SkillID, out int level))
        {
            node.currentLevel = level;
        }
    }
    ApplyUpgrades();
}

public void SaveData(ref GameData data)
{
    bool newGame = (data.skillTree == null || data.skillTree.Count == 0);
    data.skillTree = new SerializableDictionary<string, int>();
    if (_skillNodes.Count == 0)
        LoadAllSkillNodes();
    foreach (SkillNode node in _skillNodes)
    {
        data.skillTree.Add(node.SkillID, newGame ? 0 : node.currentLevel);
    }
}
Condensed from m_PlayerStats.cs: the new-game and normal branches of SaveData are merged into one loop.

In production

The interface held up when someone else used it. Another programmer added portal unlocks by implementing ISave and adding one dictionary to GameData. Neither the SaveManager nor the file layer had to change.

Results

  • The designers authored the skills themselves in the editor window, without code changes.
  • Every stat bonus resolves in one function, so balancing questions have one place to look.
  • Saves survive renamed or moved skill assets, because levels are keyed by GUID.
  • Persistence was extended by another programmer without any changes to my code.

What I’d Change

  • Keep runtime state off the ScriptableObjects. Skill levels live on the SkillNode assets. Loading resets them, so builds behave, but in the editor, upgrades bought in Play mode stick to the asset. I’d keep levels in a dictionary keyed by GUID and treat the nodes as read-only definitions.
  • Reset stats to base inside ApplyUpgrades(). It only writes stats that have upgrades, so it relies on Start() having reset the rest first.
  • Let components register themselves. The SaveManager finds ISave components once, at startup. Registering in OnEnable and unregistering in OnDisable would also cover objects from scenes loaded later.
  • Save atomically. Writing to a temporary file and then swapping it in means a crash mid-save can’t corrupt the only save file.
Scapegoat: a blood-soaked sword swing cutting through a crowd of hooded enemies