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
1
Question by timviana · Apr 01, 2012 at 12:06 AM · editorinspectorcustomextensionsnapshot

Editor GUI: Object preview icon

Hi

I'm trying to show icons of game objects in my custom inspector attribute, I would like to use a small picture of the game object in a button, exactly like the ones we can find in this video.

The question is, given an GameObject, how do I display its icon? Something like: GUILayout/EditorGUILayout.Button(x) where x is the desired parameter, which is supposed to be the preview icon for the prefab.

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
8
Best Answer

Answer by timviana · Apr 01, 2012 at 02:21 AM

I found the answer:

 [Formerly]Texture2D EditorUtility.GetAssetPreview(Object obj);
 [Currently]Texture2D AssetPreview.GetAssetPreview(Object obj);

This function creates an object preview snapshot and returns as Texture2D.

Credit goes to blikstad on IRC: http://forum.unity3d.com/threads/128626-Asset-Preview-level-design-tool.

Comment
Add comment · Show 4 · 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 numberkruncher · May 21, 2012 at 11:25 PM 0
Share

Perhaps you would consider voting for a rock-solid implementation of EditorUtility.GetAssetPreview via http://feedback.unity3d.com/forums/15792-unity/suggestions/2834294-solid-implementation-of-editorutility-getassetprev

avatar image Gyfis · Aug 20, 2014 at 12:06 AM 4
Share

Updated answer, if someone gets here in 2014:

it's Texture2D AssetPreview.GetAssetPreview(Object obj); and AssetPreview is in UnityEditor namespace

avatar image ocimum Gyfis · Dec 20, 2015 at 09:59 PM 0
Share

I am glad you added this snippet! thx

avatar image Glurth Gyfis · Jan 11, 2017 at 08:48 PM 0
Share

thank you- I've edited the answer since I missed your comment initially!

avatar image
0

Answer by Bunny83 · Apr 01, 2012 at 01:33 AM

Unity uses their internal class PreviewRenderUtility to directly render a mesh preview in the inspector or the ObjectSelector. As already said it's an internal class so it can't be used (at least not that easy).

This internal class needs to use RenderTextures to be able to render to a texture. There's also the internal function EditorUtility.SetTemporarilyAllowIndieRenderTexture() which can do this, but as "user" you have no direct access to those functions.

If you have Unity pro you can create your own preview renderer or use the DrawMesh function to directly draw the mesh on the button. In the indy version it's getting a bit more complicated. You can also use a temporary camera and render the object directly, but i guess it takes a lot fiddling to get it working.

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 timviana · Apr 01, 2012 at 02:00 AM 0
Share

I found the answer on IRC, I tried to post here but it's waiting a moderator, it's an undocumented function and it isn't internal.

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How do I get the default scene GUI for a CustomEditor for RectTransform? 1 Answer

Unity editor and inspector header 0 Answers

Arranging KeyCode type variables in custom editor 0 Answers

Custom Inspector Variables 1 Answer

How do you make a custom inspector for a class or instance? 3 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