Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
0
Question by grimmy · Feb 22, 2013 at 04:04 PM · editoreditorguilayoutobjectfield

How can I get the full path to an object in an ObjectField?

I have an editor script in which you can choose textures and assign them to EditorGUILayout.ObjectFields. After the user has dragged textures(objects) into the object fields I'd like to know the paths of where they came from so I can perform other functions on them.

How is that done?

Comment
Add comment · Show 1
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 Fattie · Jan 25, 2016 at 03:59 PM 0
Share

related ! http://answers.unity3d.com/questions/1133078/recover-path-information-for-an-asset-but-at-runti.html

3 Replies

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

Answer by Paulius-Liekis · Feb 22, 2013 at 04:17 PM

AssetDatabase.GetAssetPath

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 grimmy · Feb 22, 2013 at 05:10 PM 0
Share

Looks like you were the first to answer correctly. You win a prize! Thanks everyone!

avatar image
6

Answer by numberkruncher · Feb 22, 2013 at 04:26 PM

Path relative to project folder can be found using the following:

 Object selectedObject = EditorGUILayout.ObjectField(selectedObject, typeof(Object));
 if (selectedObject != null) {
     string assetPath = AssetDatabase.GetAssetPath(selectedObject);
 }

Which will produce a string like:

 "Assets/Some/Path/YourObject.prefab" (if you select a prefab)

You can then get the absolute path (if needed) using:

 using System.IO;
 ...
 string filePath = Path.Combine(Directory.GetCurrentDirectory(), assetPath);
 // i.e. "/Your Unity Project/Assets/Some/Path/YourObject.prefab"

 // The following is needed if you are using Windows :-)
 filePath = filePath.Replace("/", "\\");
 // i.e. "C:\Your Unity Project\Assets\Some\Path\YourObject.prefab"
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 Fattie · Jan 25, 2016 at 03:59 PM 0
Share

you may know this,

http://answers.unity3d.com/questions/1133078/recover-path-information-for-an-asset-but-at-runti.html

@numberkruncher .. thanks!

avatar image ruudvangaal · May 06 at 07:59 AM 0
Share

For others reading along: I used Path.Combine() until that failed on a file inside a package. The filename for that was not exactly what was stored on disk. Turned out that using path=Path.GetFullPath(path) seems to do some magic behind the scenes to resolve a virtual package filename into an absolute disk file.

avatar image
5

Answer by appearance · Feb 22, 2013 at 04:18 PM

You can use :

 string path = AssetDatabase.GetAssetPath (myObject);

Note: path will be the full path to the object that has been dropped onto "myObject" objectfield.

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

14 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 avatar image avatar image avatar image

Related Questions

EditorGuiLayout - Objectfield 1 Answer

EditorGUILayout.ObjectField cannot be changed. 1 Answer

why I Cant Add Multiple Objects to the "Object Field" in Editor Window? 3 Answers

EditorGUILayout.ObjectField does not allow me to select a script. 1 Answer

How can I get a list of specific game objects in the object picker opened from an ObjectField()? 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