# CreateItem

> Create a new SearchItem from a value with an optional label.

## Definition

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

## CreateItem(string, Object, string)

Create a new [SearchItem](/engine/6000.7/script-reference/unityeditor/search/searchitem.md) from a value with an optional label.

```csharp
public static SearchItem CreateItem(string label, object value, string description)
```

### Parameters

**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): Optional label of the SearchItem. This will be displayed in the search Window.**** (\[Object]\(https\://learn.microsoft.com/dotnet/api/system.object)): Initial value of the SearchItem.**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): Optional description of the SearchItem. This will be displayed in the search Window.

### Returns

| Type                                                                           | Description               |
| ------------------------------------------------------------------------------ | ------------------------- |
| [SearchItem](/engine/6000.7/script-reference/unityeditor/search/searchitem.md) | Returns a new SearchItem. |

### Examples

```csharp
[Description("Returns asset paths corresponding to a list of instance ids")]
[SearchExpressionEvaluator("IdsToPaths", SearchExpressionEvaluationHints.ThreadNotSupported, SearchExpressionType.Iterable)]
public static IEnumerable<SearchItem> IdsToPath(SearchExpressionContext c)
{
    foreach (var idItem in c.args[0].Execute(c))
    {
        if (SearchExpression.TryConvertToULong(idItem, out var idNum))
        {
            var id = UnsafeUtility.As<ulong, EntityId>(ref idNum);
            var path = AssetDatabase.GetAssetPath(id);
            if (!string.IsNullOrEmpty(path))
            {
                yield return SearchExpression.CreateItem(path, c.ResolveAlias("asset path"));
            }
        }
    }
}
```

## CreateItem(string, string)

Create a new [SearchItem](/engine/6000.7/script-reference/unityeditor/search/searchitem.md) from a value with an optional label.

```csharp
public static SearchItem CreateItem(string value, string label = null)
```

### Parameters

**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): Initial value of the SearchItem.**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): Optional label of the SearchItem. This will be displayed in the search Window.

### Returns

| Type                                                                           | Description               |
| ------------------------------------------------------------------------------ | ------------------------- |
| [SearchItem](/engine/6000.7/script-reference/unityeditor/search/searchitem.md) | Returns a new SearchItem. |

### Examples

```csharp
[Description("Returns asset paths corresponding to a list of instance ids")]
[SearchExpressionEvaluator("IdsToPaths", SearchExpressionEvaluationHints.ThreadNotSupported, SearchExpressionType.Iterable)]
public static IEnumerable<SearchItem> IdsToPath(SearchExpressionContext c)
{
    foreach (var idItem in c.args[0].Execute(c))
    {
        if (SearchExpression.TryConvertToULong(idItem, out var idNum))
        {
            var id = UnsafeUtility.As<ulong, EntityId>(ref idNum);
            var path = AssetDatabase.GetAssetPath(id);
            if (!string.IsNullOrEmpty(path))
            {
                yield return SearchExpression.CreateItem(path, c.ResolveAlias("asset path"));
            }
        }
    }
}
```

## CreateItem(double, string)

Create a new [SearchItem](/engine/6000.7/script-reference/unityeditor/search/searchitem.md) from a value with an optional label.

```csharp
public static SearchItem CreateItem(double value, string label = null)
```

### Parameters

**** (\[double]\(https\://learn.microsoft.com/dotnet/api/system.double)): Initial value of the SearchItem.**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): Optional label of the SearchItem. This will be displayed in the search Window.

### Returns

| Type                                                                           | Description               |
| ------------------------------------------------------------------------------ | ------------------------- |
| [SearchItem](/engine/6000.7/script-reference/unityeditor/search/searchitem.md) | Returns a new SearchItem. |

### Examples

```csharp
[Description("Returns asset paths corresponding to a list of instance ids")]
[SearchExpressionEvaluator("IdsToPaths", SearchExpressionEvaluationHints.ThreadNotSupported, SearchExpressionType.Iterable)]
public static IEnumerable<SearchItem> IdsToPath(SearchExpressionContext c)
{
    foreach (var idItem in c.args[0].Execute(c))
    {
        if (SearchExpression.TryConvertToULong(idItem, out var idNum))
        {
            var id = UnsafeUtility.As<ulong, EntityId>(ref idNum);
            var path = AssetDatabase.GetAssetPath(id);
            if (!string.IsNullOrEmpty(path))
            {
                yield return SearchExpression.CreateItem(path, c.ResolveAlias("asset path"));
            }
        }
    }
}
```

## CreateItem(int, string)

Create a new [SearchItem](/engine/6000.7/script-reference/unityeditor/search/searchitem.md) from a value with an optional label.

```csharp
public static SearchItem CreateItem(int value, string label = null)
```

### Parameters

**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Initial value of the SearchItem.**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): Optional label of the SearchItem. This will be displayed in the search Window.

### Returns

| Type                                                                           | Description               |
| ------------------------------------------------------------------------------ | ------------------------- |
| [SearchItem](/engine/6000.7/script-reference/unityeditor/search/searchitem.md) | Returns a new SearchItem. |

### Examples

```csharp
[Description("Returns asset paths corresponding to a list of instance ids")]
[SearchExpressionEvaluator("IdsToPaths", SearchExpressionEvaluationHints.ThreadNotSupported, SearchExpressionType.Iterable)]
public static IEnumerable<SearchItem> IdsToPath(SearchExpressionContext c)
{
    foreach (var idItem in c.args[0].Execute(c))
    {
        if (SearchExpression.TryConvertToULong(idItem, out var idNum))
        {
            var id = UnsafeUtility.As<ulong, EntityId>(ref idNum);
            var path = AssetDatabase.GetAssetPath(id);
            if (!string.IsNullOrEmpty(path))
            {
                yield return SearchExpression.CreateItem(path, c.ResolveAlias("asset path"));
            }
        }
    }
}
```

## CreateItem(ulong, string)

Create a new [SearchItem](/engine/6000.7/script-reference/unityeditor/search/searchitem.md) from a value with an optional label.

```csharp
public static SearchItem CreateItem(ulong value, string label = null)
```

### Parameters

**** (\[ulong]\(https\://learn.microsoft.com/dotnet/api/system.uint64)): Initial value of the SearchItem.**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): Optional label of the SearchItem. This will be displayed in the search Window.

### Returns

| Type                                                                           | Description               |
| ------------------------------------------------------------------------------ | ------------------------- |
| [SearchItem](/engine/6000.7/script-reference/unityeditor/search/searchitem.md) | Returns a new SearchItem. |

### Examples

```csharp
[Description("Returns asset paths corresponding to a list of instance ids")]
[SearchExpressionEvaluator("IdsToPaths", SearchExpressionEvaluationHints.ThreadNotSupported, SearchExpressionType.Iterable)]
public static IEnumerable<SearchItem> IdsToPath(SearchExpressionContext c)
{
    foreach (var idItem in c.args[0].Execute(c))
    {
        if (SearchExpression.TryConvertToULong(idItem, out var idNum))
        {
            var id = UnsafeUtility.As<ulong, EntityId>(ref idNum);
            var path = AssetDatabase.GetAssetPath(id);
            if (!string.IsNullOrEmpty(path))
            {
                yield return SearchExpression.CreateItem(path, c.ResolveAlias("asset path"));
            }
        }
    }
}
```
