Forum rules - please read before posting.

Sprites Unity Complex using Animation 2d bones

I'm trying to use bones based animation for my characters. I read on the form that using Sprite Unity Complex is the preferred method while working with bones, but I'm not sure about one particular issue. My characters can move in 6 directions (R, L, UR, UL, DR, DL), so I need to create 6 (or 3, if I can flip them) different skeletons and 6 different set of sprites.

The question is: can I manage the 6 directions with 6 different PSB files, or am I forced to place all 6 in the same PSB and turn on/off sprites and bones via animations? Is there a "proper" way to go about this? I'm afraid that having all 6 directions in the same file will be a pain to rig and animate, since layers hierarchy is always flattened when importing in unity.

I found this thread on the same topic but it's not clear to me if the OP needed multiple directions (beside R and L) like I do, or not.

thanks!

«1

Comments

  • A script that provides the ability to use frame-flipping with Sprites Unity Complex characters can be found here:

    https://adventure-creator.fandom.com/wiki/Frame-flipping_for_Sprites_Unity_Complex_characters

    You don't need to have each direction's graphics be a separate file - Unity will source the sprites from whichever files they're in, which can be shared or separate.

    When it comes to the rigging, there's a couple of approaches you can take. It's not so much a case of which one is "best" in the general sense, but more about which one is right for you and your situation:

    1. Use a separate rig for each direction, and enable/disable them as necessary.

    This approach will make your Hierarchy a bit more cluttered, but is generally a bit easier to work with. For a given rig, each bone will generally be associated with a specific sprite the whole time - so you can concentrate on just working on animating the bone rotations without dealing with sprite-swapping as well.

    1. Use the same rig for all directions.

    This is harder to set up, but will be the more efficient approach on a technical level. For each direction, you'd need to animate each bone's associated sprite as well as their rotation (so e.g. the Head bone's sprite is showing Head_R when moving right, Head_DR when moving down-right etc). The sprite-swapping could feasibly be done on another layer in the Animator, to avoid having to update them as part of the standard idle/walk etc animations.

    This is also the approach that Broken Age took, though that involved creating rigs in separate 3D software rather than animating them inside the engine.

  • Hi Chris,
    thanks for the answer. I was actually thinking about implementing solution 1. By playing around with Sprite Complex Brain I think I'm getting an idea of how I could structure the character in order to work with bones without creating a mess.

    I still have few issue though, and it seems I'm blocked:

    1) I tried following Brain's example and use the angle parameter in a blend tree to determine the right rig to show. No matter how I divide the angles, it always seems that at least two rigs get activated at any time, instead of just one. No idea if it's an issue of the blend tree states overlapping, or the way I hide/show the rigs in the animation

    2) The sprites order of the PSB get always messed up during animations (even in preview). I tried even excluding "follow sorting map" but it doesn't seem to have any effect. I can't imagine where the issue lies

    If it's useful, I uploaded the prefab + assets for the character I'm trying to build. The model and animations are super crude but they're just to give an idea

    https://www.dropbox.com/s/z319kk6tl4xi6pm/test-character.zip?dl=0

    any feedback is welcome
    thanks again

  • The package is missing the nested prefabs that hold the bones, but if you're having issues with the Blend Tree and angle parameter, try using the Direction integer and transitions instead. A Blend Tree is designed for properties that can blend between values, rather than just either on/off.

    Though, it would also be possible to set the rig enabled states solely through code based on the angle, which can be read from the character's GetSpriteAngle function.

    As for sorting issues, with updates to Unity's sprite system it's no longer necessary to rely on AC's Sorting Map for 2D sorting - you can just use it for character scaling. You can attach a Sorting Group to the character's root to have each sprite's Sorting Order be relative to one another, without affecting the overall Sorting Order relative to other objects in the scene. The new 2D Primer covers how to prevent the Sorting Map from affecting sorting orders here.

  • edited August 2022

    Hi Chris,
    I solved the sprites overlapping in the wrong order by removing and re-including them in the scene. No idea what happened to mess them up, but apparently it wasn't related to the sorting map.

    For the animations, I followed your suggestion and tried to implement everything just with transitions. I made 2 layers in my animator: one that listens to the Directions and uses 6 animations that just turn off/on the correct rig; and another layer that listens to Speed to manage the idle/walk/run animations. It works ok, the only doubt I have is that I had to "merge" all animations of the same type in a single one. So for example I don't have anymore idle_L, idle_UL, idle_DL etc, but I have just a "idle" that animates all the bones in all the rigs. This makes managing the animation window a bit of a pain because of the amount of bones (I can turn off the rigs from the inspector window to hide them from the scene, but the animated properties in the animation window will still clutter everything), but I can live with that. Do you think this a sensible/scalable solution for a rigged character?

    I still have a small problem that might be related to AC: when the character talks, the subtitles appear above their feet instead of above their head. I think this is because the character doesn't have a sprite renderer: in fact, the only way around this that I found is to add a sprite renderer and attach an image of roughly the same size of the character, and turn its transparency up to hide it. It feels hacky, so if there's another way to fix it please advise. This is the structure of my character object so far (few directions still to do)

    thanks!

  • Do you think this a sensible/scalable solution for a rigged character?

    It does look troublesome to deal with like that. This would be more feasible were you using sprite-based animations, but if each direction uses a separate rig it is going to get messy quickly.

    I'd personally probably look into the single-rig approach, but going back to the separate rig/animation approach, I'd say it'd be worth looking into moving each of your idle/walk animations to direction-specific layers, each with their own Idle -> Walk transition. Your "BodyDirection" layer could probably be moved to the base layer, effectively flipping the ordering.

    the subtitles appear above their feet instead of above their head. I think this is because the character doesn't have a sprite renderer

    That's right - AC will try to use a Sprite Renderer to "guess" where that character's subtitles should appear. If it can't find this component, or you want it moved, you can correct this by positioning a child object in the character's Hierarchy and assigning it in their "Speech menu placement child" field.

  • worth looking into moving each of your idle/walk animations to direction-specific layers, each with their own Idle -> Walk transition

    I'll look into that. I guess that ultimately it's a choice between having clean animations with cluttered animator controls, or cluttered animations with clean animator controls

    The speech placement did the trick. Thanks for all the advice!

  • edited June 2024

    I have a noob question, but I am also working with Sprites Unity Complex using bones and will need to either

    1. use different rigs that switch based on direction
    2. put everything in a single rig and turn on/off specific sprites

    as you suggested above, Chris.

    I managed to implement parameters to change basic walk/idle animations, but I have no idea how to Turn on/off specific rigs in Animator based on the direction the character walks as suggested in 1) or how to turn On/Off sprites if I chose to go with 2) (i can do that in AL, but how do I put that in the Animator?). When I open the Animator blend tree, I can only select specific animations for directions, but they are assigned to the basic rig. Plus i can set a parameter condition in the transitions between states, but i cannot seem to find anything more.

    The character will walk in 8 directions; so far, I have him walk only left and right (using the mirroring script).

  • It depends on what approach you want to take, but the turning on/off of your sprites (or entire rigs) would be part of the animations that get played.

    For example, the "Walk_L" animation could turn on the left rig, and turn off the up/down rigs.

    You can also create multiple Blend trees in the same base layer, e.g. Motion_L (that handles Idle_L/Walk_L), Motion_U etc, and then use the Direction integer to transition between them.

    The other approach would be to use sub-layers to control these aspects - i.e. a "Rig" layer could use the Direction integer to transition between differenet animations that turn on/off the intended rig, while the Base layer has a single Blend tree that animates all rigs at the same time.

  • For example, the "Walk_L" animation could turn on the left rig and turn off the up/down rigs.

    But how would I technically do it? Would I create an Animation event with an Action List in the first frame of the animation? Is there such an action that switches rigs?

    I struggle to understand how I invoke the rig change in the Animator. I just don't know through what functions/buttons. The only thing that comes to mind is through some action.

  • This isn't involving AC, just Unity's animation tools. There's no need for Actions / events.

    You can animate a GameObject's "enabled" state within the animation clip itself.

    When creating your animations within the Animation window, and "record" mode is on, try disabling any child object in the Animator's Hierarchy - you should find that this change gets recorded in the animation.

  • Thanks for the advice. I am finally trying to get the multiple rigs working, but I have an issue with how to place the various rigs into the Player prefab hierarchy. I thought I could just place them as children of the Sprite Child, but when I do that, the animations do not play. If I just set one of the rigs directly as the Sprite Child, the animations work properly. The extra child object between the Sprite child and the Bones and sprites of the rigs seems to be an issue (but I need it so it won't all become a huge mess of bones and sprites, often with the same names). What should I do to make this work, please?

    Here is my setup:

    The hierarchy of the Player prefab, one rig expanded:

    Player prefab Inspector with set Srpite Child:

    Sprite Child Inspector:

  • Are you moving the objects in the Hiearchy after creating the animations?

    Unity requires that the Hierarchy remains as it was when the animations are created - you can't move the objects after the fact and have the animations still play.

    So long as the Hierarchy is as you want it before you start animating, however, it should work - the Animator component is on the parent object, so it can control any object beneath it.

    I thought I could just place them as children of the Sprite Child, but when I do that, the animations do not play. If I just set one of the rigs directly as the Sprite Child, the animations work properly.

    What's the exact change you're making here?

  • The animations were made before I created the hierarchy, but the names of the specific rigs remain exactly the same (bok, predek, etc.) They were only moved under the "Hrdina rig" parent. On runtime, it just shows a static image of all the specific rigs instead of animations (I will deal with turning the rigs on/off later). The children with specific rigs (bok, predek, etc) have no components attached to them.

    What's the exact change you're making here?

    If I set the specific rigs (bok, predek, predni poloprofil, zadni poloprofil) as the sprite child instead of the "Hrdina rig", it works well, and the animations play.But I need multiple rigs in the Player prefab. If I place all the rigs under the parent sprite child "Hrdina rig" as is in the current setup, it doesn't work.

    So do I need to redo the animations now? Isn't there a simpler way?

  • If I set the specific rigs (bok, predek, predni poloprofil, zadni poloprofil) as the sprite child instead of the "Hrdina rig", it works well, and the animations play.

    Do they each have their own Animator components? Or were the animations created for the "Hdrina Animator Controller" asset?

  • Currently, they didn't. I thought the Sprite Child "Hrdina Animator Controller" would be enough. I just created the Animator component for the "bok" and uploaded its original animator component file there and the animation is playing!

  • I thought the Sprite Child "Hrdina Animator Controller" would be enough.

    It normally should be - provided the animations are all correctly referencing the GameObjects.

    You can try viewing the Animation window for your animations, from the Hrdina rig object, to see if referenced objects are missing - but this sounds to do with Unity's animation workflow rather than one specific to AC.

    As you're relying on the Sprites Unity Complex animation workflow, however, you could use scripting to copy over the Hdrina controller's parameters to each of your "child" animators, and then just have Hdrina affect the visibility of each rig.

  • edited August 2024

    They are indeed marked as missing. So next time I create animation, I should make it with the same hierarchy system, for example: Hrdina rig/Specific rig1, right?

    Is there a way I can fix the "missing" error? Like manually setting the correct path or fixing the hierarchy?

    Also, I have another problem. Because of my current Hierarchy setup, I cannot turn on/off the rigs within the animation, and I have to create an animation event with an action list where I specify this rig object instead. But that does not work for a prefab (the specified objects turn missing). Can I fix this somehow?

    Or is the easiest solution that I just put all the rigs into one parent folder. Add the animator component to this parent and then turn on/off the children with specific rigs while making specific animations?

  • You'll need to use the same Hierarchy when playing your Animations that you used when creating it.

    Is there a way I can fix the "missing" error? Like manually setting the correct path or fixing the hierarchy?

    Not that I'm aware of, though you can try Unity's Discussions pages as this is a general Unity topic.

    Because of my current Hierarchy setup, I cannot turn on/off the rigs within the animation, and I have to create an animation event with an action list where I specify this rig object instead. But that does not work for a prefab (the specified objects turn missing). Can I fix this somehow?

    You can enable/disable GameObjects as part of an Animation clip - provided those objects are below the Animator in the Hierarchy.

    The Hierarchy in your screenshot from yesterday should allow for this - the Hrdina object can control the enabled state of its child objects bok, predek etc. Animations aside, the way your Hierarchy is shown there looks correct.

    If your animations were made from each of the rig children, then you'd either need to rebuild them from Hrdina, or have Hrdina's Animator simply control which rig object is enabled, and use scripting to transfer its Speed/Angle etc parameters to each of the children. I'd recommend the former, however, as you'd have trouble transferring custom animation state names otherwise.

  • Thank you very much for all the advice, I will rebuild them in the correct hierarchy - it seems like the simplest solution. Fortunately I didn't make that many of them yet.

  • I have one last issue that arose from rearranging the Hierarchy in the correct way. Before, I had one animation that was applied to three different rigs, which was great as it saved me a lot of time and work. This was not a problem when the rigs were "standalone". But now, when they are placed as children and the controller is on the parent, the path to the rig's bones and sprites is different (although names are the same).

    My question is, is there a way to copy animation from one rig to another in this hierarchy arrangement? I tried control+c/v inside the animator, but it always copies the specific path to the original and is not connected to the elements in the rig I'm copying into.

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.