Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by frarees · Jan 03, 2014 at 05:19 PM · editorassemblyicongizmo

Custom script icon by code inside assembly

I'm trying to change the icon shown on inspector/project view for custom types derived of MonoBehaviour. I have those types inside a compiled assembly (i.e. MyAssembly.MyScript).

I've managed to load a custom icon by placing it at the following path Gizmos/MyScript Icon.png. But I don't want the icons to be there, as I'm embedding them into the assembly (they are base64'd on code, so I load them at recompilation). Any hint on how to load them properly? Or even an explanation on how Unity load those? I've been digging the assemblies for a while and the closest I've got is AssetPreview.GetMiniThumbnail (obj), which is defined on unmanaged-code land (i.e. C++), and only gives me the image but doesn't let me change it.

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image mhtraylor · Jan 04, 2014 at 03:38 AM 0
Share

Have you tried EditorGUIUtility.ObjectContent? I seem to recall using this, it's been a while so I'll try a few tests and see.

avatar image frarees · Jan 04, 2014 at 06:04 PM 0
Share

I've tried but it seems it holds the returning GUIContent as a cached copy inside EditorGUIUtility, so no way to change the icon reference.

1 Reply

· Add your reply
  • Sort: 
avatar image
3

Answer by Wortex17 · Feb 25, 2016 at 08:38 AM

You can change them either via the editor or via manipulating the meta files yourself (go for the later if there are a lot of scripts in your assembly). To show the differences, I will explain the process for assembly scripts as well as non-assembly scripts.

Non assembly scripts

The usual way to change a scripts icon is by selecting the script in the project view to see it in the inspector. On the top left is the default script icon with a dropdown indicator. Click on that to get various options as well as the option to select a custom image, which does not have to reside in any special directory.

Changing script icon in editor

This changes the meta file to reflect the new icon as such:

 fileFormatVersion: 2
 guid: 6543a02a4c6aac747a980a5d43f0b13b
 ...
 MonoImporter:
   serializedVersion: 2
   ...
   icon: {fileID: 2800000, guid: 659304581cc9f3c4aa2a7f1942ceac20, type: 3}

Notice the icon: entry.

Assembly scripts

Scripts inside an assembly can be viewed in the project view and inspector too, but, for some reason, do not have that dropdown. This makes sense, as scripts from assembly do not have their own meta files.

But the assembly itself does!

A trick to change the icon via the editor is by opening the the "Gizmo" dropdown. For the script to even appear there it must either already have a custom icon or have an OnDrawGizmos() method. If it doesn't, you may just add an emtpy OnDrawGizmos() method temporarily (and remove it after you have set an icon as it will appear from there on anyway). There is a little dropwdown next to your script which gives you the exact same menu to change the icon (and it works flawlessly). Unity may get stuck a little after changing it, as it reimports the meta data about the whole assembly.

Trick changing assembly script icon via the gizmo list

The changes are reflected in the assemblys meta file as such:

 fileFormatVersion: 2
 guid: c5e7423a261e0bb41b66c0570cb04b0a
 ...
 PluginImporter:
   serializedVersion: 1
   iconMap:
     Fully.Qualified.Name.Track: {fileID: 2800000, guid: 659304581cc9f3c4aa2a7f1942ceac20,
       type: 3}
   executionOrder:
     FirstScene: -32000

Notice the iconMap: section. Each entry has as key the fully qualified name of the class (its namespaces, containing classes' names and its own class name, just like you would import it) and as value the reference to the asset you want to use (which can be found easily with existing asset database and editor classes form unity)


script-icon-assembly-gizmo.png (95.3 kB)
script-icon-normal-changed.png (25.6 kB)
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

20 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Custom Asset Icons? 2 Answers

Handles.matrix seems strange? 2 Answers

Using the arrows of UnityEditor.UI for own inspectors 1 Answer

C# dll "MissingMethodException" - Before first recompile 1 Answer

Why does this function, when called from OnDrawGizmosSelected, produce a different result and kill the editor? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges