PROTEST: Unity does not have a cross-platform variable to get the Home or Documents path

Unity should make life easier for developers, not complicate it by forcing them to write very long ifs and switches based on the platform!
I can use variables like Application.persistentDataPath but they only work on windows! On android they don’t even write to the app’s private folder!
I expect Unity to automatically add the necessary permissions to the manifest and provide variables like

  • home
  • documents
  • desktop

if others feel the need for other folders write them in the comments.
And, most importantly, compatible with all OS versions: Windows XP to 7 changed the Documents path, Android changed the necessary permissions. As a developer I want to write the code once and then compile it for multiple platforms.
Is it only I think that Unity should provide this?

Functionality built into .NET could be worth a go.

The values might be different with Unity if they use different class libraries.

NO. Those functions work on Windows, maybe on Linux, but certainly not on android!

doesn’t Environment.GetFolderPath(Environment.SpecialFolder.Personal) work basically everywhere?

1 Like

It works on Windows, but on android it only returns root “/”.
I need Documents or Home

At this point Unity is not going to change anything to support two ancient versions of Windows.

And MyDocuments is antiquated system anyway and the less people using it the better. I’d rather games not use it at all. And I certainly don’t want games touching my Desktop. That’d be an immediate uninstall.

Dunno about Android but I’m pretty sure users always have to give permission to allow an app to read/write outside of its own package folder. Unity can’t just add these permissions themselves; that’d feel pretty sketchy.

Application.persistentDataPath is where you should shove data, and it works accross PC, Linux and Mac. Things like “the documents folder” is very platform-specific, not only in what path it has, but also if it even exits, and what you should put into it if it does.

I have been wanting a proper cross-platform (desktop, phone, console) API for writing files. Something that makes WriteFile("saves/mySave.json", saveContent); work correctly, no matter if you’re on desktop, phones, or a console. I feel like that’s the correct level of abstraction, instead of just “here’s named paths, good luck, lol” or “a fully fledged save system that also handles serialization of GameObjects for some reason”

1 Like

Many famous games write inside Documents. Tomb Raider does! It doesn’t annoy. OK, the desktop would disturb, but sometimes it might be necessary.
Other games write inside AppData.

I want if I need to write to the android home folder, unity adds the necessary permissions, then when the user installs the app they will see that write permission is needed. i don’t want to hide it. i just want unity to do it.

Unity, fortunately, should work on XP as well, so I expect that there is an API that works there as well.

The main purpose of these game engines is write once and compile everywhere, with the same code!
But why do I have to stand here and defend a legitimate request?

I had omitted the reason: I need a place to write logs so that in case of an error they can send it to me.

In fact I’d be content even with home, but better would be, as you say, to have a standard folder to write in.

It should never be necessary.

As far as I’m aware apps can’t write outside their own package without user permission. What you’re asking for is likely impossible.

Unity dropped Windows XP support with Unity 5.3. That’s nearly 9 years ago.

Unity has services that can do this for you already.

What are these services you speak of?

Writing the debug in the console is not enough, of course. I need
that my users can send me a file!

Apparently it’s too hard to google “Unity crash reporting”.

I don’t want to depend on an external service, and I also don’t want to know why you insist on telling me I’m wrong.
I expected you to tell me ready-made instructions for generating logs!

does anyone know how to write files or not?

It’s a Unity provided service. You’re asking Unity to give you a way to get crash and log reports from your users. Unity already have you covered. So what’s the problem?

2 Likes