If a prefab instance in the scene is renamed, either by the user or automatically by duplicating the prefab in the scene, the name connection to the original prefab is automatically broken beyond repair, right clicking the name doesn’t show a “Revert value to prefab” option, this makes it impossible to keep the original name since duplicating a prefab is the fastest way to work, now i want to rename some prefabs but renaming the master prefab won’t change most of the prefabs in my scenes, I’d have to rename a thousands prefabs individually one by one if I ever wanted to change the prefab’s name, is there no way to reset all instances to the original prefab name?
In short:
I want to rename all the prefab instances in my project by renaming the original prefab, which doesn’t work on duplicated (or renamed) prefabs in the scene. I’d like to either prevent, or fix the broken name link.
If you want to revert the names of prefab instances to the name of the prefab itself you can use this little tool i just created: PrefabNameRevert.
Just select one or more prefab instances and select “RevertName” in the “Prefab” menu.
Note that i removed my original script and replaced it with a much more simpler one.
I wonder why the Editor doesn’t let you do this through the Inspector. Every other game object property (that I am aware of) can be considered an “override” and inherits from the prefab and can be reverted. And you are allowed to name two or more objects in the scene at the same level of hierarchy the same thing…
Is the problem that users are more likely to want uniquely named objects, so doing “Apply All” on a prefab instance could ruin the naming in a whole scene? If that is the reason, it would be nice to have an option to “lock or unlock” certain properties for Overriding and Reversion.
Current solution is no longer valid. PrefabUtility.GetPrefabParent
is obsolete and SelectionMode.OnlyUserModifiable
is deprecated. The current solution also has no validation and doesn’t integrate into the existing menus.
Here is a updated one: PrefabNameReverter.cs
I’ve made these changes from the original:
- Use modern versions of deprecated
PrefabUtility.GetPrefabParent
and SelectionMode.OnlyUserModifiable
methods.
- Integrate with existing menus such as right click prefab context menu.
- Add validation before processing anything.
- Add a namespace and preprocessor directive to only compile on editor.
- Add documentation and comments so people can have easier time doing changes it if they need to.
- Undo and redo still work great

Gist link above has a video on the comments showing example as well.
Below is the whole script in case gist breaks for some reason:
#if UNITY_EDITOR
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
namespace EditorPrefabUtility
{
/// <summary>
/// Utility for reverting GameObject names to their original prefab names.
/// Adds a menu option to reset selected GameObject names to match their associated prefab names.
/// </summary>
public class PrefabNameReverter
{
private const string MENU_ITEM = "GameObject/Prefab/Remove Name Overrides...";
private const string UNDO_RECORD_MESSAGE = "Remove name override";
private static double _last_execution_time = 0;
private static double _execution_time_threshold = 0.1d;
/// <summary>
/// Reverts the names of all selected GameObjects to their prefab names.
/// </summary>
[MenuItem(MENU_ITEM)]
private static void RevertPrefabNames()
{
// Prevent executing multiple times (once for every object) when called from right click menu
if(EditorApplication.timeSinceStartup - _last_execution_time <= _execution_time_threshold)
{
return;
}
var selectedObjects = Selection.GetFiltered(typeof(GameObject), SelectionMode.Editable);
// Validation should prevent this, but can't be too careful
if(selectedObjects.Length == 0)
{
Debug.LogWarning("No valid GameObjects selected to revert names.");
return;
}
RevertAllNames(selectedObjects);
_last_execution_time = EditorApplication.timeSinceStartup;
}
/// <summary>
/// Validates whether the menu item should be enabled or disabled based on the current selection.
/// </summary>
[MenuItem(MENU_ITEM, isValidateFunction: true)]
private static bool ValidateRevertPrefabNames()
{
var selectedObjects = Selection.GetFiltered(typeof(GameObject), SelectionMode.Editable);
foreach(var obj in selectedObjects)
{
// Check if the object is a gameobject and has a corresponding prefab
if(PrefabUtility.GetCorrespondingObjectFromSource(obj) != null && obj is GameObject)
{
return true;
}
}
return false;
}
private static void RevertAllNames(Object[] objects)
{
var itemsRequiringRemoval = new List<Object>();
foreach(var obj in objects)
{
// Validation will not prevent this if there are mixed types in the selection
var gameObject = obj as GameObject;
if(gameObject == null)
{
// Skipping these is fine
//Debug.LogWarning($"Skipping non-GameObject: {obj.name}");
continue;
}
// Validation will not prevent this if there are non-prefab linked objects in the selection
var prefab = PrefabUtility.GetCorrespondingObjectFromSource(gameObject);
if(prefab == null)
{
// Skipping these is fine
//Debug.LogWarning($"Skipping GameObject '{gameObject.name}' as it is not linked to a prefab.");
continue;
}
// Take a snapshot of the object's current state for undo purposes
Undo.RecordObject(gameObject, UNDO_RECORD_MESSAGE);
// Actually revert the name
gameObject.name = prefab.name;
itemsRequiringRemoval.Add(gameObject);
}
// Commit the undo changes in bulk
Undo.FlushUndoRecordObjects();
// Clear the name property modifications for all items that were reverted since they are now in sync with their prefab
foreach(var item in itemsRequiringRemoval)
{
RemoveNamePropertyModification(item);
}
//Debug.Log($"Reverted names for {itemsRequiringRemoval.Count} GameObject{(itemsRequiringRemoval.Count == 1 ? "" : "s")}.");
}
private static void RemoveNamePropertyModification(Object obj)
{
var mods = new List<PropertyModification>(PrefabUtility.GetPropertyModifications(obj));
// Remove the modification related to the name
for(int i = mods.Count - 1; i >= 0; i--)
{
if(mods[i].propertyPath == "m_Name")
{
mods.RemoveAt(i);
}
}
PrefabUtility.SetPropertyModifications(obj, mods.ToArray());
}
}
}
#endif
This should have been a native editor feature.
Hi @KhenaB,
Not sure why you want to rename the prefabs, but if it has to do with searchign for the prefab name in game you can use this:
void Start () {
this.gameObject.name ="SetTheNameHere";
}
Alternatively I found that selecting all the objects in the hieracrchy, right-clicking and say rename changes them all.
You can change inspector to Debug view and there you can revert insance name.