Custom Asset Icons?

So I’m starting to make some custom assets, and I wonder if there’s any way I can give them custom icons to distinguish them, instead of that silly paper-with-bent-corner indicating it’s based on a script. Quite like that little island-with-palm-tree icon that Terrains have.

Anyone know how this might work?

1 Like

I’ve been searching to do the same thing but no luck so far. If I do find out definitavly one way or the other I’ll post here.

Yes, this would be useful. There seems to be two places where custom icons would be useful (both as with the terrain asset)

  • MonoBehaviour scripts when added as components to an object. A different variation of the terrain icon is used. This is nice because it helps emphasize that it is the important component.

EDIT: This can be achieved: Changing the Inspector Titlebar icon, and Text? - Questions & Answers - Unity Discussions

  • Asset File - as mentioned.

how can i set the inspector icon for a MonoBehaviour in a compiled C# plugin?

Same question, did you find any solution?

nope.

It be cool if there was a MonoBehaviour class attribute for compiled .net DLL’s
ex:

[IconTexture( "Assets/MyPlugin/Editor/Resources/kissCamera.png" )]
public class kissCamera : MonoBehaviour
{
//...
}

but this should work too for a compiled dll MonoBehaviour:

2 Likes

I just figured out how to do this. Follow these steps:

  • Turn on Visible Meta Files in both your source code project and your DLL/Assembly project.

  • For a custom MonoBehaviour that you want an icon for, locate the script file in your project and set the icon to a custom icon. E.g. CustomBehaviour.cs.

  • Open your source code project in Explorer (Win) or Finder (Mac) and locate your CustomBehaviour.cs file. Next to it will be a CustomBehaviour.cs.meta file. This is a text file.

  • Open the meta file in your favorite text editor. Make note of the line that reads “icon: {...}”.
    Expanded example of {…} {fileID: 2800000, guid: 6416ff…4830a, type: 3}

  • Open the project with your DLL/Assembly compiled plugin.

  • Locate the meta file associated with the DLL/Assembly that contains your CustomBehaviour class.

  • Find the line that reads “iconMap: {}”.

  • Delete the curly braces next to “iconMap” and add a new line.

  • Enter four spaces to indent below the “iconMap:” line, write the name of your class followed by a colon (“:”), and then copy everything in the curly braces (including the braces) from step 4 above and paste it to the end. It should look like this:

...
  iconMap:
    CustomBehaviour:  {...}
  • If your class is in a namespace, it would look like the following:
...
  iconMap:
    Name.Space.CustomBehaviour:  {...}

If you create a package to export in a project with these modified meta files, those settings will be stored in the exported unitypackage file. This means that they will transfer when imported to a different project, even if that project doesn’t have visible meta files turned on!

I have only tested as early as Unity 4.5.5 and it works partially there (icon appears everywhere but in the “Add Component” menu). This works completely for Unity 4.6+, however.

4 Likes

Sweet.

It be cool if (on Unity 5.0.2) Project View would also read the iconMap… because its not showing the icon there. But the Inspector is reading the iconMap.

ex:

PluginImporter:
  iconMap:
    kissUI.kissLayoutAsset: {fileID: 2800000, guid: 9a76736e44bebbe44b7b32b187275b58, type: 3}

Only way to get this to show the icon in the Project View, is to place it in the Assets/Gizmos folder. :confused:
I was hoping for a way to Avoid having to have a Assets/Gizmos folder with the icons. :confused:
Ohh well. :confused:

Right. The Project folder view does its own thing. My guess is that they use different icons because the size of the icons in the Project View can be much larger when “zoomed in”. It would be really nice to have better, more universal support for icons. As for Custom Assets (ScriptableObject based assets), adding the iconMap setting and having the icon set in Assets/Gizmos seems to work the best. I’ve encountered a situation where the Inspector doesn’t read the icon from Assets/Gizmos (in my case it was drawn with [EditorGUILayout.PropertyField](http://docs.unity3d.com/ScriptReference/EditorGUILayout.PropertyField.html)). Adding the iconMap setting for the asset type solved that issue.

You can have custom previews in the project window for custom ScriptableObject’s.

  • Create a custom ScriptableObject class.
  • Create a custom Editor for the custom ScriptableObject class.
  • Override and implement your custom preview in YourCustomEditor.RenderStaticPreview.
3 Likes

Awesome! Thanks for the heads up on that! It’s good to know that RenderStaticPreview will fall back on the default icon:

Presumably you could add support for your own icon this way and simply always return the icon itself as the Texture2D. That way you might be able to sidestep the Assets/Gizmos trick for the Project view(?). However, you would still need the iconMap trick (or equivalent with raw source files) to get the icon (not custom preview) to show up in the Inspector when used as a property.

Maybe i’m missing something, but you can do this:

(if you chose ‘other’ you can select your own texture),
and it looks like this (if it’s a scriptableObject, assets will have the icon too):

1 Like

The thing you are missing is that you can’t set that icon as you’ve shown there when the script is compiled into an assembly (a DLL). For that you need the steps listed above.

Yes, but that does not work for the Project view. Simply setting that icon will work for Inspector properties but the asset will still show a “default asset icon” in the Project view.

For the first part, yes. But as for the Project view, it works for me:

That is the Script Asset for the ScriptableObject class, not a custom asset file (a serialized instance of your “WorldGrid” class). Serialized instances that you can see in the Project view are what I’m referring to. Like this:
2447849--168039--20140724014803.jpg

The Inspector doesnt give the “Select Icon: Other” Option when you click on the Class that’s part of an Assembly.
ex:

1 Like

@SonicBloomEric , i’m sure that was the behaviour, instance-assets got the icon too (i worked with that on a project, that’s why i wrote that). But i just tested it, and it seems this behaviour was changed in a recent unity version and now it doesn’t display the icon anymore.

If you say so, @Flavelius ! :slight_smile: I’ve tested on Unity 4.5.5, 4.6.9, 5.0.4, 5.1.4, 5.2.4, and 5.3.1 and they have all acted the same way*… :confused:

*Well, Except Unity 4.5! The “iconMap” implementation appears to be disregarded in the “Add Component” menu. This works in Unity 4.6+ (which makes sense because that’s when they started shipping UnityEngine.UI and needed the feature internally, too).

Have a look at the ‘Atoms’ assets, ignore the rest of the project (it’s buggy anyway): http://www.heijulien.de/files/CellProto.zip

And here’s another Idea i just had, based on what you discussed a few posts above. Not sure if it works from within other assemblies or if this even is a practical approach: http://www.heijulien.de/files/AssetIcons.unitypackage