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
6
Question by FatWednesday · Jun 24, 2013 at 03:42 PM · editorassetsselectionrename

Select asset for rename

Just a small curiosity as my browsing the docs has yet to reward me with anything regarding this matter.

I have a custom asset type that I am creating in a project. On creation the project window gets focus and the item is selected. However I was wondering if (and if so how) it is possible to have the object automatically select for renaming, much like the default assets do when you right click to create say a new material or shader.

I'm aware I could do the naming through a very basic popup window when the asst is created, but the aim is to have the asset behave as much like a regular unity asset as possible in terms of how you create and modify it.

Any help is appreciated, been looking around for a while but not found anything yet.

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 Loius · Jun 24, 2013 at 05:36 PM 0
Share

I don't know a coding solution, but F2 is the keyboard shortcut for 'rename currently selected thing' (works in Windows file explorer, too; might be windows-specific). If you can't make it automatic at least it can be convenient :)

2 Replies

· Add your reply
  • Sort: 
avatar image
11

Answer by TokiZR · Apr 18, 2014 at 05:51 AM

While delving into the same issue I found ProjectWindowUtil.CreateAsset(Object asset, string name) in the assemblies. In case anyone is still looking it creates the asset and starts renaming it.

Comment
Add comment · Show 3 · 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 Kumo-Kairo · Nov 15, 2014 at 06:05 PM 1
Share

You, sir, deserve more fame

avatar image SniperEvan · Jul 24, 2015 at 07:54 PM 0
Share

How do we get access to this method? Can we use it?


I found the answer. Header: using UnityEditor.ProjectWindowCallBack and using UnityEditorInternal.

avatar image jwvanderbeck · Jan 11, 2018 at 07:44 PM 0
Share

I know this is old, but many thanks for this!

avatar image
1

Answer by skalev · Sep 05, 2013 at 09:43 PM

I had the same question. This is how I resolved it. Note: this is basically a hack, I was using ILSpy to look at how unity does it, and it relies on a bunch of internal classes and functions.

What I opted up for, was getting the project window's reference, selecting the asset I have just created, and sending a keyEvent to the window with F2 as the key. Granted this only works for windows but you can find out which key to send if you need it to work on Mac.

For information on getting the window's reference, I would refer you to this thread:

http://answers.unity3d.com/questions/267097/editor-programming-experts-regarding-layouts.html

Note that the window name is different between unity 3 & 4 (there is more info on the above thread).

In code it looks like this:

     private static System.Type ProjectWindowType = typeof(EditorWindow).Assembly.GetType("UnityEditor.ObjectBrowser");
     private static EditorWindow projectWindow = null;
 
     public static void StartRenameSelectedAsset()
     {
         if (projectWindow == null)
         {
             projectWindow = EditorWindow.GetWindow(ProjectWindowType);
         }
         //should never be null but still ;)
         if (projectWindow != null)
         {
             var e = new Event();
             e.keyCode = KeyCode.F2;
             e.type = EventType.KeyDown;
             projectWindow.SendEvent(e);
         }
     }
     public static T CreateAssetAndStartRename<T>(string path = null, string assetName = null, string extension = ".asset") where T : ScriptableObject
     {
         var asset = CreateAsset<T>(path, assetName, extension, false);
         Selection.activeObject = asset;
         EditorUtility.FocusProjectWindow();
         StartRenameSelectedAsset();
         return asset;
     }

So to use, you would call CreateAssetAndStartRename(), which in turn calls CreateAsset (this you should already have implemented from your question, so I didn't include the code for that), sets the new asset as the active selection, focuses the project window, and then calls StartRenameSelectedAsset(), which makes sure there is a reference to the window, and sends it the event.

As you can tell these are static functions, I just have them in my CustomAssetUtility class. Using the generics here allows this to work with any scriptable object in the game (in my case, you can always extend the support obviously thorugh your own CreateAsset().

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

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

Related Questions

Custom Editor: show asset folders in ObjectField 2 Answers

Is it possible to rename an asset in V5.5? 2 Answers

Change angle of camera in prefab preview 4 Answers

Access or remove background color of AssetPreview 2 Answers

Working with the editor Selection 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