• RuntimesUnity
  • Is there a way to load spine data from Streaming Assets?

Hey I was wondering if there was an easy way to load spine data from Streaming Assets.
We are setting our game up for modding, and a lot of our other assets (png's, json data files etc.) are exposed in Streaming Assets. I was wondering what the best way would be to also load spine characters from Streaming Assets with the goal to expose them to the players and let them modify them.

Cheers!

Related Discussions
...

Please check out the Spine Examples/Other Examples/Instantiate from Script example scene, it shows how you can instantiate a skeleton from the separate export files at runtime.

An alternative way would be to replace some of the assets (e.g. the textures at materials or the atlas asset) of an existing skeleton at runtime. If you replace the atlas layout and not only the texture at a material, you would need to call e.g. skeletonAnimation.Initialize(true); to reload the skeleton using the updated atlas asset.

I've been loading the skeleton as you suggest (and the link)
m_skeletonAnimation.skeletonDataAsset = UnitManager.Instance.GetUnitSkeletonData(spawnerData.m_id);
m_skeletonAnimation.Initialize(true);

But I'm getting the following error:

IndexOutOfRangeException: Index was outside the bounds of the array.
Spine.RotateTimeline.Apply (Spine.Skeleton skeleton, System.Single lastTime, System.Single time, Spine.ExposedList
1[T] firedEvents, System.Single alpha, Spine.MixBlend blend, Spine.MixDirection direction) (at Library/PackageCache/com.esotericsoftware.spine.spine-csharp@c658453bb5/Animation.cs:481)`

I forgot to mention: when replacing the SkeletonDataAsset at an existing skeleton, you also need to make sure to set initialSkinName and the initial animation (AnimationName) to a value that exists at the new SkeletonDataAsset, before calling Initialize(true);.

If this does not resolve your problem, could you please share a minimal Unity project that shows this issue? E.g. using a simple script that replaces the local SkeletonDataAsset asset reference instead of using Streaming Assets. 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 what's going wrong.

In general please always post the complete stack trace, not only the topmost line, as it's rarely helpful without the context.

  • Изменено

Thank you Harald.
Setting the default animation to my "run" animation fixed the error for me for 3/4 Skeletons but not for one of them. But trying to the same with my "aim" animation throws the same error for all of them.

Both animations are setup the same way and show up just fine in the SkeletonDataAsset inspector.
And all 4 characters are setup the same as well.

We are not using skins at this time so that didn't seem to be required. Currently the Skeleton is assigned as a reference in the unity editor and not loading from Streaming Assets.

IndexOutOfRangeException: Index was outside the bounds of the array.
Spine.RGBATimeline.Apply (Spine.Skeleton skeleton, System.Single lastTime, System.Single time, Spine.ExposedList1[T] firedEvents, System.Single alpha, Spine.MixBlend blend, Spine.MixDirection direction) (at Library/PackageCache/com.esotericsoftware.spine.spine-csharp@c658453bb5/Animation.cs:1171)
Spine.AnimationState.Apply (Spine.Skeleton skeleton) (at Library/PackageCache/com.esotericsoftware.spine.spine-csharp@c658453bb5/AnimationState.cs:266)
Spine.Unity.SkeletonAnimation.ApplyAnimation () (at Library/PackageCache/com.esotericsoftware.spine.spine-unity@c658453bb5/Runtime/spine-unity/Components/SkeletonAnimation.cs:252)
Spine.Unity.SkeletonAnimation.Update (System.Single deltaTime) (at Library/PackageCache/com.esotericsoftware.spine.spine-unity@c658453bb5/Runtime/spine-unity/Components/SkeletonAnimation.cs:239)
Spine.Unity.SkeletonAnimation.LateUpdate () (at Library/PackageCache/com.esotericsoftware.spine.spine-unity@c658453bb5/Runtime/spine-unity/Components/SkeletonAnimation.cs:273)
Spine.Unity.SkeletonRenderer.Initialize (System.Boolean overwrite, System.Boolean quiet) (at Library/PackageCache/com.esotericsoftware.spine.spine-unity@c658453bb5/Runtime/spine-unity/Components/SkeletonRenderer.cs:426)
Spine.Unity.SkeletonAnimation.Initialize (System.Boolean overwrite, System.Boolean quiet) (at Library/PackageCache/com.esotericsoftware.spine.spine-unity@c658453bb5/Runtime/spine-unity/Components/SkeletonAnimation.cs:187)
Unit.SetUnitData (SpawnerLevelData spawnerData) (at Assets/_scripts/battle/units/Unit.cs:103)

Calling m_skeletonAnimation.initialSkinName = "default";

works on 3/4 but breaks another one of my spine characters. While setting it to "" - breaks the same one as if I don't set it at all.

Sorry to hear the problem persists. Could you then please send us a minimal Unity reproduction project (with a problematic character where it fails) as described above? Then we can have a look at what's going wrong.