nicmar

Hi,
We've successfully managed to do the mix and match setup with various skins to build a character. However, when all skins are unequipped, the character is invisible. Is there a way to setup the default skin to show something? I can't see the default skin in the editor, and I can't create it as the name is reserved. This also leads to the character invisible in Unity and there is no skin I can choose that has all the parts. Do i need to create a "default2" skin to use? :)

The other question i had was if there will be performance issues when changing skins a lot?
We have a 3 way character (up, down, side), and each direction uses a different skin combination.

Here is some pseudo code to show how we're setting it up:
// Define the cache as a dict
private Dictionary<Direction, Skin> skinCache = new Dictionary<Direction, Skin>();

// CacheSkin() method that creates a new skin on scene load, and stores it in skinCache (some code removed for clarity)

......
var skeletonData = skeletonAnimation.skeleton.Data;
var mixAndMatchSkin = new Spine.Skin("custom-chef-side");
var eyeSkin = bodySkin; //"male";
var headSkin = bodySkin; //"male";
var noseSkin = bodySkin; //"male";
var mouthSkin = bodySkin; //"male";

// Make a list of strings with all the attachments we want to copy
var skinNames = new List<string>() {
$"clothes/bottomwear/normal",
$"clothes/topwear/normal-{bodySkin}",
$"head/head-shape/{headSkin}",
$"head/hair/female", // Will only have one hair (male will be deleted)
};

foreach (var skinLabel in skinNames) {
var skin = skeletonData.FindSkin($"{skinLabel}-{direction}");
if (skin != null) {
mixAndMatchSkin.AddSkin(skin);
} else {
Debug.Log("Skin not found: " + $"{skinLabel}-{direction}");
}
}
...

// Then we use this when changing direction to get the correct skin depending on what direction we move in.
var customSkin = skinCache[CurrentDirection]
skeleton.SetSkin(customSkin)
Can you see any issue with doing it like this? Will it work even with 10-15 characters in the scene?

We've looked into the "GetRepackedSkin" features but didn't quite get it to work, but would that also help with performance?

Thanks!
We're making SpaceChef with Spine. An action filled cooking adventure. We're coming soon to Kickstarter, sign up for our newsletter to be the first to get notified: www.spacechefgame.com. Follow our work on Twitter @BlueGooGames.
User avatar
nicmar
  • Posts: 148

Harald

nicmar wrote:We've successfully managed to do the mix and match setup with various skins to build a character. However, when all skins are unequipped, the character is invisible. Is there a way to setup the default skin to show something? I can't see the default skin in the editor, and I can't create it as the name is reserved. This also leads to the character invisible in Unity and there is no skin I can choose that has all the parts. Do i need to create a "default2" skin to use? :)
The default skin contains attachments that are common across all skins. If none are common, it will be empty.

Just take a look at the Mix and Match Spine example project (and the example scene Mix and Match Skins), it contains additional full skins such as full-skins/boy and full-skins/girl which combine multiple of the individual item skins. Alternatively you could also write your own editor script which sets a combination of skins in the Editor.
The other question i had was if there will be performance issues when changing skins a lot?
If you don't repack your skins however, changing them frequently should not be costly as such. Repacking skins often will of course come with an overhead every time you repack.

Unfortunately, as always with performance questions, you're the only one who can give a definite answer to such questions by measuring on the target device, with a scene that matches your target use-case and context.

From looking at your code it seems as if you're using skins to switch between movement directions. Please note that this is not the recommended setup to implement multiple movement directions.

There is a twitch video series by Erika regarding 8-way setup:
https://www.youtube.com/watch?v=eHEHmycdnsM
While it may be too long, it might help to skip over it to get the basic idea.
We've looked into the "GetRepackedSkin" features but didn't quite get it to work, but would that also help with performance?
If you want to use skins for directions, then repacking them each time you change movement direction will likely make things worse.
User avatar
Harald

Harri
  • Posts: 4459


Return to Unity