I’m getting this error:
get_dataPath can only be called from the main thread.
Constructors and field initializers will be executed from the loading thread when loading a scene.
Don’t use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function.
All I’m trying to do is load a text file from the resources folder of the project. Originally I was just setting the filepath with a string and loading from that but it would not work when publishing to the web.
Code is as follows:
TextAsset infoFile; public SearchField searchfield; public void Update() { if (searchfield.Confirm == true) { infoFile = (TextAsset)Resources.Load(searchfield.ToString(), typeof(TextAsset)); string[] allcontents = File.ReadAllLines(infoFile.text); contents = ConvertStringArrayToStringJoin(allcontents); } }