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
0
Question by enerology · Aug 04, 2020 at 06:08 AM · editor-scripting

How to set thumbnail of assets from a script?

How would I like to know how to set an asset's texture from an editor script. Basically, I made my own rendering engine in DOTS and want to preview the prefabs with my own image and not the default blue cube. I tried

 public override Texture2D RenderStaticPreview(string assetPath, UnityEngine.Object[] subAssets, int width, int height)
     {
         Debug.Log("Rendered Statics");
         ConvertRenderer renderer = target as ConvertRenderer;
 
         if (renderer == null || renderer.sprite == null)
             return null;
 
         Texture2D cache = new Texture2D(width, height);
         EditorUtility.CopySerialized(AssetPreview.GetAssetPreview(renderer.sprite), cache);
         return cache;
     }

Doesn't seem to do anything. If you need a reference for what I am trying to do, there is an asset called "AssetIcons" that does what I am talking about.

Thanks!

Comment
Add comment · Show 2
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 enerology · Aug 05, 2020 at 04:43 PM 0
Share

I got my DOTS sprite rendering engine working perfectly, this is just one of the last hiccups. Basically, I want to preview prefabs from the asset window and just need to replace the default cube texture.

avatar image enerology · Aug 15, 2020 at 02:27 AM 0
Share

Bump, I know a lot of others wanted something similar to this and this should help them out if it gets answered.

2 Replies

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

Answer by enerology · Aug 16, 2020 at 05:18 PM

 [CustomEditor(typeof(GameObject))]
 public class ChangeObjectThumbEditor : Editor
 {
     public Texture2D texture;
 
     public void OnEnable()
     {
         texture = Resources.Load<Texture2D>("DesertHeart");
     }
 
     public override Texture2D RenderStaticPreview(string assetPath, UnityEngine.Object[] subAssets, int width, int height)
     {
         Debug.Log("Rendered Statics");
         GameObject renderer = target as GameObject;
 
         if (renderer == null || texture == null)
             return null;
 
         Texture2D cache = new Texture2D(width, height);
         EditorUtility.CopySerialized(AssetPreview.GetAssetPreview(texture), cache);
         return cache;
     }
 }

Here is the code that allows you to change the thumbnail. It's extremely primitive, but should give you an idea of how to proceed.

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

Answer by Pangamini · Aug 15, 2020 at 11:27 PM

RenderStaticPreview only works for ScriptableObjects, not for gameObjects with a component (there could be more possible thumbnails coming from different scripts that way)

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 enerology · Aug 16, 2020 at 05:16 PM 0
Share

You just game me an idea to use "[CustomEditor(typeof(Gameobject))]" and it worked! It's still behaving weird but the basic idea behind what I wanted works.

Thanks!

avatar image Pangamini enerology · Aug 16, 2020 at 05:19 PM 1
Share

Cool, I didn't think it'd work :-P Also I think that static preview is only visible for bigger size thumbnails, not when you are listing the assets with the smallest gui possible - not sure, maybe it changed

avatar image enerology Pangamini · Aug 16, 2020 at 08:29 PM 0
Share

It also works for small assets. $$anonymous$$y textures show up in the object fields which are only 32x32 pixels. I am amazed that it worked so well and didn't need more code to work properly.

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

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

Related Questions

Do you know of any advanced custom editor examples? 1 Answer

How to include custom art/styles in editor scripts 1 Answer

Detect when project is saved 1 Answer

Inspector Scripts stops working after each compile 2 Answers

How to highlight an object in the heirarchy from code? 2 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