Hello!
I’m trying to create a custom script to split sprite by JSON data, but after the second usage (to update sprite asset) I receive warning like:
Identifier uniqueness violation: ‘Name:Hell-Limbus-Security-Desk, Type:Sprite, FileId:0’. Multiple Objects with the same FileId are generated by this Importer. There is no guarantee that subsequent imports of this asset will properly re-link to these targets. UnityEditor.AssetImporter:SaveAndReimport ()
And some previously added sprites are became Missed.
Here is my code:
```csharp
-
[MenuItem("FF Tools/Import Json Slices")] public static void Slice() { var texture = Selection.GetFiltered(typeof(Texture2D), SelectionMode.DeepAssets).First(); var path = AssetDatabase.GetAssetPath(texture); var sjson = AssetDatabase.LoadAssetAtPath<TextAsset>(path.Replace(".png", ".json")); var ti = AssetImporter.GetAtPath(path) as TextureImporter; if (ti == null || ti.spriteImportMode != SpriteImportMode.Multiple) return; var spritesheet = new List<SpriteMetaData>(); /* ... json data preparation here */ foreach (var slice in slices.Values) { var name = slice["name"].Value; var bounds = slice["keys"][0]["bounds"]; var pivot = slice["keys"][0]["pivot"]; var rect = BoundsToRect(w, h, bounds); var item = new SpriteMetaData { pivot = new Vector2(0.5f, 0.5f), alignment = (int)SpriteAlignment.Custom, name = $"{layerName}-{name}", rect = rect, border = Vector4.zero }; spritesheet.Add(item); } ti.spritesheet = spritesheet.ToArray(); ti.SaveAndReimport(); }*
```
Also I noticed that for some reason in .meta file TextureImporter: internalIDToNameTable: - field not filed with a new added sprites names/ids.
Unity 2021.2.0b9
Appreciate any help! Thanks!