How to programmatically change name of sub-assets

I am trying to change the name of the sub-sprites of a sprite sheet. I have searched and tried everything I can think of and cannot get it to work, which makes me think it can’t be done at this point in time.

Let’s say I have a sprite sheet that has already been split up into individual sprites inside of Unity.
49224-screen-shot-2015-07-01-at-34749-pm.png

I am attempting to change the sub-sprite names programmatically.

I tried using

AssetDatabase.RenameAsset (...)

on the sprite sheet asset, which only changes the sprite sheet name and not sub-sprites.

I then obtained a sub-sprite and attempted to change its name using the below code.

			if (AssetDatabase.IsSubAsset (subSprite))
			{
				AssetDatabase.RenameAsset (AssetDatabase.GetAssetPath (subSprite), "newSprite" + i.ToString ());
			}

However, this too only changes the sprite sheet name.

49227-screen-shot-2015-07-01-at-35917-pm.png

I’m not sure where else I can take this to achieve my desired outcome, apart from programmatically copying the original sprite sheet and using that to create a copy. But even then, I still am unable to alter the sub-sprite names.

I also tried changing subSprite.name, but this just changes the internal name and not the asset name.

Any ideas?

try:

   AssetDatabase.ClearLabels(item);
   item.name = newName;
   AssetDatabase.SetLabels(item, new string[]{newName});
   AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(item));

Where item is the object reference of your sub asset.

string path = AssetDatabase.GetAssetPath(mainAsset);
UnityEngine.Object assets = AssetDatabase.LoadAllAssetsAtPath(path);
string prefix = string.Format(“{0}_”, mainAsset.name);

			for(int i = 0; i < assets.Length; i++)
			{
				if (AssetDatabase.IsSubAsset(assets*))*
  •  		{*
    

_ if (assets*.name.StartsWith(prefix) == false)_
_
{_
assets_.name = prefix + assets.name;
EditorUtility.SetDirty(assets);
}
}
}
EditorUtility.SetDirty(mainAsset);
AssetDatabase.ImportAsset(path);*

This worked for me, so long as you have access to the mainAsset._