Skip to content

Instantly share code, notes, and snippets.

@philippgitpush
Created June 17, 2024 16:12
Show Gist options
  • Save philippgitpush/2af906ba0d590883212377e499d2678e to your computer and use it in GitHub Desktop.
Save philippgitpush/2af906ba0d590883212377e499d2678e to your computer and use it in GitHub Desktop.
Unity editor script to bulk rename the children of a given gameobject
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