• Editor
  • Choosing between 2 animations in spine/unity

Hey Guys, i am stucked in a problem. I have made animations of different tasks of a game. Like if you click on a button then the animation happens. For Example :- Build House, Build Fountain etc. You can find many examples of these animation in games like Gardenscapes, Domino Dreams and Royal Match.

The problem is how to create animation that let you choose between 2 animations without affecting other. For example there are 8 animations like these:-

  1. Build Coffee House
  2. Build Table & Chairs
    .....................................
  3. Rebuild Fountain
  4. Start Fountain
    .....................................
  5. Build Clock Tower
    .....................................
  6. Build Ice Cream Cart
    .....................................
  7. Set up Market
  8. Decorate Market
    .....................................

Now the problem is that the "4. Build Ice Cream Cart" and "2. Rebuild Fountain" are optional. Means you can either click on any of these 2 tasks in game. So, how can i make these animations happen in unity.

  • इस पर Harald ने जवाब दिया।
    Related Discussions
    ...
    • संपादित

    anaskhan The problem is how to create animation that let you choose between 2 animations without affecting other.

    I'm afraid I don't understand your question and your listed example. What do you mean by "create animation that let you choose between 2 animations"? And regarding "without affecting other", how is it affecting other animations?

    In general you start animations via skeletonAnimation.AnimationState.SetAnimation() or enqueue it via AnimationState.AddAnimation(). Or when using SkeletonMecanim, normal Unity guidelines for the Mecanim Animator Controller apply, triggering the respective animation transitions via Animator parameter changes. Your game logic code should determine which animation is to be played at which time. E.g., a button press results in certain game logic events which then modify game state, and the game state modifications should then trigger the respective visual representation updates, including playing matching animations.

    • anaskhan ने इसे लाइक किया।

    I have used different bones in spine. The problem is of slots visibility. If i am doing animation of fountain, should i have to open/visible other slots or not. In first export i have opened other attachment slots in every animation which were not animating. Then my programmer said that i should give him the animations only by enabling slots of that animation only and hiding other slots but this is not working, even when i am mixing the animations in spine. The slots of previous animation disappear.

    I also have a different file where i didn't hide other slots in each animation. Instead i just animated the object of that task. This file is mixing greatly in spine editor preview. I think this is the file that will be used. If that's the case then my programmer don't know how to execute this. So please tell me that how can i program these animations that they will only appear when we press that button and before that they become hidden.

    @anaskhan Thanks for the additional details! Now I think I understand your problem better.

    In general if you want animation completely independent and not affecting another, it's probably the easiest and cleanest solution to use separate SkeletonAnimation objects for each building type. Then each one is just playing animations for a single building type and automatically does not interfere with other building's animations.

    If you really need to cover multiple building type animations in a single SkeletonAnimation GameObject, the following rules apply:

    • Slot visibility itself can't be keyed, it's the slot's attachment's visibility which can be keyed as visible / invisible in animations.
    • Whenever an animation is keying attachment visibility as "visible" or "invisible", it will override the visibility state set by any lower tracks. Track 1 overriding track 0. track 2 overriding tracks 1 and 0.
    • When an attachment is keyed by an animation, as soon as the animation ends and mixes to a different animation or the empty animation, it will mix out and properties keyed in the previous animation transition to the value from lower tracks, or to the setup pose value if no lower tracks key the property.
    • There is a big difference between keying an attachment as equally visible as in the setup pose compared to not keying it at all. It may look the same in the Spine Editor when playing a single animation, but when keyed and played on a higher track, it will override lower track visibility. Thus only key attachment visibility if your animation needs to change attachment visibility. E.g. don't key everything in the first frame of your animation.
    • anaskhan ने इसे लाइक किया।

    @anaskhan Also please be sure to disable Animation Cleanup in your Skeleton Export settings, otherwise keys identical to the setup pose will be removed.

    • anaskhan ने इसे लाइक किया।
    • संपादित

    Thanks for the help.

    "In general if you want animation completely independent and not affecting another, it's probably the easiest and cleanest solution to use separate SkeletonAnimation objects for each building type. Then each one is just playing animations for a single building type and automatically does not interfere with other building's animations."

    In this case, if completely independent SkeletonAnimation objects are created, frame rate degrades drastically as the objects increase in unity.
    For example, creating one object affects around 15 frames, so creating more than 2 will effect the game execution.

    • इस पर Harald ने जवाब दिया।

      anaskhan For example, creating one object affects around 15 frames, so creating more than 2 will effect the game execution.

      By "affects around 15 frames", do you mean that your FPS count is lowered by 15 FPS for a single additional object (if so, what is your FPS base, e.g. 30, 60 or 300?)? Then I would assume something is going wrong. In general, dynamic batching should combine your meshes when they are using the same Material (and Texture). How many draw calls / batches do you see with a single object vs two separate objects?

      • इस पर anaskhan ने जवाब दिया।

        Harald
        Yes, I am referring to FPS count, FPS Base is 60.
        With multiple objects, Batches remain same that is 3, the changes are in Triangles and Vertices.

        • इस पर Harald ने जवाब दिया।

          anaskhan With multiple objects, Batches remain same that is 3, the changes are in Triangles and Vertices.

          This is surprising then. 🙂 Are you perhaps setting attachments to transparent (color alpha = 0) instead of disabling (hiding) the attachments? If so, this will not remove the attachment vertices. This is because you could use a custom shader which utilizes vertex color alpha value for different things than transparency.