AssetDatabase.Refresh at runtime? or something similar

Hello peeps,

So I’m downloading and saving some .obj’s and text files to my Resources folder at runtime which works fine as i do a check afterwords to see if the file exists and it does! then i ask unity to do a simple load on the object, the .obj loads but i get an error when trying to load the text file using the following code…

TextAsset dataTxt = Resources.Load(fileToLoad) as TextAsset;
reader = new StringReader(dataTxt.text);

the error is dataTxt is null BUT if i stop the programme and click play again it works fine and loads the assets from Resources and I’m guessing its because Unity has had a chance to import the assets after i stopped the programme running!!! SOOOooooooo… Im guessing i have to do something like refreshing the resources folder, Any suggestions???

Thanking You

There is no actual Resources folder at runtime (depending on the platform, there’s a folder called “resources”, but it’s not the Resources as in Resources.Load). All resources are bundled into a file when a build is made, therefore Resources.Load cannot work on external files. The only reason it would work partially in the editor is because there is actually a folder called Resources in that case, but you can’t make any use of that in a build.

i know it s old , but for the next guy
i found this :

Basically you have to create a folder named exactly “StreamingAssets” and grab your files from it.
You’ll always be able to access it it seems even once build


using System.IO;

the code to access it is

DirectoryInfo directoryInfo = new DirectoryInfo(Application.streamingAssetsPath);
print("Streaming Assets Path: " + Application.streamingAssetsPath);
FileInfo[] allFiles = directoryInfo.GetFiles("*.*");