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. Dismiss Notice

How to set icon for custom assets imported via ScriptedImporter?

Discussion in 'Editor & General Support' started by Xarbrough, Nov 15, 2019.

  1. Xarbrough

    Xarbrough

    Joined:
    Dec 11, 2014
    Posts:
    1,184
    I have a custom file extension "myExt" and import files of that type via a ScriptedImporter. In the Unity project window, these files are displayes as blank white icons. Can I somehow assign a new icon for my custom file type?
     
  2. Xarbrough

    Xarbrough

    Joined:
    Dec 11, 2014
    Posts:
    1,184
    So I've spent some time experimenting and found:

    1) If I assign an icon to the ScriptedImporter class in the inspector or its editor class or place a file named "MyScriptedImporter Icon.png" in the Gizmos folder, the importer script itself stores the icon as it would work with MonoBehaviour classes. However, this icon does not show on the imported asset of my custom file type.
    2) If I add any UnityEngine.Object sub-assets to my imported asset, I can manually load and pass an icon file. However, this is slightly weird, since in my case, for example, I don't actually have any objects creates, its just a text file and when I add the icon as a Texture2D object, the imported asset is treated like a texture (Texture2D icon showing) which is not what I want.
    3) I tried rendering a static preview via the ScriptedImporterEditor, but the callback was simply never invoked. I've previously used this on regular custom editor code applied to ScriptableObject assets where it worked, but with ScriptedImporter it might be not implemented or I'm missing something else. The editor also has a flag for useAssetDrawPreview which I set to false and HasPreviewGUI set to true, but the DrawPreview callback was not invoked.

    So it looks as if there is currently no way of simply assigning an icon for a custom file without any workarounds.
     
  3. _slash_

    _slash_

    Joined:
    Mar 26, 2013
    Posts:
    37
    Bump, I have exactly the same issue and I've tried the exact same steps.

    Why is RenderStaticPreview never called on ScriptedImporterEditor?