- Home /
Unit Data in a Strategy Game
Hello people,
I'm working on a turn-based strategy game at the moment and I'm looking for the best way to store complex unit data. I'm using a basic unit class and one xml file per unit, and every time I instantiate one, I fill the Unit class with the xml data.
Is there a better alternative to xml files for this purpose (I'm worried the loading of xml files might affect the games performance)? What is your preferred way to manage unit data in a strategy game?
Ins$$anonymous$$d of using a xml file per unit why not use one xml file which contains all the data?
Personaly i haven't used xml before, i use a binary streamer and save my data as a ".dat" file. I don't know how secure you want your data to be but i think the .dat files are easier to crack then the xlm files.What is the size of the xml files? .dat files hold a 128 by 128 int array and 2 other seperat int and have a size of under 10 kB.
yes using only one xml file makes sense, and could improve the loading issue :) Xml files can be as long as I want, $$anonymous$$e have a size of under 1kb. I'm not at a point where I'm worried about security yet, but it will be important later on, when I start developing the multiplayer mode.
Hello Yaza, I also like you are fond of creating a turn-based strategy. How can I contact you? I want to ask you a few questions,Hello, Yaza, I am also interested in creating step-by-step strategies. how can I contact you on social networks???
Answer by Baste · Sep 26, 2015 at 07:32 PM
Scriptable Objects
The ScriptableObject class defines objects that's stored in your Unity project. They have a bunch of advantages over XML:
They're directly importable. You don't have to use XML parsing libraries or write your own parsing code to create a usefull wrapper for your data - you just grab them as an object from the Resources folder, or link them to a prefab that uses them in the game, and you're good to go.
They're stored as text files in the YAML format, which is a lot easier to read than XML files, and behaves much better with source control.
You can write custom inspectors for them just as easily as you write custom inspectors for MonoBehaviours, so it's a lot easier to create powerful tools to work with your data - either by selecting the scriptable object and fiddling with it's values in the inspector, or by creating larger editor windows that lists a lot of them.
Scriptable Objects are provided by Unity to let you work with stored data easily, so I recommend that you use them over xml files.
Thank you, I will look into ScriptableObjects then, sounds interesting :)