How do I access an xml file that exists in the Project resources panel?

While I know you can use Resources.Load to pull in files from the Resources folder, that only applies to Unity.GameObject type objects such as Texture2D or Material and not an XML file.

What am I missing here? How can I package xml files into my project and then access them via scripts?

You can put the code for review?

XML is text, so use TextAsset.

–Eric

Well there isn’t any code to post because I don’t know what the code is. But here’s an image of what I’d like to load and where it lives:

731788--26615--$screenshot.jpg

sampleDungeon is a .tmx file (an XML exported from Tiled). How do I access this using C# ?

the only thing you need is this one line of C# code to get the asset :slight_smile:

var textAsset = Resources.Load("sampleDungeon") as TextAsset;

and then you use textAsset.text for the xml side of things.

Thanks, that did the trick. Funny, I had to rename the file as sampleDungeon.xml even though tmx is just a text file. Anyway, it’s all good now!

The docs tell you what the supported extensions are.

–Eric

1 Like