Created
June 17, 2024 16:12
-
-
Save philippgitpush/2af906ba0d590883212377e499d2678e to your computer and use it in GitHub Desktop.
Unity editor script to bulk rename the children of a given gameobject
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using UnityEditor; | |
public class RenameChildren : EditorWindow { | |
private static readonly Vector2Int size = new Vector2Int(250, 100); | |
private string childrenPrefix; | |
private int startIndex = 0; | |
[MenuItem("GameObject/Rename children")] public static void ShowWindow() { | |
EditorWindow window = GetWindow<RenameChildren>(); | |
window.minSize = size; | |
window.maxSize = size; | |
} | |
private void OnGUI() { | |
childrenPrefix = EditorGUILayout.TextField("Children prefix", childrenPrefix); | |
if (GUILayout.Button("Rename children")) { | |
GameObject[] selectedObjects = Selection.gameObjects; | |
for (int objectI = 0; objectI < selectedObjects.Length; objectI++) { | |
Transform selectedObjectT = selectedObjects[objectI].transform; | |
for (int childI = 0, i = startIndex; childI < selectedObjectT.childCount; childI++) selectedObjectT.GetChild(childI).name = $"{childrenPrefix}{selectedObjectT.GetChild(childI).name}"; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment