This is what I have sofar, and it works, but on a game object with 23 children, only 11 of them get changed.
using UnityEngine;
using System.Collections;
using UnityEditor;
using System.Collections.Generic;
public class CreateHolders : MonoBehaviour {
[MenuItem ("Pluto/Place Holders")]
static void PlaceHolders () {
foreach(GameObject go in Selection.gameObjects){
foreach (Transform child in go.transform) {
if(child.tag == "Wall"){
GameObject tempGo = new GameObject(child.name.Replace("TS001_", "WALL"));
tempGo.tag = "WallHolder";
tempGo.transform.parent = Selection.activeTransform;
DestroyImmediate(child.gameObject);
}
}
}
}
}
EDIT1:
It appears to only do half of the children
First one does 11/23, leaving 12.
Second one does 6/12 leaving 6.
Third time does 3/6 leaving 3.
etc … strange?
EDIT2: I tried unparenting the items I wanted to destroy and not destroying them, and it still only processed 1/2 of the children. Problem doesn’t appear to be with DestroyImmediate().