- Home /
Good Setup for Predefined Array Data?
Just wondering what the best set up is for arrays that will remain unchanged and be read by code during runtime.
I was considering XML for things like names of objects, dialogue, etc, but is there a preferred alternative as Unity doesn't seem to parse XML out of the box? For example, putting a script on a game object in the first scene which defines the arrays inside void Start?
Monodevelop seems to offer database setup and creation, can these be used with Unity quite easily?
What's your usecase? Arrays are different than databases are different than permanent storage are different than runtime generated lists.
expanding on the X$$anonymous$$L, there might not be an 'Add X$$anonymous$$L' game component in the drop down, but the methods are there.
Answer by DaveA · Sep 02, 2013 at 12:43 AM
It depends on what you want. If you want easy to code, CSV is pretty easy. XML is not hard either and you have several XML classes/libraries available. In both cases, you're reading text from a file (or via WWW) and if you're not worried (or if you in fact depend) on that data changing (like hacked) then that's fine.
If you want to 'bake' it into the game, what I've done in these cases is the same as the above, but make it an Editor script which reads the data into the structures on the desired component(s), and just Save Scene. Then you can see it in the Inspector to make sure it looks right, but you don't have to ship those text files.
Thanks for the replies, the baking concept seems like a good way to embed the data into the final build, but it will constantly change during development so it's "exposure" isn't a big deal for me in the initial stages.
Data would be parts of names and objects and their properties - they would act as a pool of things to be combined at runtime using fixed random number lists, generating hundreds of potential combinations of character and object names.
From some initial tinkering it seems that when Unity starts, it loads the first scene in the build settings dialog, and the code to do the initialization would need to be attached to a game-object in the first scene.
I'm just wondering what the best approach to accessing these elements across multiple scenes. I was kind of hoping to break the games principle screens into separate scenes.
I suppose the code with the data and for dealing with it could be instanced in each scene with no problem?
Thanks again.
Your answer
![](https://koobas.hobune.stream/wayback/20220613113411im_/https://answers.unity.com/themes/thub/images/avi.jpg)