Data File (xml) where to store? Resources/AssetBundles?

Hi,

Wondering if someone could give me a pointer on storing some game data, this would be an xml file that ships with the game and is read by the scripts at runtime.

My game will have random disasters, for each disaster I want to store its name, description and probability of happening.

I think there will be too many to just include in a static script so for ease of use I wanted to create an XML file that stores it all and I can deserialise at runtime.

I’m having a hard time working out how unity wants me to do this.

  • Text asset, do I just drag and drop the xml file into my unity assets folder? Can it then be referenced from my scrips?
  • Resources, do I have to create a resources folder and drop the XML in there?
  • Or do I have to create an AssetBundle?

It seems like it should be really basic I’m struggling to get my head around it.

It depends on what you need to be able to do with it at runtime. Should a user be able to change the xml file and your game would read the changes? If no, then making a text asset and putting it anywhere in your project will work. Your scripts can then reference it by making a public TextAsset variable and assigning it in the inspector. If you do need to be able to change it at runtime, then you can use Unity’s streaming assets folder (Unity - Manual: Streaming Assets). You’d then need to read the xml file somewhat manually, with the xml parsing library of your choice. You would need to handle the file IO manually as well, using file streams for example.

1 Like

Awesome thank you, I don’t need to make changes to it so I’ll go for the text asset approach.