You kidding? Erry day posts here can be solved by reading the docs or searching the forums and answers, and I make helpful posts when I can
The following works fine for me:
TextAsset text = (TextAsset) Resources.Load( “someTextFile”, typeof( TextAsset ) );
Note that you dont need to specify the assets path, because it’s ‘relative to any Resources folder inside the Assets folder of your project’, in this case my file is at
“Assets/Resources/someTextFile.txt”
They can also be discussed on the forum. Sounds like if it’s working for you then maybe something else in the project or environment is affecting it. Try running the script in a new project to rule it out.
I just spent the past 30 minutes battling the forces of Resources.Load and left-over carriage-return characters, so I can partially relate to your troubles. (In my case, the issue was due to the fact that splitting a file along new-line characters didn’t remove carriage-return characters present on each line, resulting in blood and violence)
Looking over your initial post, I can only really recommend trying again to place the text file in the Resources/ folder: Assets/Resources/Text.txt
(note that “Resources” must be at the root of “Assets”) and calling it: TextAsset asset = Resources.Load (“Text”);
(note that in the path, you should include neither the Resources/ part, nor the file extension)
On a side-note, if you were to place the Text.txt file into subdirectory Sub/ inside Resources/, i.e. Assets/Resources/Sub/Text.txt
then you would load it with: TextAsset asset = Resources.Load (“Sub/Text”);
Another common mistake: forgetting to remove the file extension from the file name in c#:
TextAsset gameInfoAsset = Resources.Load(“GameInfo.txt”) as TextAsset; //WRONG
TextAsset gameInfoAsset = Resources.Load(“GameInfo”) as TextAsset; //CORRECT
Tried each and every scenario. As @LootlabGames and @avirtualfox mentioned, I could not resolve this problem. Are there any specific settings i need to do for the script to load my xlsx file from Resources folder under Assets?
I just struggled through this for an hour, the main problem was in the end my path variable had two slashes in them that I could not see (text too small I guess). I need a fairly deep directory structure to keep track of things, and that is a downside.
However a few things that might help:
Make sure the text file’s “meta” files has type “TextScriptImporter:” (look inside). Otherwise it won’t be a TextAsset.
I had to edit this to set it, I think DOS line endings “\r\n” might throw it off, and I changed them and it seemed to help, but in the end it read a csv with \r\n endings ok. So maybe not…
I changed the DOS line endings with Notepad2 (find and replace \r\n with \n and option interpret backslash set).
My file had the “.csv” extension, but I had to do “Resources.Load(resFullName);”` without the extension.
Sometimes the resources don’t get compiled and you have stale content. I noticed that sometimes an older file gets read in (when it actually works).
I am not sure how to force the resources to be compiled. I would like to know.
@LootlabGames I know this is coming up on 7 years old, but there’s multiple suggestions and according to your details your specific issue should be solved by @XSpitFire 's answer.
Your asset path doesn’t contain a “Resources” folder. Create this folder, place your assets in there, and try again.
Also make sure that you are not using UnityEngine.TextCore.Text.TextAsset !
When I was using it, Resources.Load(some file) would always return Null. As soon as I removed the using TextAsset = UnityEngine.TextCore.Text.TextAsset; from the top of my script, it worked.
As an aside, depending on the file’s extension, you may have to make sure that the asset is being imported as a text file (or just change the file’s actual extension to txt.)
I’m using JetBrains Rider as an IDE and it used my “Resources” directory as a namespace. Totally screwed up my reference to the real “Resource.Load”.
I needed to right click the “Resources” directory (it says “(Editor)” beside it), right clicked and selected “Properties” to open up the window in this image: