Forum rules - please read before posting.

Using animating 2D character function in Unity

Hi

I'm a beginner and was told that skeletal animation is more efficient to make than sprite animation.
So I wonder How can I use this tutorial() with AC.

Comments

  • edited April 2019

    Welcome to the community, @dadadodo.

    Skeletal animation is certainly possible with AC - so long as you can play an animation in a standard Animator component, then AC can play that animation back at runtime.

    It is, however, more complicated to set up - particularly if you're a beginner to AC and/or Unity. If you're following the 2D tutorial, I would recommend sticking to regular sprite-swapping at least for the moment - until you're comfortable with using AC.

    Past discussion of using Unity's skeletal animation tools can be found here:
    https://adventurecreator.org/forum/discussion/8382/cannot-play-animations

    Discussion on an integration script between AC and Spine can also be found here:
    https://adventurecreator.org/forum/discussion/4332/spine-integration#latest

    AC's 2D characters work by having their animations/sprites on a "sprite child", which is a child object of the root, and assigned in the character's Inspector's "Sprite child" field.

    For normal sprite-swapping animations, a single Sprite Renderer and Animator component on the sprite child is generally enough. With skeletal animation, however, things get more tricky - since it involves many different GameObjects and a larger hierarchy.

    You first want to make sure that the skeleton/sprite objects all have a shared parent - which itself is a child (the "sprite child") of the character's root, i.e.:

    Root object (Player / NPC component)
    -Sprite child (with Animator)
    --Bone objects
    --IK objects
    --Sprite objects

    Animation should then play correctly.

    What gets even more tricky is when you want a character to rely on a different skeletal animation when facing a different direction. For example, if you want their down-facing animations to involve a different skeleton to their right-facing animations.

    To incorporate that, you need to attach each skeleton type as separate hierarchies, but have them all rely on the same animator, i.e.:

    Root object (Player / NPC component)
    -Sprite child (with Animator)
    --Down-facing skeleton root
    ---Down-facing bone objects
    ---Down-facing IK objects
    ---Down-facing sprite objects
    --Right-facing skeleton root
    ---Right-facing bone objects
    ---Right-facing IK objects
    ---Right-facing sprite objects

    Since this arrangement still only involves a single Animator component, what you can then do is show/hide the different facing directions as part of the animations themselves. For example, when playing "Idle_R" (the right-facing idle animation), you can disable the "Down-facing skeleton root" object - and vice-versa.

    As I say, it's tricky - but possible. Things are more simple if you only have need for one skeleton - but again, I'd recommend going through the tutorial with sprite-swapping to begin with.

  • edited April 2019

    @ChrisIceBox Thank you a lot!! I'll try this and if it's too tricky I'll just go with sprite swapping. Thanks!

  • edited April 2019

    @ChrisIceBox By the way if I want to try skeletal animation, Should I choose Sprites Unity when making Character Wizard? It has Legacy, Sprites 2D Toolkit, Sprites Unity, Mecanim, Sprites Unity Complex, Custom
    It's a silly question but I wonder.....

    +I looked up the manual and chose Sprites Unity..!

  • Sprites Unity is the easiest to use - and the quickest to set up - but Sprites Unity Complex allows for more flexibility.

    If the character only has one skeleton, then you should get be able to rely on Sprites Unity just fine, but it'd probably be wiser to rely on Sprites Unity Complex for a charater with any more.

    This is because with Sprites Unity Complex, you can expose the character's facing direction as an integer in your Animator Controller. You can therefore create a separate layer in your Animator to hide/show the relevant skeleton according to which way the character is facing, without having to incorporate such changes in your standard animations.

  • @ChrisIceBox Thanks! Is it okay if I change it now? or Should I start over to make another project..?
  • I found it can be changed on Animation setting! thanks

  • @ChrisIceBox @dadadodo Just wanted to tag you both to see if the above is still relevant or if anything has changed since then!

    I'm aiming to do skeletal animations and have 8 directions (Three are mirrored).

    Attached a picture in case! https://www.tumblr.com/eccentricstylist/736210718038392832/took-a-picture-outside?source=share

  • Largely so - though a more robust Spine integration can be found here.

    The first things to decide are your choice of animation (Unity's animation system, or Spline), and whether you need a separate rig for each direction or not.

    If you're keeping things simple (Unity + single rig), you could get by with Sprites Unity as your animation engine - but Sprites Unity Complex offers more flexibility should you want to make things more complex in the future.

  • @ChrisIceBox Ah thank you so much! I'm aiming to use Unity's animation package -- do you know if it is possible to have a single rig despite having multiple directions like in the picture?

  • edited December 2023

    I'd say so - particularly since the artstyle's lack of facial features means there are less sprites to deal with.

    What you can try is a mix of bone-based animation and sprite-swapping - i.e. have each direction share the same bone set, but each direction having its own sprite set.

    For example, the left leg would have 5 sprites (down, down-right, right, up-right and up), but they'd all be attached to the same leg bone. As part of the directional animations, you'd then also animate which of these sprites are shown.

    It's a technique similar to the one the devs of Broken Age used - their GDC talk on this process can be found here. The relevant parts are about 6:00-18:00, but the whole thing's an interesting watch.

  • Thank you for the links and the information -- it was very useful!

    I tried this out and it seemed to work for the most part -- I guess my next question is **do you know why the order of each sprite gets set to 0, despite me explicitly setting the order in layer as keys?
    **
    I also made sure all my animations had their order set in as well -- screenshots attached of what I'm referring to if it helps!

    The walk_UR (up-right) animation is playing in the screenshots. Showing you an example of the head object. Left mirrors right btw.

    UR Character:https://drive.google.com/file/d/1R5VWdefNsS-0pDoqaySQZmqwWcph6BsY/view?usp=sharing
    UR Order in Animation: https://drive.google.com/file/d/1jHU7LTgTZmdw9-gymEC3-cLhEgkojc6B/view?usp=sharing
    UR Runtime Order: https://drive.google.com/file/d/19qrcSwS-6r7sTWiRSjgX9VO4wQyQ3IXI/view?usp=sharing

    Additionally -- it seems like my character is moving constantly, from what I can tell -- video attached -- do you know why this may be?

    https://drive.google.com/file/d/1u9mCPc8R10FBvfAOY8bW4QYyQ4dwPoec/view?usp=sharing

    Also on another sidenote -- just wondering if there is a way I can natively upload images here -- I see an Image URL but was wondering if there was another way I can add images directly to the message.

    Thanks for all your help!

  • edited December 2023

    Ah so I went ahead and figured out the sorting things seem to be fixed when I changed the "FollowSorting Map" script to "Offset Original Ordering" and "Follow default sorting". Unsure if this is the correct solution, but just wanted to gather your thoughts in case!

    I'm still facing an issue with character navigation -- tried to include my player settings and the sprite child skeleton as well just in case!

    https://drive.google.com/file/d/1lQU-BvEkGK-Koa42mAYSa_ycj7W0hQtX/view?usp=sharing

  • Unsure if this is the correct solution, but just wanted to gather your thoughts in case!

    If the character follows a Sorting Map that has Affect Character sorting? checked, then yes - the sprite Sorting Orders will be controlled by this at runtime.

    As an alternative to using offsets, though, you can instead attach a Sorting Group component to the same GameObject that has the "Follow Sorting Map" component. When present, only this will be affected by the Sorting Map - any Sorting Order values on your various Sprite Renderers will be unaffected, which should make the easier to manage.

    I'm still facing an issue with character navigation -- tried to include my player settings and the sprite child skeleton as well just in case!

    I can't spot the cause from the videos. We'll need to work out if it's an issue with the character, or the scene/settings.

    Do any Console messages related to the character appear when the scene begins?

    Try removing their Rigidbody 2D and Circle Collider components - they aren't strictly necessary here.

    If the issue remains, temporarily disable your own Player character, and drop in Brain2D, from the 2D Demo, into the scene. He can be found in /Assets/AdventureCreator/2DDemo/Resources - does he have the same issue?

    Also on another sidenote -- just wondering if there is a way I can natively upload images here

    The site doesn't support direct image hosting, but you can embed images from elsewhere by pasting a link into the "Image URL" box. It'll need to be a link to the image file itself - uploading to imgur.com is probably the easiest way.

  • Thanks for the heads up! Will take a closer look at this after work today.

    Just regarding the second half -- looks like Brain2D seems to be working.

  • Ah looks like it's working now! Unsure why, but deselecting "Apply root motion" seemed to work -- thanks for all your help!

  • If Apply Root Motion is checked, AC will assume your movement is handled by the animation itself - so it won't move the character manually. For 2D games this'll normally need to be unchecked.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.