# SetIconForObject(Object, Texture2D)

> Sets a custom icon to associate with a GameObject or MonoScript. The custom icon is displayed in the Scene view and the Inspector.

## Definition

* **Type:** Method
* **Namespace:** [UnityEditor](/engine/6000.6/script-reference/unityeditor.md)
* **Assembly:** UnityEditor.CoreModule

```csharp
public static void SetIconForObject(Object obj, Texture2D icon)
```

### Parameters

**** (\[Object]\(/engine/6000.6/script-reference/unityengine/object)): The [GameObject](/engine/6000.6/script-reference/unityengine/gameobject.md) or [MonoScript](/engine/6000.6/script-reference/unityeditor/monoscript.md) to associate the icon with.**** (\[Texture2D]\(/engine/6000.6/script-reference/unityengine/texture2d)): The custom icon to associate with the [GameObject](/engine/6000.6/script-reference/unityengine/gameobject.md) or [MonoScript](/engine/6000.6/script-reference/unityeditor/monoscript.md). When this value is null, the default icon is restored.

### Remarks

Custom icons for [GameObjects](/engine/6000.6/manual/working-with-gameobjects/game-objects.md) are saved in the scene.

```csharp
using UnityEngine;
using UnityEditor;

class Example
{
    [MenuItem("Examples/Set Custom Icon on GameObject")]
    public static void SetCustomIconOnGameObject()
    {
        var go = new GameObject();
        var icon = AssetDatabase.LoadAssetAtPath<Texture2D>("Assets/MyIcon.png");

        EditorGUIUtility.SetIconForObject(go, icon);
    }
}
```

Using this function, you can set custom icons directly on a [MonoScript](/engine/6000.6/script-reference/unityeditor/monoscript.md). However the next time the script is reimported, the change will be lost.

To make the custom icon persistent, call [MonoImporter.SetIcon](/engine/6000.6/script-reference/unityeditor/monoimporter/seticon.md) and [AssetImporter.SaveAndReimport()](/engine/6000.6/script-reference/unityeditor/assetimporter/saveandreimport.md). If the script is in a managed plugin, call [PluginImporter.SetIcon](/engine/6000.6/script-reference/unityeditor/pluginimporter/seticon.md) instead of [MonoImporter.SetIcon](/engine/6000.6/script-reference/unityeditor/monoimporter/seticon.md).

```csharp
using UnityEngine;
using UnityEditor;

class Example
{
    [MenuItem("Examples/Set Custom Icon on MonoScript")]
    public static void SetCustomIconOnMonoScript()
    {
        var monoImporter = AssetImporter.GetAtPath("Assets/MyMonoBehaviour.cs") as MonoImporter;
        var monoScript = monoImporter.GetScript();
        var icon = AssetDatabase.LoadAssetAtPath<Texture2D>("Assets/MyIcon.png");

        EditorGUIUtility.SetIconForObject(monoScript, icon);

        // make the custom icon persistent
        monoImporter.SetIcon(icon);
        monoImporter.SaveAndReimport();
    }
}
```

When you set custom icons from a GUI, it is recommended that you defer reimport until the GUI is closed. If you reimport before the GUI is closed, the domain reload caused by recompiling the script could lead to a poor user experience.

Additional Resources: [MonoImporter](/engine/6000.6/script-reference/unityeditor/monoimporter.md), [PluginImporter](/engine/6000.6/script-reference/unityeditor/pluginimporter.md).
