Skip to content

This is a save data management plugin for Unity. It allows you to easily save and restore game states at any time. Unity用のセーブデータの保存・復元プラグインです。いつでも簡単に好きな状態へ戻すことができます。

License

Notifications You must be signed in to change notification settings

IShix-g/HistoryTracker

Repository files navigation

Unity

README - 日本語版

Important

This plugin is designed to save/restore existing game data files. It does not include save system functionalities such as data serialization or deserialization.

HistoryTracker

A Unity plugin for saving and restoring game data (persistent data).

HistoryTracker

Features

  • Save game data (persistent data).
  • Restore saved game data.
  • Manage data via a clean, easy-to-read UI.
  • Use data saved in the Editor on actual devices.

Why HistoryTracker?

1. Focused Debugging of RNG Elements

When verifying "items with a 1% drop rate" or "events triggered under specific conditions," restarting the game from the beginning is a waste of time. By saving the state immediately before the check and loading it after the check to retry repeatedly, you can verify the behavior of low-probability events dozens of times in a short period.

2. Comprehensive Testing of Quest Branches & Multi-Endings

This is useful in RPGs or adventure games when you want to test both "Option A" and "Option B." By saving the state just before a branching point, you can check one route and then immediately return to check the other, minimizing backtracking during debugging.

3. As a "Bug Reproduction" Tool for QA

When testers find a bug, reproducing "how that state was reached" is often difficult. Since this plugin works on actual devices, by saving periodically, you can rewind to the moment a bug occurred. This makes it easy to share the exact occurrence context with developers or identify reproduction steps.

4. Accelerating Game Balance Adjustments

Useful for situations like adjusting boss difficulty, where you want to "slightly increase attack power and retry." By preserving the state before the battle starts, adjusting enemy parameters in the Inspector, and repeating the "Restore & Retry" process, you can efficiently find the ideal game balance.

5. Test Initialization

When performing integration tests, you often need specific states like "1000G, Level 10." Instead of setting up from new data every time, restoring an "ideal state" created in advance with this plugin allows you to start testing immediately, significantly reducing execution time and ensuring a clean testing environment.

Getting Started

Install from Git URL

"Unity Editor : Window > Package Manager > Add package from git URL...".

https://github.com/IShix-g/HistoryTracker.git?path=Packages/HistoryTracker#v1

Scripts

Implementation

Implement IHistSaveDataHandler to link your save system with HistoryTracker.

Method Description
OnBeforeSave() Called immediately before saving. Save necessary game data and return the title and description. This content will be displayed in the UI.
GetSaveFilePaths() Returns an array of full paths to game data files. e.g., Application.persistentDataPath + "/data.bytes"
ApplyData() Called after game data has been restored. Reflect the game data by reloading it or by calling Application.Quit() to close the app once.
using HistoryTracker;

public sealed class TestModelRepository : ModelRepository, IHistSaveDataHandler
{
    public HistRecordInfo OnBeforeSave()
    {
        // Save data
        for (var i = 0; i < Models.Count; i++)
        {
            var model = Models[i];
            var path = GetFullPath(model.Id);
            Save(model, path);
        }
        // Return the title and description
        var title = "Saved Count: " + Models[0].SaveCount;
        var description = "[Test]";
        return new HistRecordInfo(title, description);
    }

    // Determine and return the file path
    // e.g. `Application.persistentDataPath` + "/data.bytes" 
    public IReadOnlyList<string> GetSaveFilePaths() => Paths.Values.ToList();

    public void ApplyData() => Restored();
}

HistRecordInfo

The title and description set in OnBeforeSave() above will be displayed in the UI as follows:

var title = "Saved Count: " + Models[0].SaveCount;
var description = "[Test]";
return new HistRecordInfo(title, description);

Setting Dependencies

Set the IHistSaveDataHandler implemented above to HistoryTracker. Configure it in Awake as early as possible after the game starts.

void Awake()
{
    // Initialize the repository that implements IHistSaveDataHandler in Awake
    Hist.Configure(_repository);
}

Opening the History Dialog

The dialog is opened via script. You can release it by calling Hist.Release() when it's no longer needed, but since it's lightweight, this is unlikely to cause any issues.

using HistoryTracker;

void OnDialogButtonClicked()
{
    Hist.OpenDialog();
}

History Dialog Explanation

History List

Displays a list of saved history.

No Description
Save Game Data
Record Count
Saved Game Data Item
Open Details
Previous Page
Next Page
Close

詳細

Details and operations for saved game data.

No Description
Restore Game Data
Delete Game Data
Title (Long press to edit) *
Description (Long press to edit) *
List of saved file paths
Badge displayed if saved in Editor
Close
Date Saved
  • Note: On actual devices, you cannot edit data generated in the Editor.

Plugin Settings

By default, this plugin operates only in the debug environment. You can adjust this in the settings.

Open via Window > HistoryTracker > open Settings

Settings

No Description
Show GitHub Page (External Link)
Open History Dialog (Runtime only)
Plugin Scope (EditorOnly / DevelopmentBuild / All)
Use game data saved in Editor on actual device?

Saving Game Data via Script

While you can save game data using the Save button in the History Dialog, you can also save via code using the snippet below:

Hist.SaveHistory();

Use Cases

Save Game Data on Level Up

If your save system has level-up events, saving game data each time you level up makes it easier to revert if issues occur.

Code Example:

void OnLevelUp(int level)
{
    // You can add a title and description.
    var title = $"Level Up {level}";
    var description = JsonUtility.ToJson(_user, true);
    var info = new HistRecordInfo(title, description);
    Hist.SaveHistory(info);
}

Save Game Data When Errors Occur

To use the pre-prepared code, execute the following. This is a singleton component that monitors for errors and calls Hist.SaveHistory().

Code Example:

void Start()
{
    HistErrorSaver.Create();
}

API Used for Asset Loading

Resources.Load - Used for loading UI assets at runtime on actual devices (e.g., mobile phones). Assets loaded via this API are only included in the final game build if the associated plugin is enabled. If the plugin is disabled, the assets are omitted (stripped) and will not be packaged with the application.

About

This is a save data management plugin for Unity. It allows you to easily save and restore game states at any time. Unity用のセーブデータの保存・復元プラグインです。いつでも簡単に好きな状態へ戻すことができます。

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Contributors 2

  •  
  •  

Languages