# SetLabels(Object, string[])

> Replaces the list of labels on an asset.

## Definition

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

```csharp
public static void SetLabels(Object obj, string[] labels)
```

### Parameters

**** (\[Object]\(/engine/6000.0/script-reference/unityengine/object)): The asset object.**** (\[string\[]]\(https\://learn.microsoft.com/dotnet/api/system.string)): An array of labels.

### Remarks

`SetLabels(obj, null)` is safe and is equivalent to clearing the labels.

Don't set labels between calls to [AssetDatabase.StartAssetEditing](/engine/6000.0/script-reference/unityeditor/assetdatabase/startassetediting.md) and [AssetDatabase.StopAssetEditing](/engine/6000.0/script-reference/unityeditor/assetdatabase/stopassetediting.md). Labels are only visible to [AssetDatabase.GetLabels](/engine/6000.0/script-reference/unityeditor/assetdatabase/getlabels.md) after [AssetDatabase.StopAssetEditing](/engine/6000.0/script-reference/unityeditor/assetdatabase/stopassetediting.md) is called.

The following example adds the `Vegetation` label to the assets selected in the **Project** window:

### Examples

```csharp
using System.Linq;
using UnityEditor;
using UnityEngine;

static class VegetationLabeler
{
    [MenuItem("Tools/Add Vegetation Label")]
    static void AddVegetationLabelToSelection()
    {
        foreach (string guid in Selection.assetGUIDs)
        {
            string path = AssetDatabase.GUIDToAssetPath(guid);
            Object asset = AssetDatabase.LoadMainAssetAtPath(path);
            string[] currentLabels = AssetDatabase.GetLabels(asset);

            if (currentLabels.Contains("Vegetation"))
            {
                continue;
            }

            // SetLabels replaces the whole list, so append to the labels
            // the asset already has.
            AssetDatabase.SetLabels(
                asset, currentLabels.Append("Vegetation").ToArray());
        }
    }
}
```
