• Editor
  • How to export texture just for one skin with linked mesh

Here is the question.
I had project with some base skin, which contains original mesh.
Other skin (full recolor) use linked meshes from original mesh.
And I want only one recolored texture for export (without base texture) for some reason; f.ex. I want only recolored texture in my final application.

I found some similar questions:
https://esotericsoftware.com/forum/d/5494-export-just-one-skin
https://esotericsoftware.com/forum/d/24300-export-json-and-texture-atlas
But I know that skeleton contains all skin info in JSON and this is ok.
And there thread are... some quite old, some asks another info.

So go on. If I export recolor without base texture (using "no pack"), I get error in Unity (yes, it's Unity runtime).
In these threads I see some mentions about "edit AtlasAttachmentLoader".

So, my final question is:
"Edit AtlasAttachment" is still correct way to do this, or there is some other, more actual methods (implemented by Spine side, not runtime)? Or just - some others methods 🙂

Related Discussions
...

To export a texture for just one skin while using linked meshes, you can follow these steps:

  1. Separate Texture Packing: Use the Texture Packer to pack only the images for the skin you want. Place the images for the desired skin in a separate folder and pack that folder. This will create an atlas containing only the images for that skin.

  2. Custom AttachmentLoader: At runtime, you can use a custom AttachmentLoader to handle the loading of attachments. This allows you to load only the necessary textures and avoid errors related to missing textures. You can modify the AtlasAttachmentLoader to skip loading textures that are not needed.

Here is a brief outline of how you can achieve this:

Step 1: Packing the Texture Atlas

  • Organize your skin images in separate folders.
  • Use the Texture Packer to pack the images for the specific skin into a separate atlas.

Step 2: Custom AttachmentLoader

  • Create a custom AttachmentLoader by modifying the AtlasAttachmentLoader.
  • Ensure that the custom loader only sets the region for attachments that are present in the packed atlas.

Here is a simplified example of how you might modify the AtlasAttachmentLoader:

public class CustomAttachmentLoader extends AtlasAttachmentLoader {
    private Atlas atlas;

    public CustomAttachmentLoader(Atlas atlas) {
        super(atlas);
        this.atlas = atlas;
    }

    @Override
    public RegionAttachment newRegionAttachment(Skin skin, String name, String path) {
        RegionAttachment attachment = super.newRegionAttachment(skin, name, path);
        AtlasRegion region = atlas.findRegion(path);
        if (region != null) {
            attachment.setRegion(region);
        } else {
            // Handle missing region, e.g., log a warning or set a default texture
        }
        return attachment;
    }

    // Similarly override other methods for MeshAttachment, etc.
}

Step 3: Using the Custom AttachmentLoader

  • When loading your skeleton data in Unity, use the custom AttachmentLoader to ensure only the necessary textures are loaded.

Example in Unity

Atlas atlas = new Atlas("path/to/your/packed/atlas.atlas", new TextureLoader());
SkeletonJson json = new SkeletonJson(new CustomAttachmentLoader(atlas));
SkeletonData skeletonData = json.readSkeletonData("path/to/your/skeleton.json");

By following these steps, you can ensure that only the textures for the desired skin are loaded, avoiding errors related to missing textures and optimizing your application's performance.

Spinebot got it. The default AttachmentLoader wants to find all the regions in the atlas. If you want to use an atlas that doesn't have all the regions, you'll need to provide your own AttachmentLoader. This is quite easy, you can just copy/paste AtlasAttachmentLoader and make changes so a missing region is not an error. Of course if you try to draw a missing region, rendering will crash.

The same technique can be used to not load any regions, only the skeleton data. Then you could use the skeleton for other purposes (like animating UI elements) or you could assign the regions later (like after packing a new atlas at runtime).

Wow, some rocket science just happens!
Thanks for answer, and for the confirmation.