The drawbacks with JSON are that the save files tend to be larger than binary serialization. And the big advantage to using JSON is that, if we wished, we could transmit this over the web with no problems – it’s such a common Internet data exchange format. It supports composite types – and in fact, this implementation uses Unity’s default serializer behind the scenes, although it only works with public fields so we still can’t use it to save entire GameObjects, complete with Components. It’s easy for computers to parse too, so we don’t lose much in terms of efficiency. This makes it very easy to debug problems during saving or loading, and even allows the designer to hand-author save files. Using JSON, we gain some advantages over PlayerPrefs and even over binary serialization. It also should be noted that the Load function needs some extra logic to read back the contents of the SaveData struct, but I’m sure you can figure that out yourself! They can store a limited amount of data types, which is adequate for small-scale use cases.
In technical terms, PlayerPrefs are a set of key-value pairs, where the keys are strings (such as “health”, “audio volume”, etc) and the values are floating-point numbers, integer numbers or strings. The API was originally designed to store player preferences between game sessions, so it was designed with simple data such as game options in mind. The first approach we’ll look at is a Unity API called PlayerPrefs. This article was available to $5+ Patreon supporters early. This tutorial focuses on saving to a local disk, but in Unity, it turns out there are several ways of doing that, each with different quirks. Expansion cards for consoles and hard drive space were the norm for a long time, and nowadays we have cloud-based saves that can be recovered on any device. But in the end, we devised ways of saving progress onto hardware.
Early “saving” systems used password entry screens to skip to certain sections of the game. Library/Preferences/.plist.In ye olden times, games weren’t saved at all – once a session was over, you started from the beginning next time. The PlayerPrefs data is physically stored in /data/data/pkg-name/shared_prefs/pkg-name.xml.Įn WebGL, los PlayerPrefs se almacena utilizando el IndexedDB API del navegador.
C#/JavaScript, Android Java and Native code can all access the PlayerPrefs data.
On Android data is stored (persisted) on the device.
On Windows Store Apps, Player Prefs can be found in %userprofile%\AppData\Local\Packages\>\LocalState\playerprefs.datĮn Windows Phone 8, Player Prefs se puede encontrar en la carpeta local de la aplicación, Mirar también: Directory.localFolder HKCU\Software\\ key, where company and product names areĮn Linux, PlayerPrefs se puede encontrar en ~/.config/unit圓d// nuevamente utilizando los nombres de la empresa y producto especificados en los Project Settings. On Windows, PlayerPrefs are stored in the registry under plist file is used for both Projects run in the Editor and In a file named ist, where company and product names are the names set up in Project Settings. On macOS PlayerPrefs are stored in ~/Library/Preferences folder,