Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How to get the project path using code?

Discussion in 'Scripting' started by UniversalGesture, Oct 6, 2018.

  1. UniversalGesture

    UniversalGesture

    Joined:
    May 29, 2017
    Posts:
    125
    How can I get the path of the project from my code?
    My script needs to know the path of a specific folder, however manually writing the path will not work since it may be different for every project.
     
  2. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,350
  3. UnusAutomationSystems

    UnusAutomationSystems

    Joined:
    Jul 15, 2019
    Posts:
    49
    danBourquin likes this.
  4. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    20,943
    Simplest solution is to just chop off the "/Assets" part. Code below should work but I haven't tested it.

    Code (csharp):
    1. string path = Application.dataPath.Substring(0, Application.dataPath.LastIndexOf('/') - 1);
     
  5. UnusAutomationSystems

    UnusAutomationSystems

    Joined:
    Jul 15, 2019
    Posts:
    49
    I used

    path = Directory.GetCurrentDirectory();
    path+ "/Builds/SystemMonitor/MultiExeProgram.exe"
     
    Dustin_00 likes this.