There is no Unity specific API for getting the project folder, but you can use System.IO.Directory.GetCurrentDirectory. The unity editor expects the current folder to be set to the project folder at all times.

If you are changing the current directory in your editor scripts using System.IO.Directory.SetCurrentDirectory you need to restore the directory back to the project folder when you are done. Otherwise the next time unity compiles your scripts it will prompt you with a dialog box and a message stating you need to restore the current directory back to the project directory and only gives you a “Quit” button to click on that will quit unity.

    // save project folder
    var projectFolder = System.IO.Directory.GetCurrentDirectory();
    // set current directory to a folder of your choosing
    System.IO.Directory.SetCurrentDirectory("c:\\some folder name");
    // do what you need to do
    // ...

    // restore current folder back the the project folder 

Add comment

  • Comment
  • Preview

Created by: X

Just another personal website in this crazy online world

Name of author Dean Lunz (aka Created by: X)
Computer programming nerd, and tech geek.
About Me -- Resume