# GetLabels

> Obtains all labels of a given asset.

## Definition

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

## GetLabels(GUID)

Obtains all labels of a given asset.

```csharp
public static string[] GetLabels(GUID guid)
```

### Parameters

**** (GUID): The GUID of the asset object to check without loading the asset into memory.

### Returns

| Type                                                               | Description                                   |
| ------------------------------------------------------------------ | --------------------------------------------- |
| [string\[\]](https://learn.microsoft.com/dotnet/api/system.string) | Returns all labels attached to a given asset. |

### Remarks

The following code checks that every texture in the `Road` folder has a `Road` label, and logs a warning for any asset without the `Road` label.

### Examples

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

static class TextureLabelAudit
{
    [MenuItem("Tools/Audit Texture Labels")]
    static void AuditTextureLabels()
    {
        string[] searchFolders = new string[] { "Assets/Textures/Road" };
        GUID[] guids =
            AssetDatabase.FindAssetGUIDs("t:Texture2D", searchFolders);

        foreach (GUID guid in guids)
        {
            // GetLabels reads the label list from the asset database, so
            // the texture is never loaded into memory.
            string[] labels = AssetDatabase.GetLabels(guid);

            if (!labels.Contains("Road"))
            {
                string path = AssetDatabase.GUIDToAssetPath(guid);
                Debug.LogWarning($"{path} has no \"Road\" label.");
            }
        }
    }
}
```

## GetLabels(Object)

Obtains all labels of a given asset.

```csharp
public static string[] GetLabels(Object obj)
```

### Parameters

**** (\[Object]\(/engine/6000.7/script-reference/unityengine/object)): The asset object to check.

### Returns

| Type                                                               | Description                                   |
| ------------------------------------------------------------------ | --------------------------------------------- |
| [string\[\]](https://learn.microsoft.com/dotnet/api/system.string) | Returns all labels attached to a given asset. |

### Remarks

The following code checks that every texture in the `Road` folder has a `Road` label, and logs a warning for any asset without the `Road` label:

### Examples

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

static class RoadTextureLabelAudit
{
    [MenuItem("Tools/Audit Road Texture Labels")]
    static void AuditRoadTextureLabels()
    {
        // This example assumes the project contains ten road textures
        // named Road0 to Road9.
        for (int i = 0; i < 10; i++)
        {
            string texturePath = $"Assets/Textures/Road/Road{i}.png";
            Object asset = AssetDatabase.LoadMainAssetAtPath(texturePath);

            if (asset == null)
            {
                Debug.LogWarning($"No asset found at \"{texturePath}\".");
                continue;
            }

            string[] labels = AssetDatabase.GetLabels(asset);

            if (!labels.Contains("Road"))
            {
                Debug.LogWarning(
                    $"\"{texturePath}\" has no \"Road\" label.");
            }
        }
    }
}
```
