Search Unity

  1. Looking for a job or to hire someone for a project? Check out the re-opened job forums.
    Dismiss Notice
  2. Unity 2020 LTS & Unity 2021.1 have been released.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Custom script icons not saving [solved]

Discussion in 'Scripting' started by Xarbrough, Mar 10, 2016.

  1. Xarbrough

    Xarbrough

    Joined:
    Dec 11, 2014
    Posts:
    990
    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!
     
  2. Xarbrough

    Xarbrough

    Joined:
    Dec 11, 2014
    Posts:
    990
    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.
     
  3. MischaWeerwag

    MischaWeerwag

    Joined:
    Jul 4, 2014
    Posts:
    9
    This needs to be the top google result!
     
  4. Michael-Ryan

    Michael-Ryan

    Joined:
    Apr 10, 2009
    Posts:
    171
    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 "<className> 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: https://stackoverflow.com/questions...te-a-script-icon-in-unity3d/65270129#65270129

    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.
     
unityunity