VOOZH about

URL: https://www.geeksforgeeks.org/c-sharp/saving-and-loading-game-data-in-unity/

⇱ Saving and Loading Game Data In Unity - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Saving and Loading Game Data In Unity

Last Updated : 4 May, 2026

Saving and loading game data in Unity allows developers to store player progress, scores, and game states so they can be restored later. This ensures a seamless gameplay experience by preserving important data between sessions. Game data includes everything that defines the player's current progress:

  • Player position, health, score.
  • Inventory items and ammo.
  • Level number and quest progress.
  • Enemy states and collectibles collected.

Creating a Save Data Class

First, create one class that holds everything you want to save.

All variables you add here will be saved. Add [System.Serializable] above the class.

Complete Save Manager Script

This script handles saving and loading everything.

Delete Save File (New Game)

Add a reset option to clear saved data.

Complete Save System Flow

Save Flow:

  1. Player reaches checkpoint OR presses save button.
  2. Collect all game data into saveData object.
  3. Convert to JSON string.
  4. Save JSON string with PlayerPrefs.
  5. Show "Game Saved" message.

Load Flow:

  1. Game starts OR player presses load button.
  2. Check if save exists.
  3. Get JSON string from PlayerPrefs.
  4. Convert back to saveData object.
  5. Apply values to player, inventory, etc.
  6. Show "Game Loaded" message.
Comment
Article Tags:
Article Tags:

Explore