- Изменено
Change skeleton data asset at runtime
Hi there, I'm developing a game in which the main character has two modes. A small size, and big size (check photo). And in both of them, the animations are all the same name, all the same parameters and the same code controls them.
I have achieved the switch I'm looking for, but it causes a small spike in performance each time it is called, and I'm wondering if there's a way to do it better without the performance loss.
Preview:
The code I'm using to make it work is this:
if (playerInput.Spider())
{
if(skeletonMecanim.skeletonDataAsset == BigNeon)
{
skeletonMecanim.skeletonDataAsset = SmallNeon;
skeletonMecanim.Initialize(true);
animator.runtimeAnimatorController = animatorControllerNeonSmall;
}
else
{
skeletonMecanim.skeletonDataAsset = BigNeon;
skeletonMecanim.Initialize(true);
animator.runtimeAnimatorController = animatorControllerNeonBig;
}
}
Any help is appreciated!
Hey AHAKuo, cool character :grinteeth:
Two options that you could try:
1) Have two SkeletonMecanim components - one for each version of the character. Then enable one and disable the other as needed when the character switches forms.
2) Combine both versions of the character into a single Spine project (skeleton), and use Skins to switch between the two. Note that Skins can have their own bones: Skins - Spine User Guide: Skin bones