Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on Dec 8, 2022, between 7 am & 7 pm EST, in the DOTS Dev Blitz Day 2022 - Q&A forum, Discord, and Unity3D Subreddit to learn more about DOTS directly from the Unity Developers.
    Dismiss Notice
  3. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

Changing the preview image?

Discussion in 'Editor & General Support' started by Democide, Feb 15, 2016.

  1. Democide

    Democide

    Joined:
    Jan 29, 2013
    Posts:
    312
    So, I have a bunch of custom ScriptableObject assets, and when I change the project view to show larger preview icons, I only get the default asset image. However I'd rather show something else to give me a better overview. What's the best way to change this?
     
  2. McMayhem

    McMayhem

    Joined:
    Aug 24, 2011
    Posts:
    443
    Hey there Martin. I've got a whole bunch of custom icons and gizmos I use for my custom components so I've dabbled quite a bit in what you're talking about. I'm just a little bit confused on what exactly is happening on your side. Are you saying that you are able to set the icon and it reverts to the original C# icon when increasing the icon size in the Project tab?

    Otherwise, I assume you've set up your icons using the drop down window on the Icon Object in the Inspector tab. Looks like this:


    If you click on "Other..." it will open up the standard texture browser and you can pick from anything in there.

    Hope that helps a bit.
     
  3. Democide

    Democide

    Joined:
    Jan 29, 2013
    Posts:
    312
    So, I've fiddled with this a bit, and using RenderStaticPreview to show an image from within the asset, and now I have this:

    Screen Shot 2016-02-16 at 13.22.58 1.png

    It does work but doesn't seem to update all the preview images.

    Here's the code:

    Code (CSharp):
    1.  
    2.     public override Texture2D RenderStaticPreview(string assetPath, Object[] subAssets, int width, int height) {
    3.         Card targetCard = target as Card;
    4.  
    5.         if (targetCard == null || targetCard.image == null || targetCard.image.texture == null)
    6.             return null;
    7.  
    8.         var preview = AssetPreview.GetAssetPreview(targetCard.image.texture);
    9.  
    10.         if (preview == null)
    11.             return null;
    12.  
    13.         Texture2D cache = new Texture2D(width, height);
    14.         EditorUtility.CopySerialized(preview, cache);
    15.  
    16.         return cache;
    17.     }
    Your solution doesn't seem to work, since it's only for c# assets, not .asset scriptable objects.
     
  4. fernandoramallo

    fernandoramallo

    Joined:
    Jan 26, 2014
    Posts:
    4
    For anyone looking for the answer, Democide's solution works but the previews are generated when the asset is *created*. So in that case to fix the missing preview images the assets would need to be saved again.
     
  5. Democide

    Democide

    Joined:
    Jan 29, 2013
    Posts:
    312
    Do you have a fix for that?