• 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 xEnOnn · Apr 14, 2013 at 02:25 AM · c#editorprefabunityeditorselection

Selecting a newly created empty prefab by an editor script

After creating an empty prefab through an editor script, how can I get the editor script to subsequently select the empty prefab in the asset folder?

I tried this:

 var prefab = PrefabUtility.CreateEmptyPrefab("test.prefab");
 AssetDatabase.Refresh();
 Selection.activeObject = prefab;

But this doesn't select the prefab.

Comment
Add comment · Show 8
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 numberkruncher · Apr 14, 2013 at 03:29 AM 0
Share

Could you let me know if the following works for you:

 Selection.objects = new Object[] { prefab };

 // the following line is optional but nice :)
 EditorGUIUtility.PingObject(prefab);
avatar image xEnOnn · Apr 14, 2013 at 04:24 AM 0
Share

Thanks! Selection.objects works! :D It seems that PingObject wouldn't work when I'm going to run Selection.objects. Putting PingObject before or after the Selection.objects doesn't ping the object. Remove the Selection.objects and the ping will appear but the object not selected.

avatar image numberkruncher · Apr 14, 2013 at 04:49 AM 0
Share

Try the following ins$$anonymous$$d:

 EditorInternalUtility.FocusInspectorWindow();
 EditorGUIUtility.PingObject(prefab);
 Selection.objects = new Object[] { prefab };
avatar image xEnOnn · Apr 14, 2013 at 04:55 AM 0
Share

It looks like it couldn't resolve EditorInternalUtility. I tried InternalEditorUtility ins$$anonymous$$d but it doesn't have the method FocusInspectorWindow.

avatar image numberkruncher · Apr 14, 2013 at 05:03 AM 0
Share

EditorInternalUtility is undocumented but it is working for me in both Unity 3.5.7 and 4.1.2. Obviously you need to have using UnityEditor; at the top of your script.

Show more comments

0 Replies

· Add your reply
  • Sort: 

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

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

12 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

Related Questions

Working with Unity Editor 1 Answer

Distribute terrain in zones 3 Answers

Changing Prefab Variables From Another Script In Editor 1 Answer

Character Selection 0 Answers

Adding a component in editor mode by selecting an Enum. 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