Quantcast
Channel: Latest Questions on Unity Answers
Viewing all articles
Browse latest Browse all 171066

Loading TextAsset under different scenes

$
0
0
I am using TextAsset to load .txt resources into a label: //Load text data from resources TextAsset toothdata = (TextAsset)Resources.Load(filename, typeof(TextAsset)); reader = new StringReader(toothdata.text); //confirm if textdata is valid and read it if ( reader == null ) { Debug.Log(filename+".txt not found or not readable"); } else { // Read each line from the fil+string txt; string txt; longtext=""; while ( (txt=reader.ReadLine()) != null) { longtext += txt; } reader.Close(); UILabel label = NGUITools.FindInParents(labeltarget); Debug.Log (filename+".txt target found"); //the problem is below label.text=longtext;// line 106 //the problem is above Resources.UnloadAsset (toothdata); This script is shared among different scenes. If I open a single scene it works flawless but if I move from one scene to another the script gives me the following: NullReferenceException: Object reference not set to an instance of an object and points to line 106 (or line 25 in the script above) on that script. The problem persists even if I request text on one scene, return to the main and go back to that scene again. I am pretty sure I need to unload something but I am stuck. Any help? Thanks

Viewing all articles
Browse latest Browse all 171066

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>