Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
4
Question by Mattivc · Apr 29, 2012 at 02:26 PM · projectpathsystem.io

Getting the absolute path of current project

I am currently working on a editor script that requires me to make use of System.IO, because Unity does not seem to have a function for getting every prefab in a specific asset folder. And i therefore have to use System.IO to get every file with a ".prefab" extension in the folder and then loop trough that list using AssetDatabase.LoadAssetAtPath()

But as i want this editor script to work on multiple machines with the project in different locations. As well as working on both Mac and Windows. I need a way to get the absolute path of the currently opened unity project. How do i do that?

So it would be something like this on windows:

 "C:\Projects\MyUnityProject"

And something like this on the mac:

 "/User/Projects/MyUnityProject"
Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image syclamoth · Apr 29, 2012 at 02:34 PM 1
Share

I'm pretty sure you don't actaully need the absolute path with System.IO. I've been able to use it cross-platform before, just with relative paths- it seems to accept those by default anyway.

avatar image Mattivc · Apr 29, 2012 at 03:27 PM 0
Share

I didn't realize it accept relative path. Just assumed it had no notion of the unity path as its part of .Net and not Unity specific. Thanks for pointing me in the right direction.

5 Replies

· Add your reply
  • Sort: 
avatar image
5
Best Answer

Answer by Paulius-Liekis · Apr 30, 2012 at 09:17 AM

You can use relative paths like "Assets/MyPrefabs/Prefab1.prefab".

Application class contains a bunch of properties which return project paths, look into that.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
16

Answer by MadDave · Aug 08, 2012 at 11:27 AM

Application.dataPath is what you are looking for.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image steinbitglis · Aug 01, 2015 at 05:28 PM 2
Share

I feel I need to point out that this is wrong, since there are no asset folders in builds.

avatar image IgorAherne steinbitglis · Sep 23, 2017 at 05:10 AM 2
Share

https://docs.unity3d.com/ScriptReference/Application-dataPath.html

avatar image
1

Answer by GVGiu · Sep 18, 2013 at 04:25 PM

There was a VCPath class on the UnityEditorInternal namespace that did the Job. ("VCPath.Project") But that class is no longer present after version 4.2.x. Using C# for editor stuff it will work by using Environment.CurrentDirectory, though I'm not sure how reliable that is.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image dsada · Dec 17, 2017 at 02:41 PM 0
Share

This was my solution for finding the relative path that my native plugin uses :) Thanks a lot from the future, this helped me a lot!

avatar image
0

Answer by yatagarasu · Aug 30, 2014 at 01:01 PM

I do something like this to get Assets/Resources path, while playing in editor, to implement my "builtin level editor". But I do not use this path in final product.

     string codeBase = Assembly.GetExecutingAssembly().CodeBase;
     UriBuilder uri = new UriBuilder(codeBase);
     string path = Uri.UnescapeDataString(uri.Path);
     resourcePath = Path.GetFullPath(new Uri(Path.Combine(Path.GetDirectoryName(path), "../../Assets/Resources")).AbsolutePath);
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by ittimstudio · May 06, 2020 at 08:43 AM

My solution

 public class GetProjectPathSample
 {
     public static string GetProjectPath()
     {
         var args = System.Environment.GetCommandLineArgs();
         for (int i = 0; i < args.Length; i++)
         {
             if (args[i].Equals("-projectpath", System.StringComparison.InvariantCultureIgnoreCase)) return args[i + 1];
         }
         return string.Empty;
     }
 }

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

11 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

GetDirectories() does not work on Android 1 Answer

Access assets from project window through code 1 Answer

Relative asset paths 1 Answer

Cannot Open Projects: Invalid Project Path 1 Answer

A* Pathfinding, destroying a path once it has reached its end 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges