Urgent.News

What's breaking now, across thousands of outlets.

Culture

Building a Save System for a Unity Visual Novel (PlayerPrefs + JSON)

This system saves settings, multiple save slots, and endings that stay unlocked across playthroughs. Used in Exire - The Fire Will Find You , a horror visual novel I programmed in Unity for Spooktober 2026. Link to Exire on Itch.io Intro In my prior games, I didn't include a save feature because they were too short. Exire, though, has multiple endings and about 3 hours of gameplay, so I needed to…

The system described in the source saves various elements of a Unity visual novel, including player settings, multiple save slots, and unlocked endings. Exire, a horror visual novel programmed in Unity for Spooktober 2026, utilized this save system. The developer initially did not include a save feature in earlier games due to their short length, but Exire had multiple endings and approximately 3 hours of gameplay, necessitating the implementation of a save feature. Players expect the ability to save progress, make choices, and load the game as needed.

The save system was more complicated than initially anticipated, encompassing not only player items, health, and location but also dialogue progress, music, flashlight status, gameplay settings, and the positions of each screen on the screen. To manage this complexity, the saving process was divided into three parts: settings, save slots, and unlocked endings.

Settings are saved using PlayerPrefs, Unity's built-in key/value store, which is suitable for player preferences such as option settings. The Options class contains static properties for MasterVolume, BGMVolume, and SFXVolume, each retrieved and saved using PlayerPrefs. The second argument in GetFloat serves as the default value if the player has never modified the setting.

Save data for a single playthrough is stored in JSON files. A single [Serializable] class, PlayerData, contains all necessary data for one playthrough. The class includes fields for saveDate, isEmpty, fileName, sceneName, unlockedEndings, inventoryEntries, itemVisibility, dialogueSaveData, and effectsSaveData. DialogueSaveData tracks which dialogues have played, choices made, and character phases for each room.

The line index allows the player to resume at the exact point in the conversation. EffectsSaveData stores information about scene effects, such as flashlight status, dust and filter effects, and looping sound effects. Music and sound effects are represented as enums, which are not assets and cannot be stored directly in JSON files. Instead, SfxDatabase and MusicDatabase map enums to their respective assets.

The PlayerDataManager script is responsible for handling the save process. It is a singleton prefab placed in the main menu scene, using the usual singleton pattern to ensure there is only one instance. The script collects state from various managers, converts it to JSON using JsonUtility.ToJson, and saves it to a file named playerData_fileX.json, where X represents the save slot. Three separate JSON files are used for settings, unlocked endings, and to store data across playthroughs.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Culture

More from Sunday 18 October →