Version: 2019.3
public static string GetUniqueNameForSibling (Transform parent, string name);

パラメーター

parent新しい GameObject のターゲットの親。 null はルートレベルを意味します。
name新しい GameObject のために名前をリクエストします

戻り値

string 新しい GameObject のためにユニークな名前をリクエストします

説明

You can use this method before instantiating a new sibling, or before parenting one GameObject to another, to ensure the new child GameObject has a unique name compared to its siblings in the hierarchy.

To use this method, you must provide a "target parent", and a "requested name". The method uses an incremental numeric suffix appended to the name to avoid duplicate names.

If the target parent that you specify does not already have a child with the requested name that you specify, the method will return the requested name. If the target parent does have a child object matching the requested name, the method will add an incremental number after the requested name until it finds one that is unique. This is useful when trying to avoid duplicate naming.

Note: You should use this method before the GameObject becomes a child of the target parent. If you use this method after the GameObject is already a child of the target parent, it will detect its own name among the siblings as a conflict! If you want to perform the check after the GameObject is a child of the target parent, you can use GameObjectUtility.EnsureUniqueNameForSibling instead.

See Also: GameObjectUtility.EnsureUniqueNameForSibling, ObjectNames.GetUniqueName.