I’m new to Unity and have been asked to look into writing a script to identify any duplicate names of any items in the scene(mostly meshes but would be nice to look at all objects) and either auto-rename or give user ability to rename.
Are there any good examples out there or even starting points to look at?
thanks,
Morris Olmsted
You can write an editor script that does this but it sounds like a lot of fiddly work for something one would rarely need to do.
Keep in mind some names are stored in the scene files, some are derived from prefabs referenced in there and possibly modified by prefab overrides, and still other names are in individual assets. Most asset names are (somewhat) maintained in synchrony with filesystem names, which must ALWAYS be maintained in precise synchrony with the meta files. Other asset names are actually stored in the meta files (such as multi-cut sprites). And still other names are hard-bound to the original source asset, such as mesh names that come from FBX files, so if you rename them the import will likely break, or if you’re lucky, it might get renamed back the way it was originally in the external file.
If you want to get an idea of what you’re up against, the easiest is to write an editor script to rename something in the scene and mark the scene dirty so that it can be saved.
Once you grasp that, try your hand at renaming an asset on disk.
Once you have that, try finding that asset by traversing serializable properties in the scene.
Yuck.