Hi, I’m developing a Unity extension. I want to display custom script icons in the component list I created.
AssetPreview.GetMiniTypeThumbnail is working perfect for built-in unity icons such as Camera but it’s returning an empty icon for custom scripts which have custom icons.
This may be a post from 2014, but also after running into this issue, I have come to a solution!
As mentioned by @Xtro the base AssetPreview.GetMiniTypeThumbnail function fails to return a Texture2D for custom scripts, and will only return a blank page icon. To correctly pull the icon from a custom script as @oscarAbraham has written, you need to get the asset/asset path of the custom script.
And if you what to use this in a image’s Sprite, you can then create a sprite with the Texture2D as such:
Sprite iconSprite = Sprite.Create(scriptIconTexture2D , new Rect(0, 0, scriptIconTexture2D .width, scriptIconTexture2D .height), new Vector2(0.5f, 0.5f));
Of course note that getting the thumbnail icon of Scriptable Objects is a different process where you modify the FindAsset search filter to “t:CustomScriptableObjectClass”, where all Scriptable Object asset GUIDs created from your CustomScriptableObjectClass will be return, and a foreach loop and be iterated through to get each of their paths and then their assets to pull their icons from.