Kaya Games

Ludum Dare 50

Quick Tip for Storing Data (Unity)

https://ldjam.com/events/ludum-dare/50/corrupted-caverns

There are many things to keep track of in our game: which items do what, crafting recipes, block data, etc. I wanted to share how we used scriptable objects to easily edit and access that data.

We start by writing the script for the scriptable object. This will contain a struct with all the different data that we need to know, in this case for blocks. Make sure to mark everything as public and the struct as serializable. Now we simply make an array or list of the struct. scriptableobject.png

We also need a way of fetching data, which we can easily do with .Find() data get.png

We can create an instance of this scriptable object and put our data into it. blockdata.png

To easily be able to access this data from anywhere in our project, we set them in a game manager script. gamemanager.png

awake.png

gamem.png

Now we can easily access the data anywhere, simply by writing GameManager.Instance.[scriptable object name]! get.png

Check out our game to see this in action: https://ldjam.com/events/ludum-dare/50/corrupted-caverns