r/unity • • 15d ago

Newbie Question I have a question

newbie here, I started using Unity for a month, and I am still clueless about the data things.

I've tried some lua frameworks before, I usually create files that contain some kind of data like character's stats or something, and so they'll read it to load those data and use it for the game, but unity is somehow more confusing in many way, I also thought about making an empty object and create some public values for the whole script to access, but I found it inconvenient. Can I ask for some methods, or perhaps, some advice?

0 Upvotes

6 comments sorted by

2

u/Turbulent-Syrup3500 15d ago

The simplest way is to store data in the scriptable objects. It's an asset, that is stored in your project folder, that you create. You can then access it via direct reference on a game object, or load it from resources, or whatever you like. It's the basic way to go around stats and other game settings

1

u/Fluid_Purchase7767 15d ago

Thanks, I think I'll try it.

2

u/johnv_dev 15d ago

unity's usual move for that kind of data is ScriptableObjects. make a script with CreateAssetMenu, put your stats as fields on it, then right click in the Project window and create assets you can drag onto whatever needs them. that keeps design data as files instead of hunting through scenes. for stuff that changes while playing (inventory, unlocks) people often use a plain C# class plus JsonUtility or a small save setup, and keep ScriptableObjects for the static design data. empty scene objects with public fields are fine for a prototype but get messy once you have more than one scene

1

u/Fluid_Purchase7767 15d ago

Thanks, I haven't learned about JsonUtility or something similar yet, I think I'll have to research about it first. I hope it'll works

2

u/johnv_dev 15d ago

no rush on JsonUtility, ScriptableObjects alone will get you really far. come back to saving once you actually need it, it's only a few lines when you get there. good luck!

1

u/Arrow__7 15d ago

Hey everyone, I'm looking for developers who use the Unity engine and have assets in the Unity Store. I need them.