- Home /
How do I make Unity Android save a read/write file anywhere other than persistentDataPath?
Hey guys, I am building a Unity Android game that gets started according to the settings set by a desktop (C#) application that writes these into a file as a string of bits using USB connection. Understood?
Now, I've come to a dead-end where I am confused as to the location the file should be at. I have two options:
i) save it on the desktop
ii) save it on android
So, if I save on the PC, Unity Android needs to access this particular file in a directory of an external device. That seems to bring in its own set of problems.
Second, if I'm gonna save on the Android device using Unity's new FileInfo(Application.persistentDataPath + "/AttentionSceneSettings.txt")
, the file that gets created cannot be written into by the PC.
So, what do I do here? Is there any way to overcome this? Please lemme know if additional information is needed.
Answer by ArminRigo · Sep 19, 2021 at 07:11 AM
I don't have a lot of experience, but I would say: either the Android device is set in developer mode and accessed with a tool adb, in which case you should(?) be able to write files from the PC; or if not, then I don't know exactly how you write files from the PC but I would instead consider making my own TCP protocol instead, where the Android connects to the PC that listens, or vice-versa.
And is there any resource that you could redirect me to, for learning how to make my own TCP protocol?
I would try to look through the google results for "c# tcp server example". The answers are general instead of being Unity-specific but should work fine. Don't try to go multi-threaded for this use case; look at the simpler examples.