c# - Unity: Resources.Load is not working -


this question has answer here:

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):

  1. the file hfba_25 doesn't exist in resources subdir;
  2. 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

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -