[ Web Proxy ]
URL:
Viewing: https://docs.unity3d.com/ScriptReference/ObjectNames.GetUniqueName.html [Back]  [Original]

Unity - Scripting API: ObjectNames.GetUniqueName
Version: Unity 6.5 (6000.5)
    • Supported
    • Legacy
    LanguageEnglish
    • C#

    ObjectNames.GetUniqueName

    Suggest a change

    Success!

    Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

    Close

    Submission failed

    For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

    Close
    Your name Your email Suggestion* Submit suggestion

    Cancel

    Declaration

    public static string GetUniqueName(string[] existingNames, string name);

    Parameters

    Parameter Description
    existingNames A list of pre-existing names.
    name Desired name to be used as is, or as a base.

    Returns

    string A name not found in the list of pre-existing names.

    Description

    Make a unique name using the provided name as a base.

    If the target name is in the provided list of existing names, a unique name is generated by appending the next available numerical increment.

    using UnityEngine;
    using UnityEditor;

    public class ExampleClass { public void Example() { string[] names = new string[] { "Object", "Thing", "Thing (1)" };

    // will display "Object (1)" Debug.Log(ObjectNames.GetUniqueName(names, "Object"));

    // will display "Thing (2)" Debug.Log(ObjectNames.GetUniqueName(names, "Thing"));

    // will display "Other" Debug.Log(ObjectNames.GetUniqueName(names, "Other")); } }

    Web Proxy Viewer  |  New URL  |  Original Page