I know this question has been asked before and often there were no answers or people saying that this feature is not officially working, but now I’ve found a product from the asset store (Chronos), which has custom icons on there scripts/components.
Does anybody know how to achieve this?
I have my icons stored in the Gizmos folder as Editor/Legacy GUI and I can drag them into the icon field of a script file, when I put the inspector into debug mode. It works for the current session. The script file and all components show the correct icon, but as soon as I restart Unity, the references are lost; none of my icons are saved. So how does Chronos do it then? I thought about that they maybe load the icons and assign them everytime the editor loads in code, but I can’t find any references to those files other than that they are set in the icon field of the script assets.
Thanks!
Ignore me…I’ve been looking for this for such a long time now, but it was too obvious and somehow my google results always returned people saying, that it doesn’t work. Anyway, so simple:
- Select the asset (script file) in the project panel.
- Click the dropdown arrow of the big icon on the inspector top left (don’t go into debug mode to change the icon).
- Choose Other… and save the project.
My problem was that I’ve been trying to drag the image file into the icon field in the debug inspector, but that way it won’t be saved to disk apparently.
8 Likes
This needs to be the top google result!
4 Likes
There’s another solution that is somewhat more automated.
My understanding is for each MonoBehaviour in your assembly, Unity looks for an associated icon image with the name “ Icon” under the “Gizmos” folder, but the folder hierarchy must match the namespace.
So if your MonoBehavior is TestClass
and its namespace is Company.Project.Foo
, you should image name the image “TestClass Icon.png”, and place it in your project at “Assets/Gizmos/Company/Project/Foo/”.
I know PNG image files work. Other image types may be supported, however when I tested with a PSD image, the gizmo wouldn’t show up. Be sure to set the Texture Type to “Editor GUI and Legacy GUI” on the texture import settings.
It’s documented with screenshots on Stack Overflow here: c# - How to create a script icon in Unity3D? - Stack Overflow
The downside to this solution is that you must use a strict file naming convention and put it in the proper spot. If you rename your class or change its namespace, the image will also have to be renamed or relocated. Personally, I prefer this over manually mapping the icon to the script using its meta file, but your mileage may vary.