All I need to know is this; so when I set the filename in the CreateAssetMenu above, it makes all “.asset” files that name + a number (First is File, then File 1, then File 2). How can I have the file name defined by the Menu itself? The assets created have an internal name but for debugging and organization purposes I will need to be able to name the actual files.
The only way I have found to rename them is through the file explorer, I was wondering if there was a simple way to do so quickly from inside the Unity editor.
(Still trying to understand ScriptableObjects in general for the most part)
That’ll allow you to create whatever name you want. If you want the +1 numbering, you can get that from AssetDatabase.GenerateUniqueAssetPath. So:
var obj = ScriptableObject.CreateInstance<MyScriptableObject>();
var path = "Assets/CoolPath.asset";
path = AssetDatabase.GenerateUniqueAssetPath(path);
AssetDatabase.CreateAsset(obj, path);
AssetDatabase.ImportAsset(path);
The importasset call makes the asset show up automatically in your project view. I think it’s neccessary, but that might’ve changed since I wrote the code I’m copying from here.
Alright thanks for the info, its still pretty odd to me that the CreateAssetMenu cannot directly name the files but its fine, this should be a good workaround
I think I’m missing something, otherwise:
The attribute allows to specify a menu entry so that you can easily create it just like a prefab, a material etc in the project window.
Once you clicked on the menu entry, a file will appear, ready to be named initially, just like usual scripts.
Sorry for the confusion, when the file was appearing it wasn’t letting me enter a name as I didn’t actually notice the box pop up. I had assumed that the file was created upon filling out the variables and not immediately when clicking the option