Forum rules - please read before posting.

2D Sprites Unity 2D: Layered Animation Query

edited April 2016 in Technical Q&A
Hi guys,

I'm wondering if someone can help me, I'm creating a sprite based adventure game using the Sprites Unity mode and am trying to implement layered animations to allow a little bit more flexibility with character movements, facial expressions, etc.

Currently I've set up an NPC so that the main body is on one layer (the sprite child), with a separate sprite for the mouth/lower jaw and eyes/forehead sections of the head, nested as children of the sprite child. The idea is that we can switch out the head sprites to allow the characters to talk/have different expressions whilst leaving the rest of the body free for other anims.

I've created a talk cycle for the lower jaw but can't for the life of me work out how to configure it between AC and the Animator Controller. I've tried putting the Talk anims on a separate layer, but in this case they don't seem to be called at all and if I put them on the base layer, the talk cycle will replace the character's body, leaving a mouth talking beneath a disembodied head.

I'm sure there's something very simple that I'm missing and have spent hours looking through the Unity documentation, AC documentation and various YouTube tutorials to try and find a solution, but nothing I've found quite seems to fit. It's occurred to me that I could play and stop the custom animation after every dialogue line but surely there is a more simple way?

Any help would be very much appreciated!

Cheers!

DB

Comments

  • Sprites Unity is generally only intended for the most simple of 2D characters - putting ease-of-use over capability.  What you want is Sprites Unity Complex - this gives you far greater control over your character and is recommended if you want to make use of multiple layers.

    Sprites Unity Complex is very similar to the standard Mecanim workflow - instead of defining standard animations to play, you instead create your Animator controller the way you want, and then define parameters that AC can then control (e.g. a "Move speed" float, an "Is talking?" bool).  These parameters are layer-independent, so you can use them to control your Animator Controller however you like.  See section 3.9 of the Manual for more.
  • Okay thanks Chris, I'll give Sprites Unity Complex a go and report back if I have any issues,

    Best,

    DB
  • Hi Chris,

    Can you confirm how the nesting for the sprites should work for Sprites Unity Complex please? Currently I've got it set up so that there is a game object with the NPC component, etc. attached to it, then under this I have an empty game object with the animator component on it (my "sprite child") and a "follow sorting map" component. Then nested under that I have the different layer sprites, each with their own sprite renderer and appropriate sorting layer specified. The "follow sorting map" component on the sprite child is set to follow default sorting map, offset original order and also affect children.

    When I play the game, I can see the animations triggering in the animator, with the exception that it appears to have left and right mixed up, (left being triggered when the Direction parameter is set to 1 & right when it's set to 2). However, the animations aren't visible in the game window, the sprites just remain in their idle state. The clips are all hooked up as far as I can see and they appear correctly when viewed outside of the game. In the animator, the layers are set to override, with a weight of 1.

    I've tried various things including giving each sprite it's own follow sorting map component, nesting the sprites on the same layer as the "sprite child" (though I'm sure this is incorrect) and changing the animation settings, but all to no avail...

    Any thoughts?

    Thanks!

    DB

  • Having a single FSM component on the sprite child rather than one on each sprite is definitely the recommended of the two.  However, I'd remove them completely until you've gotten your standard animations playing because it only complicates things further.

    If the correct animations are playing in the Animator window, then it sounds like AC at least is doing it's job properly.  My first instinct woud be to check the animations themselves are working - if you remove the NPC component to "free" it from AC, do they then play when you set the Animator parameters manually?
  • Hi Chris,

    I set the character up in an empty scene, removed the FSM component and the NPC script. Changing the parameters manually successfully triggers transitions through the state machine at run time, although the animations don't play. So it does look as though the parameters are updating correctly, although it does still confuse left (Direction = 1) for right (Direction = 2).

    Can you confirm that my setup sounds correct, please? As mentioned the objects are nested such that there is a dummy sprite child without a renderer (according to the AC manual this ought to be a viable option), with the separate layer sprites listed underneath. When I try to view the animations in the animation window, it tells me that the sprite is missing, whichever one I select, although the child objects are all still referencing the correct sprites and I can see the animations in the window. I would assume this notification is because the object that the animator component is on doesn't have a sprite renderer component.

    I've tried shifting the nesting around, but if I make the body the parent object, then the body gets replaced by the other body part animations. Would you be willing to take a look at the project for me? Sorry to be a pain but I've been trying to get to the bottom of this issue for weeks now, I've trawled through the Unity documentation (which seems pretty sparse on this subject), and it's the last major system I need to get worked out in order to proceed. Any help you can provide would be very much appreciated!

    Best,

    DB
  • This continues to sound like an issue with your animation / Unity set-up, because - as you say - the animations don't play correctly even with AC removed from the equation.  While all sounds OK in principle, you haven't shown any screenshots or videos showing what you've done.  If Unity is giving you notifications, better to not dismiss it as it could be the clue you need.
  • Hi Chris,

    I actually managed to get to the bottom of the issue over the weekend, it's not working 100% as I wanted but it's the next best thing at this point.

    It was all to do with the state machine set up and how I'd done my anims in the end. The implementation I've gone for now is to have the body sprite as the sprite child with the two head parts nested underneath. Each body section is animated in separate clips and on a separate layer in the anim controller, but set up as Additive and Synced. I would have gone for Override as I wanted to have separate state machines for each body part to allow me to mix and match say angry eyes with talking mouth, but when I set it up I couldn't stop all of the layers triggering at once so the uppermost layer just overwrote the others constantly (or didn't play at all with a weight of less than 1). I don't suppose you've got any tips on that have you?

    Also I think I worked out why only the Left anims were displaying as triggering in the state machine, despite the characters playing left and right animations correctly. Initially I had the character set up as Unity Sprites with Frame Flipping enabled, so I was wondering if the setting might have remained as true despite me switching it over to Unity Complex and if AC was just flipping the sprites at runtime rather than using the right facing animations? Just a thought, it's not a big deal as it's working but thought it might be of interest.

    Anyway thanks for your advice, as ever it's very much appreciated,

    Best,

    DB
  • Glad to hear it.  Unfortunately I don't have too much advice so far as how you set up your layers is concerned: the intention behind Sprites Unity Complex is to empower the user with greater control, but of course this means that how it's used exactly is going to vary based on the character's needs.

    I'm not understandng too well what your issue with the frame-flipping is - screenshots would help clarify.  However, the feature works by changing the inverting the x-scale of the sprite child - so you may have trouble if you control the scale through animation also.
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.