# SearchAction

> Defines an action that can be applied on a SearchItem of a specific search provider type.

## Definition

* **Type:** Class
* **Namespace:** [UnityEditor.Search](/engine/6000.7/script-reference/unityeditor/search.md)
* **Assembly:** UnityEditor

```csharp
public class SearchAction
```

## Examples

```csharp
using System.Collections.Generic;
using UnityEditor;
using UnityEditor.Search;
using UnityEngine;
using UnityEngine.Rendering;

public class Example_SearchAction
{
    [SearchActionsProvider]
    internal static IEnumerable<SearchAction> ActionHandlers()
    {
        return new[]
        {
            #region SingleItemAction
            new SearchAction("asset", "print_dependencies", new GUIContent("Print Dependencies", null, "Print all dependencies of an asset."))
            {
                // If this action is the default, double-clicking on an item to execute this action will not close the Search window.
                closeWindowAfterExecution = false,

                // Handler for a single item.
                handler = (item) =>
                {
                    var asset = item.ToObject();
                    if (!asset)
                        return;
                    var path = AssetDatabase.GetAssetPath(asset);
                    if (string.IsNullOrEmpty(path))
                        return;

                    var dependencyPaths = AssetDatabase.GetDependencies(path);
                    foreach (var dependencyPath in dependencyPaths)
                    {
                        var o = AssetDatabase.LoadAssetAtPath<UnityEngine.Object>(dependencyPath);
                        if (o != null)
                            Debug.Log(dependencyPath, o);
                    }
                }
            },
            #endregion

            #region MultiItemsAction
            new SearchAction("scene", "toggle_cast_shadows", new GUIContent("Toggle Cast Shadows", null, "Toggle Cast Shadows on a Mesh"))
            {
                // Only enable this action if any of the selected items are actually a GameObject with a MeshRenderer.
                enabled = items =>
                {
                    foreach (var searchItem in items)
                    {
                        var go = searchItem.ToObject<GameObject>();
                        if (!go)
                            continue;
                        var mesh = go.GetComponent<MeshRenderer>();
                        if (mesh)
                            return true;
                    }
                    return false;
                },
                // Handler for multiple items: (used when multi selection is used in the Search Window).
                execute = (items) =>
                {
                    foreach (var searchItem in items)
                    {
                        var go = searchItem.ToObject<GameObject>();
                        if (!go)
                            continue;
                        var mesh = go.GetComponent<MeshRenderer>();
                        if (!mesh)
                            continue;
                        mesh.shadowCastingMode = mesh.shadowCastingMode == ShadowCastingMode.Off ? ShadowCastingMode.On : ShadowCastingMode.Off;
                    }
                }
            },
            #endregion
        };
    }
}
```

## Fields

| Value                                                                                                                     | Description                                                                   |
| ------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------- |
| [closeWindowAfterExecution](/engine/6000.7/script-reference/unityeditor/search/searchaction/closewindowafterexecution.md) | Indicates if the search view should be closed after the action execution.     |
| [content](/engine/6000.7/script-reference/unityeditor/search/searchaction/content.md)                                     | GUI content of the search action used when displayed with an icon.            |
| [enabled](/engine/6000.7/script-reference/unityeditor/search/searchaction/enabled.md)                                     | Callback used to check if the action is enabled based on the current context. |
| [execute](/engine/6000.7/script-reference/unityeditor/search/searchaction/execute.md)                                     | Executes an action on a set of items.                                         |
| [handler](/engine/6000.7/script-reference/unityeditor/search/searchaction/handler.md)                                     | This handler is used for actions that do not support multi-selection.         |

## Constructors

| Constructor                                                                                                                                                                                                                                                                | Description                                   |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------- |
| [SearchAction(System.String,System.String,UnityEngine.GUIContent)](/engine/6000.7/script-reference/unityeditor/search/searchaction/ctor.md#searchaction\(string-string-guicontent\))                                                                                       | Default constructor to build a search action. |
| [SearchAction(System.String,System.String,UnityEngine.GUIContent,System.Action\{UnityEditor.Search.SearchItem\[\]})](/engine/6000.7/script-reference/unityeditor/search/searchaction/ctor.md#searchaction\(string-string-guicontent-actionsearchitem\))                    | Default constructor to build a search action. |
| [SearchAction(System.String,System.String,UnityEngine.GUIContent,System.Action\{UnityEditor.Search.SearchItem})](/engine/6000.7/script-reference/unityeditor/search/searchaction/ctor.md#searchaction\(string-string-guicontent-actionsearchitem\))                        | Default constructor to build a search action. |
| [SearchAction(System.String,System.String,UnityEngine.Texture2D,System.String)](/engine/6000.7/script-reference/unityeditor/search/searchaction/ctor.md#searchaction\(string-string-texture2d-string\))                                                                    | Default constructor to build a search action. |
| [SearchAction(System.String,System.String,UnityEngine.Texture2D,System.String,System.Action\{UnityEditor.Search.SearchItem\[\]})](/engine/6000.7/script-reference/unityeditor/search/searchaction/ctor.md#searchaction\(string-string-texture2d-string-actionsearchitem\)) | Default constructor to build a search action. |
| [SearchAction(System.String,System.String,UnityEngine.Texture2D,System.String,System.Action\{UnityEditor.Search.SearchItem})](/engine/6000.7/script-reference/unityeditor/search/searchaction/ctor.md#searchaction\(string-string-texture2d-string-actionsearchitem\))     | Default constructor to build a search action. |

## Properties

| Property                                                                                      | Description                         |
| --------------------------------------------------------------------------------------------- | ----------------------------------- |
| [displayName](/engine/6000.7/script-reference/unityeditor/search/searchaction/displayname.md) | Display name for the search action. |
| [id](/engine/6000.7/script-reference/unityeditor/search/searchaction/id.md)                   | Action unique identifier.           |
