# GetUniqueObjectName(List<Object>, string)

> Returns a unique name using the provided name as a base, derived from the names of a list of existing objects.

## Definition

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

```csharp
public static string GetUniqueObjectName(List<Object> existingObjects, string name)
```

### Parameters

**** (\[List\<Object>]\(https\://learn.microsoft.com/dotnet/api/system.collections.generic.list-1)): A list of existing objects whose names define the set of already-taken names.**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): Desired name to use as-is, or as a base for a unique name.

### Returns

| Type                                                           | Description                                         |
| -------------------------------------------------------------- | --------------------------------------------------- |
| [string](https://learn.microsoft.com/dotnet/api/system.string) | A name not used by any object in `existingObjects`. |

### Remarks

If the provided name matches the name of any object in `existingObjects`, a unique name is generated by appending the next available numerical increment.

Use this method instead of [ObjectNames.GetUniqueName](/engine/6000.6/script-reference/unityeditor/objectnames/getuniquename.md) when you already hold a `List<Object>` of existing objects. It avoids allocating a temporary string array, making it suitable for allocation-sensitive contexts such as large-hierarchy operations and frequently called Editor tools.

Additional Resources: [ObjectNames.GetUniqueName](/engine/6000.6/script-reference/unityeditor/objectnames/getuniquename.md), [GameObjectUtility.GetUniqueNameForSibling](/engine/6000.6/script-reference/unityeditor/gameobjectutility/getuniquenameforsibling.md), [GameObjectUtility.EnsureUniqueNameForSibling](/engine/6000.6/script-reference/unityeditor/gameobjectutility/ensureuniquenameforsibling.md).

### Examples

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

public class ExampleClass
{
    public void Example()
    {
        // Build a list of objects without extracting their names into a string array.
        var existingObjects = new List<Object>
        {
            new GameObject("Object"),
            new GameObject("Thing"),
            new GameObject("Thing (1)")
        };

        // Displays "Object (1)"
        Debug.Log(ObjectNames.GetUniqueObjectName(existingObjects, "Object"));

        // Displays "Thing (2)"
        Debug.Log(ObjectNames.GetUniqueObjectName(existingObjects, "Thing"));

        // Displays "Other"
        Debug.Log(ObjectNames.GetUniqueObjectName(existingObjects, "Other"));

        foreach (Object obj in existingObjects)
            Object.DestroyImmediate(obj);
    }
}
```
