• Unity
  • White boxes on spine in build when using "Repack"

  • تم التحرير
Related Discussions
...

When equipping a gun it uses a modification of the mix and match script to create the weapon as attachments from sprites in Unity.

It works perfect in the Unity editor, but in a build this happens when I pick up a weapon, and all spine attachments turn into white transparent boxes.

In the video below, the "Water gun" does not use "Repack" feature, there it works, but with the shotgun it doesn't work and I get the white boxes.

Is repack important, and how do I make it work?

Here's the part of the code with comments about repack.

// STEP 3: APPLY AND CLEAN UP.
// Recommended, preferably at level-load-time: REPACK THE CUSTOM SKIN TO MINIMIZE DRAW CALLS
//             IMPORTANT NOTE: the GetRepackedSkin() operation is expensive - if multiple characters
//             need to call it every few seconds the overhead will outweigh the draw call benefits.
//
//             Repacking requires that you set all source textures/sprites/atlases to be Read/Write enabled in the inspector.
//             Combine all the attachment sources into one skin. Usually this means the default skin and the custom skin.
//             call Skin.GetRepackedSkin to get a cloned skin with cloned attachments that all use one texture.

if (repack)   {
   var repackedSkin = new Skin("repacked skin");
   repackedSkin.AddSkin(skeleton.Data.DefaultSkin); // Include the "default" skin. (everything outside of skin placeholders)
   repackedSkin.AddSkin(customSkin); // Include your new custom skin.
   if (runtimeMaterial)
      Destroy(runtimeMaterial);
   if (runtimeAtlas)
      Destroy(runtimeAtlas);
   repackedSkin = repackedSkin.GetRepackedSkin("repacked skin", sourceMaterial, out runtimeMaterial, out runtimeAtlas); // Pack all the items in the skin.
   skeleton.SetSkin(repackedSkin); // Assign the repacked skin to your Skeleton.
   if (bbFollower != null) bbFollower.Initialize(true);
} else {
   skeleton.SetSkin(customSkin); // Just use the custom skin directly.
}

Thank you!

Sorry to hear you're having troubles. Most likely the read/write enabled or texture compression settings of the texture are setup incorrectly for reading the texture. Did you check the list of common causes for repacking to fail on the spine-unity docs pages here (section Runtime Repacking, Important Note)?

20 أيام لاحقا

Thank you for responding! Sorry for not getting back, I will check this next time it happens 🙂

-niclas

    عام واحد لاحقا

    nicmar

    Hey nicmar, I'm facing the same problem here and it only happens when I run it on android, maybe ios too but I haven't tested it. Have you found the solution? I have checked read/write on my textures.

    @AmazeFPig Sorry to hear you're facing troubles! Which version of the spine-unity runtime (name of the unitypackage, also listed in Assets/Spine/version.txt) are you using?

      Harald
      4.1-2022-10-31

        • تم التحرير

        Harald
        And here is the code I'm using

        `
        public void OptimizeSkin()
        {
        // 1. Collect all the attachments of all active skins.
        collectedSkin = collectedSkin ?? new Skin("Collected skin");
        collectedSkin.Clear();
        //collectedSkin.AddSkin(skeletonGraphic.Skeleton.Data.DefaultSkin);
        collectedSkin.AddSkin(skeletonAnimation.Skeleton.Data.DefaultSkin);
        collectedSkin.AddSkin(equipsSkin);

                // 2. Create a repacked skin.
                // Note: materials and textures returned by GetRepackedSkin() behave like 'new Texture2D()' and need to be destroyed
                if (runtimeMaterial)
                    Destroy(runtimeMaterial);
                if (runtimeAtlas)
                    Destroy(runtimeAtlas);
                //var repackedSkin = collectedSkin.GetRepackedSkin("Repacked skin", skeletonGraphic.SkeletonDataAsset.atlasAssets[0].PrimaryMaterial,
                //out runtimeMaterial, out runtimeAtlas, maxAtlasSize: 1024, clearCache: false);
                var repackedSkin = collectedSkin.GetRepackedSkin("Repacked skin", skeletonAnimation.SkeletonDataAsset.atlasAssets[0].PrimaryMaterial,
                    out runtimeMaterial, out runtimeAtlas, maxAtlasSize: 1024, clearCache: false);
                collectedSkin.Clear();
        
                // You can optionally clear the textures cache after each ore multiple repack operations are done.
                //AtlasUtilities.ClearCache();
                //Resources.UnloadUnusedAssets();
        
                // 3. Use the repacked skin.
                //skeletonGraphic.Skeleton.Skin = repackedSkin;
                skeletonAnimation.Skeleton.Skin = repackedSkin;
                RefreshSkeletonAttachments();
            }

        `
        What I did was generate new attachments and set this new attachment on slot, after that I call this OptimizeSkin(). It seems that some attachments are replaced by the white box

        Harald
        And this is how it looks like

        AmazeFPig 4.1-2022-10-31

        Thanks for the additional info. Please note that you're not using the latest version of the spine-unity runtime. Could you please check if updating the runtime perhaps already resolves the issue? As always, be sure to back up your work before updating to be on the safe side.

          Harald
          I have updated to the newest version and unfortunately it didn't solve my problem 😢

          @AmazeFPig Sorry to hear that your issue persists. Could you please send us a minimal Unity project which still shows this issue? You can send it as a zip package to contact@esotericsoftware.com, briefly mentioning this forum thread URL so that we know the context. Then we can have a look at it.

            Harald I have sent you an email with a google drive link to my unity project. Let me know if you have trouble accessing or reproducing the issue.
            Thanks for your patience.

            • تم التحرير

            Thanks for sending the email, we received your package, but it is 2.6GB in size (uncompressed about 7GB). In general, never include the Library directory when sending reproduction projects, that alone contributed 5GB of unpacked size on disk, and will be deleted before opening the project anyway. Apart from that, your project is far from being minimal, and it does not compile after opening it in Unity (related to your used thirdparty plugins), thus we can't even enter play mode in your test scene. Also you mention in your email that the problem occurs when using a custom flutter Unity widget on Android, which adds yet another unnecessary layer around it.

            What I forgot to mention earlier, there are multiple causes for skin repacking to end up failing with white textures, which are documented in the Note box here:
            http://esotericsoftware.com/spine-unity#Combining-Skins
            Please check these listed points, perhaps Texture settings for Android are messed up in your problematic textures.

            If none of the above resolve your problem, you can try building a really minimal reproduction project this time which does not use any thirdparty plugins, builds directly to Android without any wrapper layers and uses only one or two scripts to reproduce the problem. The reproduction project shall not include a game, you need to strip the logic down to include only the problematic logic, no other lines of code.

              17 أيام لاحقا
              • تم التحرير

              Harald
              Hey Harald, I just want to let you know that this has been solved. It turns out that I didn't turn on Read/Write on the textures that were exported from Spine. Thanks for your support, cheers.

              @AmazeFPig Thanks for getting back to us, glad to hear you've figured it out!