Creating an icon for a custom class in editor "Create Node Menu"

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By frankiezafe

Hello,

I’m currently working on the look&feel of this extension: GitHub - djiamnot/gdosc: OSC module for Godot game engine - it is now discontinued in favor of https://gitlab.com/frankiezafe/gdosc.

Is there an “official” procedure to add an icon to the editor for a custom module, without modifying the editor itself?

For the moment, i found a way to do so:

  • create an icon_[my custom class].svg in the folder “editor/icons” (requires the source of the engine)
  • recompile the engine
  • restart the engine: if the naming is correct, icon should be displayed in the menu

Naming convention seems to be: suffix any capital with an “_” character. For the class i’m working on, named OSCtransmitter, the filename must be:

  • icon_ (prefix)
  • o_s_ctransmitter > o_O, s_S & ctransmitterCtransmitter,
  • .png (extension…)

The result is cool, but i’m certan it is not the right way of doing… Any advice or example would be welcomed :slight_smile:

:bust_in_silhouette: Reply From: Pieter-Jan Briers

Doubt there’s a proper way to do this: in the main engine, even the visual script module just has them in editor/icons and I can’t see any “proper” way. It just pulls it from the editor icons theme type. So since you’re making a full blown module instead of using say GDNative (on that note, unless GDNative is too restrictive for your module, using it might be better than a regular module), editor/icons is probably the best way.

If you want to hack it (arguably harder) you could try getting a hold of the editor theme and setting an icon override for the whole editor with Theme.set_icon("OSCtransmitter", "EditorIcons", texture) but keep in mind you’ll have to export the SVG manually (the SVGs are exported in Godot’s build process, which won’t work if you go this way).

PS: when making a regular plugin with GDNative/GDScript/etc the icon is added in the EditorPlugin::add_custom_type call as documented here.

Thanks for the response, the GDNative approach seems much cleaner than the hacker way :slight_smile: - I will certainly try this.

frankiezafe | 2018-03-20 06:37

:bust_in_silhouette: Reply From: luislodosm

To set a custom icon of a custom class:

extends Node
class_name MyClass, "res://icons/my_class_icon.svg"
:bust_in_silhouette: Reply From: Gatada

For Godot 4, the format for adding an icon is thankfully more self-documenting:

@icon("res://path/to/optional/icon.svg")

About registering named classes with custom icons:
GDScript reference — Godot Engine (latest) documentation in English(#registering-named-classes

Details about creating the icons themselves:
Editor icons — Godot Engine (latest) documentation in English(#creating-icons

1 Like