I have a program that reads in many txt files that get saved into strings in this manner:
import System.IO;
var ITFile = “IT.txt”;
…
var room13F : String;
…
var sr = new StreamReader(Application.dataPath + “/Rooms/” + ITFile);
room13F = sr.ReadToEnd();
sr.Close();
then I display them later and all works fine. However when I make an executable none of the files get loaded. I’ve made a copy of the “Rooms” folder where the .exe is but that seems to not be the answer. Can anyone help me out or push me in the right direction?
Well I added the code you suggested and no prompt came up. I’m sure my path works fine in the code because the file gets read in and saved as a string in the editor when play is hit. All 15+ files are read and cam be used just fine until I make it an executable file and then absolutely all of them are blank.
So something is lost in transferring it into a executable. After a good bit of research, I saw Resources.Load but I am unsure if that is the solution I am looking for and although I am willing to put in hours to redo my code if Resources.Load is my answer, if someone more experienced than I could tell me if I’m on the right track or not I’d be thrilled.
Resources.Load can load textassets right from the assembly, so the user will never get to see the text at all (it will not exist as a standalone file).
that way you could indeed avoid such problems.
also your code would no longer rely on IO (allowing you to build even a webplayer for example)
What the end product would be is it loads from a .txt file that can be switched out by people who are not so Unity savy. This way departments could just switch out .txt files instead of touching unity for their descriptions. (this is for kind of a directory thing)
Would resources.Load pull from files in a path or is that something that I would have update myself in Unity.
I want this to be easily updated by someone with little to no unity experience after I give the end product.
Resource.Load only loads resources from the project which are compiled at compile time.
If you want to load from outside you indeed must use System.IO
that though normally should not be a problem, I’m working on a project where we cache and create a plentitude of files in a directory.
But whats an extremely bad (inacceptable to be adequate) idea is using the applications datapath.
on osx this ends within the .app folder, on windows this ends in the same folder which in case of the program files folder will lead to an error cause you can’t write there dynamically if UAC is enabled or if the user is not an admin
Ok so it finally got solved. What was the issue is that when it is turned into an executable Application.dataPath does not refer to the same spot. I had tried putting my folder nest to the exe but where it needs to be in the build data folder that is created with it.