- Home /
How do I get the Application Path?
I know I can get the application data path, but is it possible to get just the application path? I want to have a config file next to the executable file/icon on mac and windows and not in a folder
So I want player.exe config.dat
and for mac
Player (package) config.dat
Answer by Eric5h5 · Mar 13, 2010 at 10:03 PM
I used this in one of my scripts:
path = Application.dataPath;
if (Application.platform == RuntimePlatform.OSXPlayer) {
path += "/../../";
}
else if (Application.platform == RuntimePlatform.WindowsPlayer) {
path += "/../";
}
@darkhog, if you'd like to have read/write access, use Application.persistentDataPath
No, it has to be next to executable as it will contain several things bundled with the game.
Answer by proavus · Sep 01, 2011 at 03:34 PM
What I would do is Path.GetFullPath(".")
, but didn't test it anywhere except of PC
This worked great for me in OS X Yosemite as well. Thumbs up!
This has helped me a ton! I've looked everywhere for this!
Answer by Orion_78 · Feb 27, 2017 at 03:48 PM
What I would use is Path.GetDirectoryName(Application.dataPath)
Answer by Rustam-Ganeyev · Sep 07, 2011 at 04:45 AM
You can use Application.persistentDataPath. It's safe to write there.
I know this is an old thread, but using Application.persistentDataPath is absolutely where you should store configuration files, save games, logs, anything you want to exist between multiple runs of your game.
It is guaranteed to be a valid and approved location on all platforms for you to store persistent data without having to worry about platform rules, permissions, sandboxing etc.
Hacking you way around finding the application location and/or writing data files in other locations is asking for trouble on some platforms and might change in a future version of Unity.
Although true, this path is only known by the application instance from inside Unity. Third party tools, launchers, patchers, and middleware may not be able to correctly guess the path. And there are many cases where this is not the right solution.
Sometimes it is required for the application to be aware of its current root structure in terms of the root binary executable. However, the OP was seeking for it to go side-by-side with the executable / player package, not sure this addresses the question.
Answer by qJake · Mar 13, 2010 at 09:47 PM
Well, if this were a regular Windows application, I would have told you to just use Application.StartupPath
, but since it's not (and the Unity library has their own version of the Application class), I don't think what you're asking for is possible.
I'm pretty sure the dataPath
variable is there for cross-platform compatibility, since the filesystems are different on Windows/Mac/iPhone, etc, so what the dataPath
does is gives you a unified, safe location where you can store data, regardless of target platform.
Your answer
![](https://koobas.hobune.stream/wayback/20220612110101im_/https://answers.unity.com/themes/thub/images/avi.jpg)