- Home /
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() ).
Answer by YasanthaPrabath · Aug 30, 2020 at 01:19 AM
make sure Refresh after any update to assets to reload.
string assetPath = AssetDatabase.GetAssetPath(this);
AssetDatabase.RenameAsset(assetPath, "myName");
AssetDatabase.Refresh ()
That unfortunately does not work. It is still not rena$$anonymous$$g when I first create the object (which I assume is what happens in Awake()). It is only rena$$anonymous$$g when I edit a field in the inspector (which I assume is what happens in OnValidate()).
Your answer
Follow this Question
Related Questions
No way to rename Sub Assets properly 2 Answers
How to change an object's name inside an asset file? 0 Answers
Prevent changes in ScriptableObject type Asset in Editor. Dont save it. 0 Answers
How to create custom asset icons for ScriptableObject instances 2 Answers
Unity recompilation time slowly increases each time it's recompiled. Why? 0 Answers