Why does Resources.Load keep returning null?
I'm pulling my hair out here... I've got a .txt file I'm using for loading in strings that my various objects will use to accommodate different languages. I first tried putting the text file in the StreamingAssets folder and accessing it that way, and that worked well until I tested it on Android (the target platform), where it wasn't accessing the file at all. So, I found the Resources.Load() method, and set up my project in that way.
I'm trying to read the file, but my problem is Resources.Load() is always returning null. I'm not including the extension, I'm type casting correctly (I've tried multiple ways of doing that just in case), and I've got my project files set up correctly as you can see here: The file named English is a normal .txt file and Unity can open it, so I don't think there's an import issue.
The code I'm using is here: currentLanguage is an enum and using the ToString method on it returns "English", which is the proper name of the file, without the extension, as the Unity docs specify. The resulting string in Resources.Load()'s path argument would then be "Languages/English", which is how I'm supposed to do it, right? I also tried putting the results of a Resources.LoadAll("") into the debug log and it turned up empty, even though the documentation for that method says that it should return all assets in the Resources folder.
I'm sure my mistake is a silly one, but for the life of me I can't find it and it's driving me crazy. I'm using Unity 5.3.5f1, by the way.
Answer by thatCamelCode · Jul 26, 2016 at 02:33 PM
Alright, I figured it out. When I put the English.txt file in the project, I did it through Windows Explorer instead of dropping the file into the Project view in Unity. Because of that, the text file wasn't properly converted to a TextAsset. It works now that I dropped the file into the project, instead of saving it directly in the project's assets.