I am building asset bundles from a scriptable object and I would like to change the filename according to the build options I set in my scriptable object.
I’ve tried object.name = “newName” however that is does not change the filename.
Any pointers please?
Thanks
Think I found a better way to rename an asset:
string assetPath = AssetDatabase.GetAssetPath(myAsset.GetInstanceID());
AssetDatabase.RenameAsset(assetPath, newName);
AssetDatabase.SaveAssets();
@liszto Thanks you got some ideas churning which helped me solve the problem.
Final solution is this:
string listingFilePath = Path.GetFullPath(myAssetPath);
string listingFilePathNoFileName = listingFilePath.Remove(listingFilePath.Length - (myAssetPath.Length)); //Remove filename
string listingRelativePath = AssetDatabase.GetAssetPath(myAsset); //Get path withing the unity folder
string listingFullPath = listingFilePathNoFileName + listingRelativePath;
string newFilePath +="mychanges";
File.Copy(listingFullPath, newFilePath, true);
JouPal
May 23, 2020, 12:03pm
4
public bool renameOnValidate = false;
public int id;
public int itemName
private void OnValidate()
{
if (renameOnValidate)
{
string thisFileNewName = id + "_" + itemName;
string assetPath = UnityEditor.AssetDatabase.GetAssetPath(this.GetInstanceID());
UnityEditor.AssetDatabase.RenameAsset(assetPath, thisFileNewName);
renameOnValidate = false;
}
}