Hello,
I notice how Resources.Load(“filename”) not only allows you to store information from a .txt file into an Object which can then be converted into a String, but is required if you want to make it portable from one computer to another when published into an executable.
I also notice how ‘StreamReader’ will not work when I publish my project into an executable even when I transfer all the .txt files that it is supposed to read into my project_Data folder, but placing all my files into a resource folder and using ‘Resources.Load()’ instead works because the .txt file(s) get stored into my project during publishing.
Since I already know how to read from .txt files and make it portable (by using Resources.Load()), I was wondering if there is also a way to write to .txt files and make it portable too when I publish my project.
Also, what if I want to manually change or create a .txt file that my published program can read from, using a separate text editing program to create or change the file?
Thank you for any information,
Michael S. Lowe
It does work. You’re presumably just getting the path wrong.
–Eric
I suppose the reason why my executable works on my computer but crashes on somebody elses’ laptop even when I unzip the executable folder onto the laptop is because the executable is not portable for a laptop then. Is there a Unity plugin that I should download onto the laptop to be able to run executables on the laptop? If using Resources.Load() and placing my files into a resource folder (as opposed to using StreamReader) makes it so that the .txt file(s) get compiled into the executable so that it is more guarantee-able, what could I use to write to these built-in files?
I think this asset might help you, its called RESOURCEFUL JSON. It lets you define a file of stats, and it will load them up the first time you run the game and then put them into playerprefs for that operating system.
Also, there is SAVED! Which lets you define variables that get saved to a file, which let you transfer them over to other operating systems without having to define everything in code.
You cannot write to Resources. They are not separate files when they’re compiled into the runtime. As far as StreamReader not working, I would assume that you’re getting the path wrong. Use Application.dataPath instead of hard-coding it (if that’s what you’re doing).
–Eric