• 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
1
Question by Bovine · Jul 09, 2013 at 10:23 PM · editor-scriptingassetscriptableobjectcreate

Get Current Project Window Folder

I have a few editor scripts that make assets for me, but when I right-click and select my context menu item to create the asset I have no idea where to get the current project's path from, so I end up making the asset in the root of the assets folder.

I was hoping there might be some method or static property to return me t$$anonymous$$s - anyone solved t$$anonymous$$s one?

i.e. I have a ScriptableObject for behaviours. I right click in the Project window to create a new behaviour - I'd like that behaviour to be created at the location I right-clicked.

Thanks Bovine

Comment
Add comment
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

2 Replies

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

Answer by mhtraylor · Jul 09, 2013 at 10:47 PM

AssetDatabase has some methods for getting asset paths in the project; these might help.

Comment
Add comment · Show 6 · 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 Bovine · Jul 09, 2013 at 10:49 PM 0
Share
avatar image mhtraylor · Jul 10, 2013 at 02:38 AM 0
Share
avatar image Bovine · Jul 10, 2013 at 04:16 AM 0
Share
avatar image mhtraylor · Jul 10, 2013 at 12:59 PM 1
Share
avatar image Bovine · Jul 10, 2013 at 01:03 PM 0
Share
Show more comments
avatar image
0

Answer by Wappenull · Feb 26, 2021 at 06:16 AM

Use built-in property

You can use built-in property to generate a "create asset" menu

 [CreateAssetMenu( menuName = "Wappen Asset/WaveBankData" )]
 public class WaveBankData : ScriptableObject
 {


And it will magically added to right click menu -> Create. Has same functionality as Unity's one. It will be created in current browser location, prompt for a rename, etc.

alt text


As a bonus

here is how TextMesh pro determine current right-click folder. If you call Selection.assetGUIDs under MenuItem call back, it will guarantee current displaying folder (the one that you clicked on its empty space)

     [MenuItem("Assets/Create/TextMeshPro/Color Gradient", false, 115)]
     public static void CreateColorGradient(MenuCommand context)
     {
         string filePath;

         if (Selection.assetGUIDs.Length == 0)
             filePath = "Assets/New TMP Color Gradient.asset";
         else
             filePath = AssetDatabase.GUIDToAssetPath(Selection.assetGUIDs[0]);



asset.png (20.0 kB)
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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

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

Related Questions

I can't find my scriptable object though I've creat asset menu... 2 Answers

Create List of custom class types, for use in custom editor 0 Answers

How set order in [MenuItem] attribute like in [CreateAssetMenu] attribute? 2 Answers

Importing and using custom assets 0 Answers

ScriptableObject assets null on startup, then reappear? 1 Answer


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