I’m creating a custom editor window where I want to list all Objects in the current scene that has a WayPoint script attached to them. I need all Objects in this list to have unique names because I later want to use GameObject.Find(object.name) to make a reference to each GameObject.
Here is my code:
void Example() {
// Find all objects with Waypoint script
Object[] objectArray = Resources.FindObjectsOfTypeAll(typeof(WayPoint));
// A list with all duplicate names
List<Object> duplicateNames = objectArray.GroupBy(s => s.name)
.SelectMany(grp => grp.Skip(1).ToList()).ToList();
// Renaming
for(int i = 0; i < duplicateNames.Count; i++) {
duplicateNames_.name = duplicateNames*.name + (i + 1);*_
* }*
* }*
This works fine for regular gameobjects, but with prefabs i seems like I’m changing the name of the prefab asset rather than the name of the prefab instance in the scene. So for each iteration of the for loop I am renaming all instances of that prefab.
Is there a way to rename the instance of the prefab rather than the prefab itself?