How do you store non-GameObject data?

There’s data I want to store outside of any GameObject. For example, I’d like to store inheritable data for character races in a database style structure.

In this way, I can say:

  • All character races have a ‘Strength’ attribute
  • Goblins have a range of strength attribute values (they can override)
  • Goblin warriors have a specific range of strength values (they can override)
  • Joe the Goblin Warrior has an even more specific value (he can override)

I really don’t want to create empty prefabs for generic character template data. It feels clumsy for searching and updating. I also don’t believe prefabs support nested data the way I’m thinking about it.

So, I have all of this working using my own game-save/storage system. However I now have 2 different ‘save’ buttons in the editor:

  1. Unity’s normal ‘save’ to save the scene
  2. My ‘save’ to save data external to the scene (i.e. inheritable attributes)

This feels cumbersome.

So, how do you store data that isn’t part of a GameObject?

Is there a way to trigger my data save when the developer (me) saves the scene?

Sounds like you want ScriptableObject!

Have you considered using Scriptable Objects with a script like the one here. This will let you store data in objects that are saved in the Project. You can edit them just like prefabs and everything is saved automatically. You can also give them custom inspector if you need something fancy to happen.

I would suggest saving your data out to text and reading it in at run-time.

[1] is currently my format of choice.  

[SimpleJSON][2] can be used with Unity.