Reading files in the Resources folder

I have a text file that I’m reading in from the Resources folder to get information to be displayed in my Unity project. The plan was to have the text file with the published package to be able to change the text when we need to and have it update easily.

When I publish the package, there is no text file put in the Resources folder. When I put the text file in there and change something to test it, nothing happens.

Why doesn’t this work? Is there another way you’re supposed to do it?

Thanks.

Is the file in a Resources/ folder?

Are you using Resources.Load() and doing so correctly?

If you are using anything in System.IO.File it will never work. (modulo streaming assets)

Check out some tutorials on Resources.Load for how to dynamically load stuff.

Or else make a public TextAsset MyTextfile; somewhere in a scene / prefab and drag the file in you need.

Yup, that’s what I’m doing. File is in my Asssets/Resources folder when developing.

public string xmlToLoad = ""; // XML text file to load
TextAsset xmlText = Resources.Load<TextAsset>(xmlToLoad); // Load XML text file into a TextAsset
tempString = xmlText.text; // Assign the TextAsset to a string to be processed.

It works when I’m inside Unity developing, and it keeps the information when I build the project, but if I add the XML file to the "[PROJECT}Data\Resources" folder and change something, it doesn’t update the text in the game.

That’s… not how that works. Resources has no support whatsoever for post build content additions.

If you want to add data post build, use Addressables.

That’s crazy, I’ve read that’s the way to do it all over, but it doesn’t work LOL

You may want to re-read those sources then. Resources is the old method of streaming assets that are already built into the game during runtime. None of them will mention it supporting post release content additions and the documentation sure doesn’t. When they say ‘put in a folder name Resources’ they only ever mean a folder within the Assets directory of your Unity project.

Those files you see in the Resources folder of a built game are just manifests pointing to assets within the resources.assets file in the game’s main directory if I remember right.

1 Like