- Home /
TextAsset / Resources.load return null
Hi. I searched anywhere but nothing helped me. I have this code for loading different languages using same key in C#.
http://wiki.unity3d.com/index.php?title=TextManager
I have one big problem. When i start the game and try code work, it could'n find any file. Problem is on this line:
TextAsset textAsset = (TextAsset) Resources.Load(fullpath, typeof(TextAsset));
This line always return null. I don't know why. I searched for the same issue but nothing helped me. I found these themes: http://answers.unity3d.com/questions/1017186/textasset-always-returns-null-despite-the-file-exi.html
http://answers.unity3d.com/questions/188284/loading-textasset-returns-null.html
https://forum.unity.com/threads/resources-load-always-returning-null.488281/
To the end. I know, the files must be placed in the Resources folder. I use this method (Resources.Load) in another part of the code and work fine. Thanks all who helped me.
check the following:
Do you have your resource folder inside your assets folder?
Do you call Destroy() method on the textAsset anywhere in your code?
Double check your files again.
Yes. I have my resources folder inside assets. $$anonymous$$ethod Destroy() i don't call nowhere.
Answer by Marks98 · Sep 25, 2017 at 05:20 PM
Thank all who answered me. I do not know how, but when i changed the code to this: TextAsset textAsset = (TextAsset) Resources.Load ("Languages / en", typeof (TextAsset)); It works. I changed file form .po to .txt. I don't know how is possible is, i did this before several times and it didn't worked. Thanks all.
YES! just had the same problem for hours and for what ever reason this is the only combination that is actually loading my resource properly.
Answer by haruna9x · Sep 23, 2017 at 04:16 PM
Did you really find out the problem:
The path is relative to any Resources folder inside the Assets folder of your project, extensions must be omitted.
Source: Resources.Load
Text Assets are a format for imported text files. When you drop a text file into your Project Folder, it will be converted to a Text Asset. The supported text formats are:
.txt
.html
.htm
.xml
.bytes
.json
.csv
.yaml
.fnt
Source: TextAsset
Yes, i know it. I changed the format of the file from the .po to .txt and doesn't help it me.
Show me the fullpath, because Resources.Load points directly to the Resources folder, so you need to make sure it does not exist in your path. Example This is where you place the file:
Asset/Resources/$$anonymous$$yAsset /$$anonymous$$yText.txt
You would call this:
TextAsset textAsset = Resources.Load<TextAsset>("$$anonymous$$yAsset/$$anonymous$$yText");
I use this : Resources.Load("Languages/en.po"); Here is example of my way. It will be probebly correctly.
Answer by losingisfun · Dec 05, 2018 at 11:05 PM
For anyone else having trouble, you may find this helpful.
when importing a simple text file sometimes there is no extension (.txt) and unity wont recognise it as a text asset. To do so, click and edit the file's name to add an extension. An easy indicator of this is the icon that unity displays for the file,
If they appear like this, they are recognised as text assets, however if they appear as below, they havent been recognised.
I hope this helps!
Thanks for posting this.. $$anonymous$$ade me realise that OpenOffice was somehow wrecking my .csv files.. Re-saving with a different program instantly fixed the issue I was having..
Answer by GLeBaTi · May 14, 2019 at 03:15 PM
For anyone else having trouble, you may find this helpful.
remove extension from argument: Resources.Load("MyJsonFileName") //without .json
save file as CRLF (not LF)
save file into folder "Resources"
I was using .txt and had to remove the file extension for some reason too. Thanks.