Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

2d Skeletal Animation: change bone depth during animation?

Discussion in '2D' started by aromana, Jan 17, 2021.

  1. aromana

    aromana

    Joined:
    Nov 11, 2018
    Posts:
    137
    Hi, I am using Unity's build in mesh/skeletal rigging system. I understand how to specify the depth/draw order of a bone while editing the rig in the Sprite Editor, however, I am wondering how I can do this during an animation.

    My use case is straightforward: during some animations need to draw bones over other animations, but not others. For example, while idle, character arms should appear at the side and not over the chest. However, while walking, the arms should swing and be drawn over the chest.

    Any ideas?
     
  2. Leo-Yaik

    Leo-Yaik

    Unity Technologies

    Joined:
    Aug 13, 2014
    Posts:
    434
    Are they on the same sprite?
     
  3. aromana

    aromana

    Joined:
    Nov 11, 2018
    Posts:
    137
    Yes, the same sprite. I ended up working around this by using a separate sprite and “hiding” bones by setting with scale to 0. So I don’t actually change the depth... I just hide the bone and replace it with a completely different sprite drawn on top of the whole skeleton.

    That’s a hack of course, so if you can suggest a better solution I’d greatly appreciate it!
     
  4. Ted_Wikman

    Ted_Wikman

    Unity Technologies

    Joined:
    Oct 7, 2019
    Posts:
    876
    If your Sprites are separated, you could animate either Sorting Layer or Order in Layer to change the depth of a sprite in an animation:



    However, there are no current ways to change the depth of a bone in an animation.
     
  5. aromana

    aromana

    Joined:
    Nov 11, 2018
    Posts:
    137
    Got it, thank you for the confirmation and help. Using separate sprites is indeed what I'm doing now. The drawback to that approach is that it means I can't tie the asset into the same sprite library (e.g. "red pig"), even though "conceptually" they're part of the same asset ("red body" and "red arms").
     
    takanaryota likes this.
  6. Ted_Wikman

    Ted_Wikman

    Unity Technologies

    Joined:
    Oct 7, 2019
    Posts:
    876
    Could you walk me through the sprite library issue? I don't fully understand the problem
     
  7. Ary-Guilherme

    Ary-Guilherme

    Joined:
    Feb 27, 2018
    Posts:
    3
    The problem is, when we use a tileset with all sprites in the same image file, we cant change the depth of sprites individualy during an animation, I believe that is the most critical error of 2D animation system.

    But we can separate the tileset in separated sprites to make an animation, changing the sorting layer ID of the sprite individualy, but it is worst and require to spend more time!
     
  8. Unrighteouss

    Unrighteouss

    Joined:
    Apr 24, 2018
    Posts:
    599
    It would be cool to be able to animate bone depth, but you can use the PSD Importer to easily bring in a bunch of different sprites. This automatically splits up the sprites into separate objects so you can easily animate their sorting orders.