Changing a prefab's name (via the editor) doesn't apply the new name to the prefab's instances?

I just noticed that if I change the name of a prefab, the new name won’t be applied to the prefab’s in-scene instances. That’s not what I would expect. Same thing going the other way around, if I change the name of one of the instances of the prefab and hit apply, the prefab’s name will remain.

So how can I reflect the changes to the prefab instances when I rename it?

Thanks!

It seems that, if I manually change the name of one of the instances of a prefab, and then rename the prefab itself, the new name won’t be applied to the instance that I renamed.

If I don’t mess around like that, i.e. I be a good boy, instantiate the prefab, (by drag-n-drop or code) - and then rename the prefab (without messing with its instances names) - everything will work nice and cozy.

I didn’t like this really, so I wrote this small hack, which forces all the instances of the prefab, to have the same name as the prefab - but it forces you to rename from the prefab, not the instances.

Just stick it onto your prefab’s instances that you want their names to be connected to the prefab’s name:

using UnityEngine;
using UnityEditor;

[ExecuteInEditMode]
public class PrefabNameUnifier : MonoBehaviour
{
	[SerializeField] [HideInInspector] GameObject prefab;
	void OnEnable()
	{
		if (PrefabUtility.GetPrefabType(gameObject) == PrefabType.PrefabInstance) {
			prefab = PrefabUtility.GetPrefabParent(gameObject) as GameObject;
			EditorApplication.update += CheckForNameChange;
		}
	}
	void CheckForNameChange()
	{
		if (prefab.name != name) {
			print("Changing instance name from: " + name + " to " + prefab.name);
			name = prefab.name;
		}
	}
}

Since this MB will be used only in the editor, you have to wrap everything with “#if UNITY_EDITOR” “#endif” - one might think it’ll be better to just place it in the editor folder, but unfortunately it won’t be visible then (one can’t attach it to a GO)