Renaming Child Assets in Project

I’m looking to see if it’s possible, and if so then how to rename an asset in your project that exists as a child of another object.

I am currently using “AssetDatabase.AddObjectToAsset” API to add an object as a child of another object. But after that occurs I want to have the ability to rename that child object. Can I do this? How would I do this?

As a note, I do not want to destroy the object and then recreate it with a new name, as I want to use these as references on other objects.

You can easily change the name of a nested asset with a simple custom editor script.

using UnityEditor;
using UnityEngine;

namespace MyNamespace {
    [CustomEditor(typeof(MyScriptableObject))]
    public class MyScriptableObjectEditor : Editor {        
        public override void OnInspectorGUI () {
            target.name = EditorGUILayout.TextField("Name", target.name);
            
            base.OnInspectorGUI();
        }
    }
}

@Nerull22 If you’re using a custom Editor script, you can use the Editor script’s “target” reference to rename a Child Asset while it’s inside its Parent Asset.

From within the ItemEditor script, just use:

target.name = newName;
AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath((Item)target));

Where “Item” is the class of the Child Asset, and “newName” is the name you want to assign to the Child Asset.

The 2nd line reimports the asset, and doesn’t seem to be strictly necessary, but if you don’t use it, you won’t see the name change in your “Project” view until you save Unity manually.

Note: The “target” reference is just a reference to the Object that the Editor script is targeting. I imagine that if you changed the Child Asset’s .name value via another reference it would also work, but I haven’t tested this.

// 0 I believe would be the parent, just increment up 1 each time.
transform.GetChild (0).name = “SomeNewName”;

GameObject gme;
void Start() {
//get a unique parent or child;
gme = gameObject.Find (“some parent object name”);

            // lookup a child and rename like this:

		gme.transform.Find ("original name of child").name = "some new name";

		//find a child of a child like this:

		gme.transform.Find ("name of child/child of a child").name = "some new name";

}