- Home /
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 Lando
Answer by Eric5h5 · Oct 04, 2012 at 05:22 PM
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.
Answer by LineKernel · Sep 13, 2019 at 08:53 PM
i know it s old , but for the next guy i found this : https://www.raywenderlich.com/479-using-streaming-assets-in-unity
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
needs
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("*.*");
Your answer
Follow this Question
Related Questions
File Couldn't be Read 0 Answers
Refresh single asset 1 Answer
AssetDatabase.Refresh Causes Fatal Error: Out of Memory 0 Answers
EditorSceneManager.OpenScene fails after AssetDatabase.Refresh 1 Answer
AssetDatabase.Refresh () 2 Answers