Unity saving data12/25/2023 ![]() ![]() It’s important to mention that JsonUtility isn’t a fully featured JSON implementation. To make this easier, I wrote a basic file manager, which is available in this example repository. Handling the data storage yourself makes it easy to manage multiple save files because you can store each file in a different location. However, unlike PlayerPrefs, you must save the JSON data yourself, either in a file or over a network. Similar to PlayerPrefs, it’s also relatively easy to implement. JsonUtility is Unity’s built-in API for serializing and deserializing JSON data. Because of this, JSON is excellent for sending and receiving data from a server backend. JSON was developed as a communication protocol for web browsers, making it inherently good for sending data over a network. As a result, all platforms support it strongly, which is helpful when building cross-platform games. JSON is standardized and widely used in many different applications. Every use case is different, and it's these kinds of tradeoffs that lead developers to create many other data formats. So, if you have lots of data, you may want to consider options that aren't text-based. That is, it's slower to read and uses more memory than binary alternatives. In addition to these concerns, since JSON is a text-based format, it's more expensive for machines to parse. The ability to read and change data is useful if you support modding but detrimental if you want to prevent cheating. ![]() It’s much easier to debug your saved data or create new save data for testing purposes when you can read and understand it, but, on the other hand, it’s easy for players to read and modify the data as well. That is, it’s easily understood by people and machines alike – which has both advantages and disadvantages. A determined user can overcome this limitation by converting their saved data into some format represented by one of these basic types, but I don’t recommend it since there are better tools to store your data. PlayerPrefs are relatively easy to implement and require only a few lines of code, but they only support Float, Int and String-type values, making it challenging to serialize large, complex objects. Because of their ease of access, they aren’t safe from users who wish to open and modify them, and they can be deleted by accident since they’re saved outside of the project and managed by your OS. The stored data is in simple key-value pairs. ![]() The exact location varies depending on your operating system, but it’s usually somewhere that’s globally accessible and managed by your OS. PlayerPrefs are stored somewhere on your device, separate from your project. You can use PlayerPrefs to store a player’s preferences between sessions, such as quality settings, audio volume or other non-essential data. However, they’re useful, so we’ll discuss them. PlayerPrefs are not made to save game states. ![]()
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |