bali33

Hi guys,

In order to manage different game resolution I started to packed my scenes into AssetBundles and all the assets that are used into my scene into other AssetBundles with HD and SD variants.

It seems to work as expected but not for my Spine animations which won't show up. My scenes are correctly loaded and the right dependencies too (HD or SD assets) but when it comes to Spine animations, Skeleton Data Asset property of all Skeleton Animation scripts will remains empty.

Has anyone tried to use Spine Animations in that way ?

Thanks
bali33
  • Posts: 108

Pharan

I should really look into how AssetBundles work in general. Haven't tried them since they became part of Unity free/personal edition.
User avatar
Pharan
  • Posts: 5366

bali33

Ok - would be great :-)

Just to let you know, if you pack a scene with it's all content, included Spine animations, it will work ! I have this issue since I packed all scene assets in separate AssetBundles in order to manage an HD/SD version.

Thanks

-- 04 Avr 2016 1:33 pm --

Ok - I have another issue concerning Fonts that I didn't see. After this issue was fixed all Spine animations worked properly.

So my bad :-)

-- 05 Avr 2016 9:37 am --

Actually it still does not work !

To be sure it was not my fault I decided to create an empty project, include the AssetBundleManager project made by Unity that show how to use variant scenes and add one spine animation.

From Unity targeting OS X :

- HD variant : the spine correctly show up
- SD variant : the spine doesn't show ip - you have to click on the GameObject and reload the SkeletonData

From Unity targeting iOS :

- HD variant : the spine show pink meshes - event if the skeleton data property is correctly set-up, you have to re-assign it and reload.

- SD variant : you can't choose your variant when targeting iOS because is uses ODR protocol which is simulate and provide the right variant automatically.

Project zip file : https://we.tl/DmptbQV8hN

AssetBundleManager : https://bitbucket.org/Unity-Technologies/assetbundledemo

IMPORTANT : you have to set Assets/AssetBundles/Local AssetBundle Server and deactivate "simulation mode"

If someone can help me on this it would be great - I really need HD and SD variant in my game in order to have it running fine on all mobile devices.

Thanks
bali33
  • Posts: 108

Pharan

What's ODR?

I think this is a deserialization order problem. I'm not super sure, and internet's kinda wonky right now. No idea how your asset bundles are set up (material level or texture level or whatever). But the pink meshes definitely point to things not being referenced correctly.

If this is the case, one of the solutions should be to make sure the skeletons are loaded (or reloaded) AFTER the asset bundles are downloaded and loaded.

Spine's dependency/loading order goes this way:
The AtlasAsset holds a .atlas.txt TextAsset and Material assets (which points to the textures).
SkeletonDataAsset has assigned assets. A json (or binary) TextAsset, and the AtlasAsset above.
If this information is complete, a SkeletonData object can be generated by parsing the json/binary. SkeletonData holds the stateless/setup pose data, attachments, animations and other skeleton data for your skeleton.
At this point, each Attachment object is assigned the correct Material asset. <--- this is likely the point where it would break if your asset bundles are not loaded.

A Skeleton object is instantiated using SkeletonData.
This Skeleton is managed and used by SkeletonRenderer/SkeletonAnimation.

So what will likely fix this is delay skeleton loading (don't spawn or cause any prefabs with spine components to be loaded) until the asset bundles are done loading.
Or if you can't do that. You need to call skeletonDataAsset.Reset() on the relevant SkeletonDataAssets, and THEN call skeletonAnimation.Initialize(true) to any of those instances that didn't load correctly. Note that this means any post-initialization steps will have to be done again here. Particularly, subscriptions to AnimationState events won't be in effect because Initialize(true) actually creates a new instance of AnimationState.
User avatar
Pharan
  • Posts: 5366

bali33

ODR stands for On Demand Resource which is a feature you can use on iOS - it useful when working for platform like AppleTV for example and you app had to be below 200 mo.

I just updated my Spine runtime because I did not have the Initialize method on my SkeletonAnimation. Since that the result is worst than before, now the SkeletonAnimation script it's still there but the SkeletonData property is empty. So no way to call Reset on it !

If you download the project and build AssetBundles you can see what is inside each one and the dependencies in the manifest file. The variant-scene manifest shows that it depends on the myassets.hd bundles. In the myasset.hd.manifest you have the list of the assets used :

Assets:
- Assets/AssetBundleSample/Assets/Variants/MyAssets-HD/logo.png
- Assets/AssetBundleSample/Assets/Variants/MyAssets-HD/someMaterial.mat
- Assets/AssetBundleSample/Assets/Variants/MyAssets-HD/logo_SkeletonData.asset
- Assets/AssetBundleSample/Assets/Variants/MyAssets-HD/logo.json
- Assets/AssetBundleSample/Assets/Variants/MyAssets-HD/myTexture.png
- Assets/AssetBundleSample/Assets/Variants/MyAssets-HD/logo_Material.mat
- Assets/AssetBundleSample/Assets/Variants/MyAssets-HD/logo_Atlas.asset
- Assets/AssetBundleSample/Assets/Variants/MyAssets-HD/logo.atlas.txt
Dependencies: []
bali33
  • Posts: 108

Pharan

To Reset it, you call Initialize(true). If the SkeletonData asset is not there, set it.
User avatar
Pharan
  • Posts: 5366

bali33

Hi,

How would I set-it ? The only reference I have of the SkeletonData asset is the one in the SkeletonAnimation component. If it is lost during the serialisation/deserialisation process I have no mean to set-it back. So it means I have to add a script to reference this SkeletonData assets and then wait, reset-it and then cal Initialize(true).

But all that let me think that is something wrong with Spine or AssetBundle variant feature - it should works "out of the box". Using AssetBundle + AssetBundles variants it's already an pain in the *** - now I have to change my set-up and add code to handle Spine Animations. The workflow it's really not convenient.

Do you think the issus comes from AssetBundle or SkeletonAnimation ?

Thanks
bali33
  • Posts: 108

Pharan

It could just be that using AssetBundles requires certain setups. It looks like there are any number of ways to split your assets between bundled in an asset bundle or the main program.

It does look like a pain in the ass, especially the part where you have to build per platform whenever you need to update.

But if you're losing serialized references because everything's in a bundle, I don't think the problem would be specific to Spine. There's certainly nothing in the code that automatically sets that field.
User avatar
Pharan
  • Posts: 5366

bali33

That's what I think too - I'll try to ask in Unity forum and shared the same sample project.

Thanks
bali33
  • Posts: 108

Bryant

Hi bali & Pharan,

Have you guys found a workaround for this? I have exactly the same issue right now with my asset bundle setup :(

All of my art assets are in one bundle, which variants for each target resolution (e.g., art.sd, art.hd). The art asset bundles also include my Spine assets, since each variant has a different atlas and Skeleton scale. I have my scenes in separate asset bundles, and those scenes have dependencies on the art bundles.

When I load a scene and its dependencies with the default (HD) variant, everything works fine. But when I load a scene with the non-default variant (SD), all of my Spine objects lose their references to their Skeleton Data Assets.

All of my non-Spine objects work just fine. What this suggests to me is that the Skeleton Data Assets in my variant bundles are somehow being assigned a different GUID than the assets in my default bundle.

This is a huge blocking issue for me right now :( Any ideas? :(

-- 08 Apr 2016, 15:19 --

I found a clue! :)

My suspicion now is that there's a bug in Unity's scene loading behaviour when a scene contains references to a ScriptableObject data type that needs to be loaded from a variant asset bundle.

I created a test scene that displays an HD Spine animation. It also loads a dummy ScriptableObject data file that has nothing to do with Spine. I placed all of my HD Spine assets + my dummy data asset into an art.hd asset bundle. I then created an art.sd asset bundle variant that has clones of all of the HD + dummy data assets. Lastly, I placed my test scene in its own asset bundle.

After building the bundles, I load the test scene and all of its dependencies using the .hd variant. Everything works as it should :) I then load the test scene and all of its dependencies using the .sd variant. Now, any component in the scene with a reference to a ScriptableObject asset (like the Skeleton asset and my dummy data asset) loses its reference, and everything is broken.

So, it's not a problem that's specific to Spine.

I did discover a workaround for the issue, though! If I manually call assetBundle.LoadAllAssets() on my dependency bundles before loading the test scene, the ScriptableObject assets get loaded correctly and everything works! :) That makes me think that Unity's scene loading isn't properly calling assetBundle.LoadAsset() on the ScriptableObject types when using a variant bundle.

I hope that helps! I'm going to test this in the 5.4 beta, and if it's still an issue, I'll report a bug to Unity.
Bryant
  • Posts: 10

bali33

Hi,

Thanks for the clue ! I did post in the Unity forum but had no answers. I will bump it and point to your post here or copy/paste here in order to let them now about what you found.
bali33
  • Posts: 108

atraver

Hi, bryant and bali33.

I'm not entirely sure if my issue is related to yours, but I was having a pink-box issue when building Spine assets into asset bundles, and just managed to solve it. Hopefully it helps your use cases, as well. Here's the thread: Unity crashes when building Spine-related asset bundles
atraver
  • Posts: 27


Return to Unity