• Unity
  • AtlasUtilities.GetRepackedAttachments failed

Related Discussions
...

Hi. I try to repack a few atlases used from different skeletons at runtime.

I found a problem in tAtlasUtilities.GetRepackedAttachments.
If sourceAttachments contains any unrendarable attachments, regionIndexes.Count become less than sourceAttachments.Count.
It cause an ArgumentOutOfRangeException at line 463 AttachmentTools.cs.

This is my code.

public void repackSkeletons(List<SkeletonDataAsset> dataAssetList)
{
   if(dataAssetList == null || dataAssetList.Count <= 0)
   {
      return;
   }

   List<Attachment> attachmentList = new List<Attachment>();
   List<Attachment> repackedAttachmentList = new List<Attachment>();
   List<List<Skin.AttachmentKeyTuple>> keyListList = new List<List<Skin.AttachmentKeyTuple>>();
   Material sourceMaterial = null;
   Material repackedMaterial = null;
   Texture2D repackedTexture = null;

   foreach (var dataAsset in dataAssetList)
   {
      var skeletonData = dataAsset.GetSkeletonData(false);
      if (skeletonData == null)
      {
         continue;
      }

  var skin = skeletonData.DefaultSkin;
  sourceMaterial = dataAsset.atlasAssets[0].materials[0];
  List<Skin.AttachmentKeyTuple> keyList = new List<Skin.AttachmentKeyTuple>();
  keyListList.Add(keyList);
  foreach (var attachmentTuple in skin.Attachments)
  {
     attachmentList.Add(attachmentTuple.Value);
     keyList.Add(attachmentTuple.Key);
  }
   }

   Spine.Unity.Modules.AttachmentTools.AtlasUtilities.GetRepackedAttachments(
      attachmentList,
      repackedAttachmentList,
      sourceMaterial,
      out repackedMaterial,
      out repackedTexture,
       2048);

   int attachmentIndex = 0;
   int keyListIndex = 0;
   for (int dataIndex=0; dataIndex<dataAssetList.Count; ++dataIndex)
   {
      var skeletonData = dataAssetList[dataIndex].GetSkeletonData(false);
      if (skeletonData == null)
      {
         continue;
      }

  var skin = skeletonData.DefaultSkin;
  Skin repackedSkin = skin.GetClone();
  var keyList = keyListList[keyListIndex];
  foreach (var key in keyList)
  {
     repackedSkin.Attachments[key] = repackedAttachmentList[attachmentIndex];
     ++attachmentIndex;
  }
  ++keyListIndex;

  // register with my dictionary of repacked skeletons
  registerRepackedData(dataAssetList[dataIndex], repackedSkin, repackedTexture, repackedMaterial);
   }
}

You wrote your own code? I'll check this out later today.

Thanks for reporting and looking into some of the details! Stay tuned


Issue: [unity] useOriginalNonrenderable when repacking. · #1132


This should be fixed. You can apply it to your project immediately : https://raw.githubusercontent.com/EsotericSoftware/spine-runtimes/3.6/spine-unity/Assets/spine-unity/Modules/AttachmentTools/AttachmentTools.cs

This will be included in the next unitypackage update.

Great!! It was fixed.
Thanks Pharan! 😉