Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Question Exploring Sprite Swap possibilities

Discussion in '2D Experimental Preview' started by Jaime97, Apr 29, 2022.

  1. Jaime97

    Jaime97

    Joined:
    Aug 1, 2017
    Posts:
    10
    Hello!
    I am trying to use sprite swap in my skeletal animations and I have some doubts:

    First of all, I have been trying to use this functionality to simulate 3D effects in my animations:

    first_image.png

    In the image you can see that the soldier has two right arms, one seen from the outside and one from the inside. My idea is to use this functionality to alternate between one and the other in the middle of an animation, and thus better simulate the movement (I intend to do the same with the shield).

    However, when swapping the sprites the arm is totally deformed, so I don't achieve my goal:

    second_image.png

    I have added the Sprite library and Sprite resolvers for each part of the arm:

    third_image.png

    fourth_image.png

    What am I doing wrong? Should the sprites be influenced by the same bones? can one alternative have more bones than the other? I have seen that it can in the hand example, but I can't replicate the behavior.

    My second question is about the reuse of this skeleton, to reuse its animations. I have seen in another example that I can completely replace the Sprite library with another one, but I had some more specific questions about it:
    - If, for example, I wanted to reuse this skeleton in another soldier that did not have a shield or helmet, and therefore did not use some of the bones that the image example uses, would that be possible? Or would they all have to have exactly the same components?

    Thank you very much for all the help!
     
    lexlegs likes this.
  2. Ted_Wikman

    Ted_Wikman

    Unity Technologies

    Joined:
    Oct 7, 2019
    Posts:
    916
    Hello @Jaime97

    Here is the sample you were talking about:



    In this sample, we have two Sprites (R_arm_1 and R_arm_2). If we open the Skinning Editor, we can see two things:
    1. The two Sprites share bones (bone_13 for example), but R_arm_1 (with the hand open) is skinned to a few more bones (bone_54, bone_55 and bone_56).
    2. The Sprites are positioned in a neutral pose with the bones laid over them.

    A third (and more difficult thing to spot) is that the two Sprites have all the same bones associated with them.


    Because we have the same set of bones associated with the two Sprites, when we swap between R_arm_1 and R_arm_2, the Sprite Resolver already has the list of bones needed to deform the two Sprites. The Sprites are also laid out on top of each other, with the bones running over them. This is to make sure that any bone rotation needed for one Sprite won't distort the other Sprite if swapped while the bone is in an extreme rotation.

    Looking at your bone structure and the result, it looks like either the Sprite Resolver cannot find the correct bones to use for deformation after swapping, or the Sprites have some of its vertices skinned to a bone it shouldn't be skinned to.

    For your second question, could you clarify what you mean with "Skeleton"?
     
  3. Jaime97

    Jaime97

    Joined:
    Aug 1, 2017
    Posts:
    10
    Hello @Ted_Wikman

    Thank you for your answer.

    I have checked and the sprites are not skinned to any bones they shouldn't be. What I wasn't doing was having both sprites influenced by the exact same bones, but I've corrected that now:
    bone_influence_2.png
    bone_influence_1.png

    However, I'm still experiencing the same behavior:
    bone_influence_4.png

    bone_influence_3.png

    These are the 3 bones:
    bones.png

    I also see that you talk about the position of the two sprites, do they have to be positioned in the exact same place or have the same proportions for it to work?

    As for my second question, with skeleton I mean the bone structure that is associated to the sprites and that I use to create animations. I was asking if using this skeleton I could replace the Sprite library to be able to reuse the animations in another soldier, but that this one for example would not have a shield (and therefore some of the bones would be unused or would not move any sprite).
     
  4. Ted_Wikman

    Ted_Wikman

    Unity Technologies

    Joined:
    Oct 7, 2019
    Posts:
    916
    Thanks for sharing the screenshots. In the current version of 2D Animation, the bones also have to be in the same order for the two sprites (this has been fixed in 2D Animation 9.0.0, Unity 2022.2). If you re-arrange the bones in the Bone Influence list (you can drag and drop the bones to change their order in that list), it should start looking better.

    This step is more for ease of animating. Lets say you have two Sprites mapped to the same bone, but the Sprites are either far away from each other, or different sizes. When you move the single bone it might be difficult to control it accurately and achieve the motion you are after.

    Thanks for clarifying your second question. Yes, you should be able to swap to a different Sprite Library while still using the same bone structure, as long as the bone structure is the same. If you have a different bone structure, you would need to enable the "Auto rebind" flag on the Sprite Skin component. Have a look at this post to get some more insight into how Auto rebind works. This flow as been greatly simplified in 2D Animation 9.0.0-pre.1 (for Unity 2022.2), where toggling "Auto rebind" while having the root bone set to the root of the character, will find the required bones, no matter where they are located in the hierarchy.
     
  5. Jaime97

    Jaime97

    Joined:
    Aug 1, 2017
    Posts:
    10
    Hi @Ted_Wikman,

    Reordering the bones in the influence list has finally corrected the problem! Right now it is working exactly as I expected, I think I can animate it as I intended.
    As for the second question, I appreciate the information, I will try to set up a working example of my own making use of this Auto rebind and get back here with the results.

    Thank you very much for the help and for responding so quickly.
     
  6. Ted_Wikman

    Ted_Wikman

    Unity Technologies

    Joined:
    Oct 7, 2019
    Posts:
    916
    Happy you managed to resolve the issue! Best of luck with your project!