SupaTIM

Hey so I'm trying to have two rigs/skeletons/SkeletonDataAssetsfor a character in Unity.



It's a 3/4s view and a Side view with slightly different rigs. If I had to I could just have the Side View as a skin and change the bones in set up, but at the moment I'm trying to have two separate spine files that I switch between when needed in my script to make it easier on the animators.

So far I'm just switching the SkeletonAssetData:
private SkeletonAnimation skeletonAnimation;
public SkeletonDataAsset threeFourths;
public SkeletonDataAsset sideView;
...
if
(condition where I need to be in side view for an animation) {
skeletonAnimation.skeletonDataAsset = sideView;
}
else {
skeletonAnimation.skeletonDataAsset = threeFourths;
}
...
// FIST
else if (Input.GetButton("Melee P2")) {
if (currentAnimation != "Attack") {
currentAnimation = "Attack";
skeletonAnimation.state.SetAnimation("Attack", true);
}
isAttacking = true;
}
// RUN
else if (Input.GetButton("Horizontal P2")) {
Debug.Log("test");
if (currentAnimation != "Run") {
currentAnimation = "Run";
skeletonAnimation.state.SetAnimation("Run", true);
}
}
// IDLE
else {
if (currentAnimation != "Idle") {
currentAnimation = "Idle";
skeletonAnimation.state.SetAnimation("Idle", true);
}
}
Which is pretty close but when I switch the SkeletonDataAsset, the animation I set directly after doesn't play, like if I'm in "Idle" and I move right, it switches to Side View but "Run" won't play.

The animation I set after that will work if it's in the same view, like if I'm in "Idle" and jump it'll play the "Rising", "Falling", and "Idle" animations correctly, even if I just switched from Side to 3/4s view and have a the "Idle" animation not playing, jumping will cause the animations to work again if they're in the same view.

If anyone has an idea of how to fix this so the animation plays, how to switch the SkeletonDataAsset properly, or a more effective way to have two rigs on a character I'd love some help. I've pretty much been guessing so any insight would be great.
SupaTIM
  • 記事: 2

Nate

Ready to get familiar with the Spine object model? :nerd: SkeletonDataAsset provides a SkeletonData. SkeletonAnimation extends SkeletonComponent which has a Skeleton which has a SkeletonData. SkeletonAnimation has an AnimationState which has an AnimationStateData which has a SkeletonData. If you change the SkeletonAnimation's SkeletonDataAsset the Skeleton and AnimationStateData will still be using the old SkeletonData, so strange things might happen.

You could have a single gameobject that swaps the SkeletonDataAsset, Skeleton, and AnimationState. Or, you could have 2 gameobjects and switch between them.
アバター
Nate

Nate
  • 記事: 9730

SupaTIM

Awesome! Works perfectly, thanks for the insight!
SupaTIM
  • 記事: 2


Return to Runtimes