c# - Unity: Resources.Load is not working -
this question has answer here:
- using resources folder in unity 1 answer
string filepath = "hfba_25"; textasset textasset = resources.load(filepath) textasset; string filestring = textasset.text; i cant seem figure out why resources wont load not in editor , not on android device? file hfba_25 in folder assets > resources > hfba_25
edit_1: textasset returned null
if textasset null, can mean 2 things (due code):
- the file
hfba_25doesn't exist inresourcessubdir; - the file exist, can't cast
textasset.
to check of 2 true, need change code this:
textasset textasset = (textasset)resources.load(filepath); debug.log(textasset); then run inside unity , check console.
if null, means it's 1 (file doesn't exist).
if instead invalidcastexception: specified cast not valid., means it's 2, file exists can't cast textasset type.
this happens because in c#, if cast using keyword as, when cast invalid don't exception, instead reference set null.
Comments
Post a Comment