• Unity
  • Changing the SkeletonDataAsset at Runtime

We have a SkeletonGraphic object that contains the player's avatar. Due to the 1 material limitation of the SkeletonGraphic we had to split it into Male and Female (with skins).

Now we're displaying the player avatars in little boxes and are swapping them out when their turn rotates and I'd really prefer not having to use two GameObjects and turning them on and off but rather swapping out the SkeletonDataAsset. But I'm having a hard time figuring out what functions to call and in what order...

So if I have the name of the new base skin (e.g. "female_body1") what do I need to do to accomplish this?

Related Discussions
...

If you really want to switch SkeletonDataAssets, this can be done like this:

public SkeletonDataAsset otherSkeletonDataAsset;

void SwitchSkeletonDataAsset() {
   SkeletonGraphic skeletonGraphic = this.GetComponent<SkeletonGraphic >();
   skeletonGraphic.skeletonDataAsset = otherSkeletonDataAsset;
   skeletonGraphic.initialSkinName = "YourNewSkinName";
   skeletonGraphic.Initialize(true);
}

However I would recommend enabling/disabling GameObjects, as you then only initialize once at startup.
Another simpler solution: Have you tried increasing atlas images size so that both characters fit into a single atlas page?

Unfortunately Spine file is to big to fit onto a 4096x4096 texture, c'est la vie...

The step I was missing was the skeletonGraphic.initialSkinName, thanks for the info!

I did end up using two GameObjects and disabling/enabling the SkeletonGraphic based on the Avatar's gender as this was blocking me from continuing my work yesterday. Thanks for the reply though!