• Unity
  • Question about the loading of multi textures

Hi everyone,

There is a spine file with two skins, exporting with two different textures.
The question is, does Unity load all textures when the spine file is created, or load the one that binding to the skin only?

The case is that I'm using spine for a building. It has broken and normal skin. I'm trying to avoid having the broken and normal images in the same atlas, as the broken one will never be used after the building got fixed.

Related Discussions
...

Welcome to the Spine forum!

[Edited by Harald:] It depends on how you reference your AtlasAssets. Any indirect (cascading) asset references of a scene object will be loaded by Unity. If your GameObject has e.g. a SwapToDestroyed component which holds a direct reference to the secondary destroyed AtlasAsset holding the Materials and Textures for the destroyed skin, these asset references will then be loaded alongside the GameObject. If you want to avoid loading assets up front, you need to use delayed-loading mechanisms like Addressables, Assetbundles, etc. [Edit end]

If you have any further questions, please do not hesitate to ask us!

Welcome to the Spine forum!

Unfortunately the wording in the above posting could be misunderstood, I have just changed it so that it's more correct.

To answer your question:
Normal Unity means apply, Unity loads all assets that are referenced directly (A->B) or indirectly (A->X->B). This means that by default, the SkeletonDataAsset references the AtlasAsset, which references it's atlas pages as Materials, where each Material references the atlas page texture. So if you exported all atlas pages normally as a single AtlasAsset, all pages will be loaded as soon as your skeleton's SkeletonDataAsset is loaded.

In your case, if you export two separate AtlasAssets for two separate skins and assign the AtlasAsset only later upon switching skins, the SkeletonDataAsset does not initially reference your secondary skin atlas textures. However, if e.g. your building GameObject holds a reference to the second AtlasAsset, this again counts as a normal asset reference as usual, so you have just moved the reference from one asset to another.

If you want to use delayed loading of atlas texture pages, you would need to make sure to not include direct references to e.g. your secondary AtlasAsset asset and instead use Unity means like Addressables, AssetBundles, etc. You could use e.g. a build script clear any direct references to the delayed-loaded resources and use a loader script to load and assign references at runtime when actually used.
See this forum thread for additional info.

We also have an issue ticket here which deals with implementing a component to more comfortably support on-demand loading of atlas assets:
https://github.com/EsotericSoftware/spine-runtimes/issues/1890
Unfortunately we didn't get to implement this feature yet.

If anything of the above is unclear, don't hesitate to ask.

5 dias depois

This is very clear. Thanks!

One more question about texture packing.

I got two skins and tried to pack them into two textures.

I'm using Photoshop to Spine workflow, so the folder structure looks like this in Photoshop.

Then I got the image file structure like this.

The question is: How do I pack all "base" folder images into one texture and all "normal" folder images into the other?


This works as expected, but I need to move them out of the "skin" folders and re-assign the path. Seems I shouldn't do that.

You can use pack.json to combine subdirectories:
Texture packing - Spine User Guide: JSON Configuration

In your case, create a pack.json file with the following parameter:

{
combineSubdirectories: true
}

Then, put the pack.json file in the "base" folder. This allows you to combine the images in "base_1", "base_2", and "base_3" subdirectories into a single page.