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
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 this - anyone solved this 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

None that I can see. I have looked and unless I've missed something...

avatar image mhtraylor · Jul 10, 2013 at 02:38 AM 0
Share

You can use AssetDatabase.GetAssetPath() on Selection.activeObject. You can make sure it is a directory with System.IO.Directory.Exists() or something similar. There was a similar question that looped through the selection array, but I'm guessing activeObject would be better since you are just right-clicking on a folder.

Hope this helps.

avatar image Bovine · Jul 10, 2013 at 04:16 AM 0
Share

Hmmm. I'll take a look but typically I've right-clicked in the folder, so not sure there's anything selected. I guess it might be a partial solution...

avatar image mhtraylor · Jul 10, 2013 at 12:59 PM 1
Share

Just double-checked this and right-clicking inside the folder does select it (or if you clicked an asset in the folder, you can extract the path from that as well).

avatar image Bovine · Jul 10, 2013 at 01:03 PM 0
Share

Righto I'll give that a whirl then later as it's a pain finding the new asset and should be easy to sort. Looking like a helper function to me :)

Will mark answered if it does as you say

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.

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... 1 Answer

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