Dracon Interactive

Study Blog

  • Home
  • About
  • Media
  • Games
    • The Eternal >
      • Eternal Ember
      • Eternal Shards
    • University >
      • SubTerraneon
      • Hero Rising
  • Tools
    • Sequences
    • Flow
  • Other
    • VR Bow System
    • Project Guardian
    • NLP AI

27/3/2019

Saving Data in Unity - A Short Explanation

0 Comments

Read Now
 
1. JSON.
This is a way of storing data in what is essentially a single string. Unity has some inbuilt tools for using it, or you can get external ones. Its made up of a list of key:value pairs. So, a player might be:

{
"name":"Player1",
"level": 0,
"faction": "elves,
"awesome": true
}

This system is very good for online data storage, because you can just use REST GET/POST methods to transfer it to and from a server. Parse it on your end, you all g. There are a ton of tutorials on this

2. PlayerPrefs
This saves the data to the computers registry under the game name. I think you can do floats, ints and strings (so if you need a bool, just use a 0/1 int). Its fairly fast, but only local, so keep that in mind. Its also pretty persistent. Because a lot of us dont actually use installers, even if you delete all trace of your game from your system, chances are that your save data is still sitting in the registry eating a sandwhich. 

3. Scriptable Objects
Imagine c# scripts you can make assets out of. Define your variables, create an instance, set variables on the instance, then reference like you would a prefab or texture! Again, only local storage, but very handy for inventory control / item databases. Again, so many tutorials available. Check #unitytips (Unity Official Discord) for some :)

4. Make your own save file. 
While C# is not as machine focused as C++, it is still an amazing versatile language with links to all sorts of windows systems. So, of course, you can create/delete/modify files. What is cool about this is that you can do this with a custom filetype. I use a .dracon file to store local authentication and save games. They can usually be opned with a text editor, like notepad++ (or just notepad if you're a heathen). I use Sublime Text because its light AF. There are a few tutorials around this, but make sure to look up C#, not unity, because most of the info is in the microsoft docs etc. 

5. Combinations of the above
Remember these are all individual techniques that can be used in conjunction. Save a json string to playerprefs. Add a network script to a scriptable object to populate it with data retrieved from a custom save file ... that you retrieved off a server ... that has json in it! 

Hope this helps. Feel free to ask questions :)

Share

0 Comments



Leave a Reply.

Details

    Author

    Peter Carey. Game Developer, STEM Education Provider, Dracon Interactive Founder

    Archives

    May 2019
    March 2019
    February 2019
    January 2019
    November 2018
    June 2018
    May 2018
    April 2018
    March 2018

    Categories

    All

    RSS Feed

Copyright Dracon Interactive (2025)
  • Home
  • About
  • Media
  • Games
    • The Eternal >
      • Eternal Ember
      • Eternal Shards
    • University >
      • SubTerraneon
      • Hero Rising
  • Tools
    • Sequences
    • Flow
  • Other
    • VR Bow System
    • Project Guardian
    • NLP AI