

This can be perceived as a very crude way of storing and accessing the data across your scenes. It is entirely possible to write a public static class and access all it’s primitive components and member functions from any script in your scenes. This one should be pretty obvious, but I noticed that some developers are not aware of it. I’ll try my best to structure this article to act as a reference point whenever you find yourself stuck with your project. In this section I will focus on the main commonly used solutions for data persistence in Unity games. Let me describe all the possible solutions that are commonly known to the best of my knowledge. Each of them comes with pros and cons and it depends on what kind of data you want to preserve. There are multiple ways of dealing with this problem. Similarly, the same principle applies whenever you start / stop the game. The way Unity deals with any kind of Object, especially Component or GameObject type instances, is that it destroys them every time you transit from one scene to another. However, that is not the case and you will still be faced with losing the data. One may think that this can be easily solved by marking any of these objects as static. All scripts and components that are attached to GameObject inside a Unity project are destroyed each time you load a scene. In order to tackle the problem, let’s first define it. The ScriptableObject data persistent object.The PlayerPrefs data persistence concept.In this tutorial I’ll describe the most important ones. All of them have pros and cons and it is entirely up to developer to decide which one is the best for the project. Luckily, both C# and Unity provide few solutions to this problem. That goes without saying that even the smallest game may require persistent data, which you can always access from various scripts inside your system’s architecture. Save states, game configuration settings or characters statistics – these are just the examples of data you would ideally want to somehow store on a game’s platform for later use. It may occur at the stage in your development when you have to maintain information between loading different scenes or even different game sessions.

While you work on your project in Unity, sooner or later you will come across a problem of data persistence.
