Newbie Q: Data Access

I’m learning as fast as I can, I swear! :slight_smile: But I have a general question about level data storage.

For a game that has lots of pre-made level which specific data (in my case, numeric is fine), is there a better way for grabbing this information as needed? Do you throw it in a .txt file as part of the project, or is the another way to store lots of numeric info with a minimum amount of fluff / extra space needed?

Thanks in advance, Unity help has been amazing so far!

There are lots of ways to do this. I like to use text files in GRFON format.

But there are even ways to grab data from Google Sheets if you want, or you could use ScriptableObjects, or probably even embed a SQLite database if that’s your thing. Do whatever makes sense to you!

1 Like

CSV, JSON and XML are also formats worth investigating.

CSV plays really nice with other data programs. JSON sometimes plays really nicely with the built in serialisation system.

1 Like

That sort of ingenuity is right up there with people using Gmail attachments as a form of file storage. According to the documentation though it isn’t intended and doesn’t function at runtime but rather during design time.

http://www.litteratus.net/G2UDocumentation.pdf

Yes, with that one the Sheets data gets baked into your app, which may be exactly what you want.

However if you want access to Sheets at runtime, I seem to recall there is an asset or two for that as well. Handy if your want to be able to tweak unit stats after that game is released, I guess, or compare the build version against the latest version for nag updates, etc.

Great, thank you all! CSV seems easy enough, once I figure out how to design the storage system for variable level sizes etc. JSON seems like a good second choice, not too complex to jump into.

Be sure to check out JsonUtility if you go this route.

2 Likes

Actually, Unity’s built-in JSON support was a letdown; I was looking forward to it, but it turned out to be pretty inflexible. I recommend miniJSON.

1 Like

I agree. I am still hoping for more. But it does work for some lazy stuff.

Oh nice it isn’t just for Unity. I’ll have to keep this one bookmarked for non-Unity projects. :smile:

Please correct me if I’m wrong, but after some general research on JSON, it doesn’t seem like Unity has the ability to search for a specific set of information, only to parse the file as a whole. Am I missing something?

To put it another way, if I have 97 levels or whatever, I’d need 97 files to be handled individually, or create a very extensive array system to hold it all on initial load. Is there another way, or is the individual files the best approach, generally speaking?

I’m not sure what you think is so hard about sticking everything into a list. In particular, what do you mean by “a very extensive array system”?

1 Like

My thinking was since the levels aren’t consistent size and shapes, there’s likely to be over 100 of them, with dialogue information before and/or after… I suppose it could be a series of arrays that carry empty values when not needed.

I was under the impression is was better to leave it all in a file and call it only when needed, but admittedly it should be fairly small text/numerical input, so storing it all probably isn’t too memory-intensive. Just want to plan ahead rather than write myself into a corner.

This totally seems like a place for that maxim “premature optimization is the root of all evil”. Just make a list for now, if you need to optimize it later then optimize it later.

1 Like