Get Your Personalized Game Dev Plan Tailored tips, tools, and next steps - just for you.

persistentDataPath Explained: How to Store Data in Unity

Posted by Gemma Ellison
./
August 24, 2023
The cover for persistentDataPath Explained: How to Store Data in Unity

Hi! I’m Michael. I’m a game developer. I make assets and tools to help you develop better games, faster.

I’m writing this guide to teach you about a powerful tool in Unity. You will use this all the time when saving and loading data in Unity. This tool is the persistentDataPath.

The persistent data path tells you the best place to save player data. I always use this path to save and load data in Unity. You will, too.

This guide will not cover how to save or load data. But it will cover everything you need to know about persistentDataPath.

This is a series on data storage and user preferences in Unity. We recommend reading the series in order.

  1. Persistent Data Path in Unity
  2. Scriptable Objects in Unity
  3. Player Settings in Unity

Key Info

  • Application.persistentDataPath returns a string path.
  • This path is the best place for you to save data.
  • You need to save data to disk to preserve player data between game sessions.
  • The path is different for each platform. Windows, Mac, iOS, Android, and WebGL have different persistent data paths.
  • It doesn’t matter what the persistent data path is. But you need to save and load your data from the same place every time.

Are you a beginner game developer? Do you want to learn the basics of working with Unity? If so, then you’re in the right place.

You may still learn something new if you’re an intermediate or advanced game developer. Off we go.

What is a persistent data path?

It is a folder. This folder is the best place for you to save data in your game. As a game developer, you need to maintain player progress between sessions. You need to record when the player levels up. You need to save if the player completes a level. And you need to make sure that you preserve the player’s graphics settings.

Have you ever lost your saved data? If so, you know precisely why you need to save and load data with care.

Imagine you made a game. So you sent a copy to your friend. Your friend plays for hours. They get pretty good, and they make a lot of progress. Then, they close the game to eat dinner. When they come back, they open the game up again. And their progress is gone.

With persistentDataPath, you can save their work when they exit the game. Ready to pick up for their next gaming session.

How do I access the persistent data path?

To access this path, you only need a few lines of code. Here’s a simple example in C#:

string dataPath = Application.persistentDataPath;

This line of code gets the path where your game can store persistent data. It’s like asking Unity for the best place to store long-term data. This path is different for each platform.

Create a free account, or log in.

Gain access to free articles, game development tools, and game assets.