x


Getting the absolute path of current project

I am currently working on a editor script that requires me to make use of http://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 http://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"
more ▼

asked Apr 29 '12 at 02:26 PM

Mattivc gravatar image

Mattivc
1.7k 55 60 67

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.

Apr 29 '12 at 02:34 PM syclamoth

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.

Apr 29 '12 at 03:27 PM Mattivc
(comments are locked)
10|3000 characters needed characters left

2 answers: sort oldest

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

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

more ▼

answered Apr 30 '12 at 09:17 AM

Paulius Liekis gravatar image

Paulius Liekis
7.3k 16 24 45

(comments are locked)
10|3000 characters needed characters left

Application.dataPath is what you are looking for.

more ▼

answered Aug 08 '12 at 11:27 AM

MadDave gravatar image

MadDave
544 1 2 7

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x268
x238
x31

asked: Apr 29 '12 at 02:26 PM

Seen: 2502 times

Last Updated: Aug 08 '12 at 11:27 AM