RenameAsset does not change the name of asset in Project Window in Awake() or OnEnable()

I have this in Awake() and OnValidate() (also have tried OnEnable())

string assetPath = AssetDatabase.GetAssetPath(this);
AssetDatabase.RenameAsset(assetPath, "myName");

The above renames the ScriptableObject Asset in the Object Window in OnValidate() but not in Awake() or OnEnable().

Not sure if it matters, but I am creating the ScriptableObject using this at the top of the SO class:

[CreateAssetMenu(fileName = "NewActor", menuName = "ScriptableObject/Object/Actor", order = 0)]

The Object is named NewActor and not myName until I enter some data in a field.

My goal is to the name asset based on name field and an id that I’m generating (not shown in the above code, since I can’t even get a simple myName string to rename properly in Awake()).

My best guess is that you’re not having [ExecuteInEditMode] or [ExecuteAlways] in your script and thus no Awake or OnEnable are running.

Be sure to check the return value of RenameAsset - it’s a string that, if not empty, contains an error message. Log that!

make sure Refresh after any update to assets to reload.

string assetPath = AssetDatabase.GetAssetPath(this);
AssetDatabase.RenameAsset(assetPath, "myName");
AssetDatabase.Refresh ()