# Menu Icons

While we can't really add our own icons on the fly as easily, something we can do somewhat easily is use the existing Slate Icons!

## Finding Icons To Use

To browse available icons, I recommend thee Slate Style Browser plugin available on FAB:

{% embed url="<https://www.fab.com/listings/04eb0964-3152-412f-85be-fdbfbda56425>" %}

We can launch this plugin's tool from the `Tools` dropdown menu:

<figure><img src="/files/ebrq4HBUIDg76OdsioCw" alt="" width="230"><figcaption></figcaption></figure>

The Slate Style Browse allows us to quickly scan through all available Slate Icons, providing the exact information we need for our Python menu classes:

<figure><img src="/files/2xmea5pkRw3Q74AH0AZA" alt=""><figcaption></figcaption></figure>

## Adding Icons in our Menu Class

The key thing we want to add to our class' init is the following line:

```python
self.data.icon = unreal.ScriptSlateIcon(
    "<Style Set>", 
    "<Property Name>"
)
```

That's all there is to it! Just find a Slate Icon we like and copy its Style Set and Property Name

Using the Details Button icon as an example, here's what our class now looks like:

```python
@unreal.uclass()
class PythonMenuTool(unreal.ToolMenuEntryScript):
    name = "icon_menu"
    label = "Menu Class w/ Icon"
    tool_tip = "tool tip!"

    def __init__(self, menu, section=""):
        """Initialize our entry for the given menu_object's section"""
        super().__init__()

        # Initialize the entry data
        self.init_entry(
            owner_name="custom_owner",
            menu=menu.menu_name,
            section=section,
            name=self.name,
            label=self.label,
            tool_tip=self.tool_tip
        )
        
        # Set the icon!
        self.data.icon = unreal.ScriptSlateIcon(
            "EditorStyle", 
            "WorldBrowser.DetailsButtonBrush"
        )

        menu.add_menu_entry_object(self)
```

And now our menu class has an icon:

<figure><img src="/files/mgUeTlxFw9tBf0x6tOLn" alt="" width="204"><figcaption></figcaption></figure>

## Dynamic Icon

We can also make it dynamic, too!

```python
    @unreal.ufunction(override=True)
    def get_icon(self, context):
        """determine the icon to display"""
        is_ctrl_down = unreal.InputLibrary.modifier_keys_state_is_control_down(
            unreal.InputLibrary.get_modifier_keys_state()
        )
        active_icon = unreal.ScriptSlateIcon(
            "EditorStyle",
            "SourceControl.StatusIcon.On"
        )
        inactive_icon = unreal.ScriptSlateIcon(
            "EditorStyle",
            "SourceControl.StatusIcon.Error"
        )
        return active_icon if is_ctrl_down else inactive_icon
```

{% hint style="danger" %} <mark style="color:yellow;">Note</mark>: The Icon does not refresh on Tick like the Label does, most menus only call this function once when the menu list is displayed
{% endhint %}

<figure><img src="/files/oRcryxrXyWYQFxzUekE6" alt="" width="257"><figcaption></figcaption></figure>

## Full Class Code

```python
@unreal.uclass()
class PythonMenuTool(unreal.ToolMenuEntryScript):
    name = "icon_menu"
    label = "Menu Class w/ Icon"
    tool_tip = "tool tip!"

    def __init__(self, menu, section=""):
        """Initialize our entry for the given menu_object's section"""
        super().__init__()

        # Initialize the entry data
        self.init_entry(
            owner_name="custom_owner",
            menu=menu.menu_name,
            section=section,
            name=self.name,
            label=self.label,
            tool_tip=self.tool_tip
        )
        self.data.icon = unreal.ScriptSlateIcon(
            "EditorStyle", 
            "WorldBrowser.DetailsButtonBrush"
        )

        menu.add_menu_entry_object(self)

    @unreal.ufunction(override=True)
    def get_icon(self, context):
        """The Python code to execute when pressed"""
        is_ctrl_down = unreal.InputLibrary.modifier_keys_state_is_control_down(
            unreal.InputLibrary.get_modifier_keys_state()
        )
        active_icon = unreal.ScriptSlateIcon(
            "EditorStyle",
            "SourceControl.StatusIcon.On"
        )
        inactive_icon = unreal.ScriptSlateIcon(
            "EditorStyle",
            "SourceControl.StatusIcon.Error"
        )
        return active_icon if is_ctrl_down else inactive_icon

```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://bkortbus.gitbook.io/unreal-python-recipe-book/editor-menus/python-menu-class/menu-icons.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
