- Home /
How can I asynchronously load and save text files?
My game has several text files that will be included with the app when shipped.
When a player creates a new game, the text files are copied so they can be loaded, edited, then re-saved at runtime.
The load & save process needs to be:
asynchronous
cross-platform, especially for mobile (web player not needed)
available without Unity Pro
The only thing I've found that seems to work is WWW but I'm not sure if there are cross-platform problems or if there is a better alternative.
what do you mean "the only thing that works is WWW" ?
that's just what it is for, heh !
Note that, other than audio, Unity unfortunately DOES NOT stream large files well.
http://answers.unity3d.com/questions/433609/hiccups-when-loading-images-from-resources-folder.html
Other than the fact you can't get rid of items from memory, it's the only huge "$$anonymous$$or problem" in Unity at the moment.
Thanks. Good thing I was only making a test demo. It would have been sad to write half the app then encounter the strea$$anonymous$$g problem.
Answer by kilian277 · Jun 15, 2013 at 09:43 PM
You can use the .NET assemblies for that like ,
Streamreader , reads a file in a stream: http://msdn.microsoft.com/en-us/library/system.io.streamreader.aspx
StreamWriter , writes to a file in a stream: http://msdn.microsoft.com/en-us/library/system.io.streamwriter.aspx
If you want it crossplatform keep the file as text so there are no binary problems whilst porting.
I thought .NET was only for PC distribution. This works on all mobile (iOS, Android, BlackBerry, Win$$anonymous$$o) and consoles?
await isn't available for Unity, so this can't be used async
I know this is a 7 years old answer but it solved my problem.
BTW with a little magic you can use await/async/thread in Unity