- Home /
Resources.Load from TextAsset string
Hello. So I need to get a texture from my resource folder, and I really can't seem to get it to work. I have a TextAsset with a file path for the texture, and... well it's easier to just show my code:
string iconPath = variables[n].Remove(0, 5);
itemIcon = (Texture)Resources.Load(iconPath, typeof(Texture));
and from the TextAsset:
icon Sprites/maleBase/weapon/icon_gold_sword
variables[n].Remove(0, 5) removes the "icon " from the text. So it should be Sprites/maleBase/weapon/icon_gold_sword
, but it still doesn't work.
Any ideas? :)
You say "is should be" but is it? Just Debug.Log() it to be sure. Also, do you have that asset in your Resources folder? Is it a Texture or a Texture2D?
I tried Debug.Log and it was "Null" in the console. And yes, I have it in my resource folder. I've tried both Texture2D and Texture. I should probably have mentioned that it works if I don't try to use the path from the textasset, and just type it manually, but I'd really like the path to be specified in the textasset.
EDIT: By manually I mean like this: itemIcon = (Texture)Resources.Load("`Sprites/maleBase/weapon/icon_gold_sword`", typeof(Texture));
i tried to recreate your variables array and i did the same thing. It got the path properly. Check the variables array once whether the path is actually there in variables[] array
icon Sprites/maleBase/weapon/icon_gold_sword
UnityEngine.Debug:Log(Object)
ItemList:Awake() (at Assets/Scripts/ItemList.cs:46)
That is what I got from Debug.Log(variables[n]). Should I post my entire script?
yeah post the part where you are loading the variables[] array
Answer by RakshithAnand · Jul 01, 2014 at 03:13 PM
Ok, if you are getting the path properly, you can try this as well with "@' before path
itemIcon = (Texture)Resources.Load(@iconPath, typeof(Texture));
Your answer
![](https://koobas.hobune.stream/wayback/20220613152926im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Get file in project using it's path 1 Answer
when loading a textasset from .txt file, the quotations disappear?? 1 Answer
Load file name form Resources folder with special characters 1 Answer
Do I need to manually call Resources.UnloadUnusedAssets? 0 Answers
Does Resources.Load work with Sprites? 2 Answers