Search Unity

[Release][Free] Unity Sprites And Bones - 2D skeleton animation

Discussion in 'Assets and Asset Store' started by TheRealBanbury, Dec 29, 2013.

  1. playemgames

    playemgames

    Joined:
    Apr 30, 2009
    Posts:
    438
    Wish I had the time, you are right though, writing up documentation is a pain and unless someone is willing to pay me to do it, I'll do it whenever I can get around to it. You can look through the thread, some people have already compiled some things http://www.4shared.com/office/x8IOTNWSba/SpritesAndBones_Tutorial_Manua.html

    It does do vertex animation and deformation, unless Unity puts onion skinning in their animation tool I don't see that happening any time soon. In the meantime, it works great for me with some minor caveats, I'll post improvements as I go and extra tools as I make them. In the meantime, get the code, play with a project, look through the forum here to see how things work. That is the best advice I can give for now!
     
  2. awesomedata

    awesomedata

    Joined:
    Oct 8, 2014
    Posts:
    1,419
    Thanks, not a problem! That's how I generally have to learn anyways!

    Btw, by deformation, I meant something like this:

    http://ru.esotericsoftware.com/spine-meshes#Edges





    And not as much (although still very very useful) like this:



    The advantage of the former version of the "deformation" is that it allows you to modify the silhouette of the sprite with ease. The main requirement is you'd have to be able to define your own mesh triangles and edges first to be able to do something like extending the nose.

    Silhouette is very important in animation, and the only way to avoid the paper-doll-cutout-pieces look is to be able to animate the mesh of a part directly (sometimes the same image part should even be animated in different ways depending on the overall pose of the character).

    You can do many things with this type of animation deformation, such as squash and stretch, creating very cartoony or hand-drawn-looking animations by simply modifying the verticies' positions on a per-pose basis on certain images on the skeleton. This allows you to fill in the inbetweens just before you swap drawings with "unique-looking" images, despite them simply being the same image just stretched in different ways depending on the keyframe and pose. This allows your images to not appear overly smooth when translating and then suddenly "jerk" when the image must change to display another angle or drawing on an extreme pose or change.
     
    Last edited: Jun 10, 2015
  3. playemgames

    playemgames

    Joined:
    Apr 30, 2009
    Posts:
    438
    Yep it does that and you can make custom meshes.

    http://forum.unity3d.com/attachments/new_walk-gif.115237/
     
  4. dantamont

    dantamont

    Joined:
    Jun 17, 2015
    Posts:
    2
    So, I've been trying to use this because I think it's perfect for what I want, which is to animate a character with multiple segments.

    Question, am I stupid, or is there a trick to moving the bones around with the helper? I followed the second tutorial, and when it came time to drag the helper around, I couldn't even select it. I turned off edit mode and everything. so the bones are just sitting there and I don't know how to manipulate them. Here is my setup: https://imgur.com/cDDcTMh

    Also, separate question. Is it possible to swap out sprites during runtime or during animations with this?
     
    Last edited: Jun 17, 2015
  5. awesomedata

    awesomedata

    Joined:
    Oct 8, 2014
    Posts:
    1,419
    @playemgames
    How accurate are the old tutorials for setting up a basic rig in the current build?

    @dantamont
    1) I think you have to click /exactly/ on the bone and/or helper itself to select it, but I read this in the old documentation so there may be some new/special trick -- I haven't successfully created an animation with this yet, so I don't know for sure.
    2) You /should/ be able to do it via the typical unity animation workflow, but I may be wrong on this...
     
  6. playemgames

    playemgames

    Joined:
    Apr 30, 2009
    Posts:
    438
    Sorry been very busy as of late, you are using an old build, use the one from my fork:

    https://github.com/playemgames/UnitySpritesAndBones/tree/unstable

    And yes you can switch sprites in the animation window when you are creating the animation for it.
     
  7. playemgames

    playemgames

    Joined:
    Apr 30, 2009
    Posts:
    438
    Probably not accurate at all if you are working from my fork. All depends on the type of rig you are making, if it is not a skinned rig then it should be pretty easy to set up, skinned rigs can get a bit more complicated, especially if you are weight painting it.
     
  8. awesomedata

    awesomedata

    Joined:
    Oct 8, 2014
    Posts:
    1,419
    Yep, I'm working from your fork...

    No matter how complicated it is, I've only got 4 very basic questions...

    1) Are there any shortcut commands for each of the Sprites and Bones menu items (i.e. adding a bone, adding a helper, etc?) or a list somewhere of the shortcuts available in a given mode?
    2) What are the basic steps to skin + weight paint and/or animate the skinned-mesh's control points with your fork?
    3) Are there any special requirements for the bone/image parenting or weight/skin setup with images, skinning, weights and especially control point animation?
    4) How can I change a skinned image+mesh w/animated control points to another skinned mesh w/animated control points during an animation (e.g. a deforming cape that swaps the currently deforming image+mesh to another angle with a different mesh+image with different deformation)?

    Any help on any of these whenever you get the time would be greatly appreciated, especially on the 2nd and 4th questions.
     
  9. playemgames

    playemgames

    Joined:
    Apr 30, 2009
    Posts:
    438
    Sorry I'm just getting this now, didn't get an email from Unity about this. I'll answer some of these quickly.

    1) As far as I know CTRL + Left click creates a bone where the mouse is in Edit mode.

    2) Check these forums, I have multiple posts detailing this that I'd rather not reiterate here.

    3) Not that I know of.

    4) Disable and enable gameobjects in animation, use 2 different skeletons or Skin2D parts as needed.
     
  10. Freezerg

    Freezerg

    Joined:
    Sep 25, 2015
    Posts:
    2
    I have a problem with S&B. Don't know if it is just me, but I cant seem to get the bones to pass near each other. They collide with themselves, no matter what settings do I use. It is a real problem when I want the character to move both of his arms in the same direction - one arm interfere with the spine.
     
  11. TheRealBanbury

    TheRealBanbury

    Joined:
    Dec 15, 2013
    Posts:
    248
    Without knowing how your setup is, I can't really tell what's wrong. Unless you've added colliders to the bones, they shouldn't collide.
    If you're using IK and the spine is moving, when you're moving the arms, then yo have to change the length of the IK chain.
     
  12. Freezerg

    Freezerg

    Joined:
    Sep 25, 2015
    Posts:
    2
    I've rigged it to Kinect 2.0, and I've checked every kinect setting and it's not its fault. No colliders added to the bones. No IK chain (for now).
     
  13. TheRealBanbury

    TheRealBanbury

    Joined:
    Dec 15, 2013
    Posts:
    248
    Are you sure, you're in the right thread? :) I'm puzzled, how to use a 2D framework with a Kinect.
    Anyways, if you're not using colliders or IK, then there is nothing in Sprites And Bones, that would make the bones collide or interfere with each other.
    Maybe you could make short video to demonstrate, what is going wrong?
     
    Last edited: Oct 1, 2015
  14. Vickylance

    Vickylance

    Joined:
    Mar 28, 2014
    Posts:
    17

    Attached Files:

  15. TheRealBanbury

    TheRealBanbury

    Joined:
    Dec 15, 2013
    Posts:
    248
    Could you upload your changes to Github and make a pull request?
    Also if you're planning to make more changes to Sprites And Bones, I could add you to the project as a committer.
     
  16. playemgames

    playemgames

    Joined:
    Apr 30, 2009
    Posts:
    438
    Are you using the main branch or my fork with the changes? I've not seen any issues arise from my fork in 5.2.1 so far. I'll have to update my code for the fork for 5.2 anyway, can you please make a pull request so I can see a comparison?
     
  17. MD_Reptile

    MD_Reptile

    Joined:
    Jan 19, 2012
    Posts:
    2,664
    I haven't had problems on 5.2.1p1 so far...
     
  18. adjnor

    adjnor

    Joined:
    Sep 14, 2015
    Posts:
    3
    I made this video tutorial, hopefully it can be helpful if anybody is having troubles using Sprites and Bones:
     
    playemgames likes this.
  19. TheRealBanbury

    TheRealBanbury

    Joined:
    Dec 15, 2013
    Posts:
    248
    @adjnor Thanks for making the tutorial. I'm sure this will be very helpful. I'll link to it in the first post, if you don't mind.
     
  20. SHARKvince

    SHARKvince

    Joined:
    Oct 6, 2015
    Posts:
    1
    Hi! Found out about this tool while searching for, well, something like this tool. Watched the tutorial from adjnor (thanks!) and it looks like it covers most things we need. One thing I need to know though:

    We have characters that change their facial expressions, hand motions and so on. So, let’s say I had different face sprites for a character (e. g. expression of pain, joy) and different hand sprites (open hand, fists) — can this be done with S&B too?

    EDIT:
    Derp me. Second video of the opening post shows it’s possible. Going to check S&B out!
     
    Last edited: Oct 6, 2015
  21. adjnor

    adjnor

    Joined:
    Sep 14, 2015
    Posts:
    3
    @TheRealBanbury no problem, I think it's better to link it on the first post actually otherwise people might have troubles finding the tutorial among the other posts, so thanks :)
     
  22. TheRealBanbury

    TheRealBanbury

    Joined:
    Dec 15, 2013
    Posts:
    248
    I'm happy to see, that there's still some interest in Sprites And Bones.
     
    playemgames likes this.
  23. playemgames

    playemgames

    Joined:
    Apr 30, 2009
    Posts:
    438
    Keeping it alive!

    Great video! One thing that you can do about the elbow problems is create angle limits in the IK, you can set it up between the transforms of the IK chain. I have done it both ways in my rigs, sometimes it is better to use angle limiting, especially for feet/toes.

    Another thing, if you want to touch upon later, is creating poses for the characters. You can also bake poses from IK in an animation to bake in the IK to an animation to save some processing power using the Bake Pose tool. You can read about that here:

    http://forum.unity3d.com/threads/re...keleton-animation.219915/page-12#post-1916087

    Otherwise great tutorial!
     
  24. adjnor

    adjnor

    Joined:
    Sep 14, 2015
    Posts:
    3
    @playemgames, Thanks! For the elbow, I wouldn't say it's a problem however because sometimes I want my character to be throwing a punch from above the head so the shoulder would be higher, like a big haymaker punch, while sometimes I want to throw a quick punch from the hip so the elbow would be lower. Using angle limits, the lower arm will always be under the upper arm or always above the upper arm (depending on the angle limits). Of course changing the angle limits work but then it isn't any faster or more intuitive than changing the IK target for the elbow in my opinion. For the feet though yeah it's better I think :)

    I'll definitely look into baking poses and might make a video on it, I'm developing for mobile so if I can save some processing power that would be great! :)
     
  25. Mikekan13

    Mikekan13

    Joined:
    May 30, 2015
    Posts:
    90
    Great tool! I did notice there was a strange effect when I animated. Sometimes the animation would change a joint rotation. I am using the angle limits. Is there a bug with those?

    Also how would you go about having something that is affected by gravity attached to a skeleton. Example a swinging lantern in someones hand. I have tried adding another bone attached to the hand and then adding a rigidbody and reducing the dampening but it won't work.
     
    Last edited: Nov 5, 2015
  26. pawelek

    pawelek

    Joined:
    Mar 4, 2015
    Posts:
    1
    How about creating Unity chain (using joints and rigid bodies) and making it child of hand? I've made lamp that way but its just sticked to the ceiling
     
  27. playemgames

    playemgames

    Joined:
    Apr 30, 2009
    Posts:
    438
    I've finally pushed everything to master, updated it for Unity 5, and made some changes to help speed things up with IK and the bones. I've also included a "Lock Bone Weights" bool to lock the bone weights on a skin that you do not want recalculated. This is helpful if you want to change part of the rig but do not want to lose the weights on some skins to their bones.

    upload_2015-11-23_23-51-24.png

    I've also included buttons for locking and unlocking all the bone weights for all the skins on a skeleton, it is in the Skeleton component. It's useful if you have multiple rigs and want to lock the skins down on a skeleton while you change another skeleton's skins.

    upload_2015-11-23_23-52-41.png


    Also added a way to quickly save poses with only the active game objects in the Bake Pose Editor:

    upload_2015-11-24_0-29-35.png

    This should be all the changes I'll have for a while so I've merged everything to master, so now you can get it at:

    https://github.com/playemgames/UnitySpritesAndBones

    I will no longer be supporting Unity 4 so don't update if you are still using Unity 4 for anything.

    Hope this helps some of you folks who are using this!
     
    Last edited: Nov 24, 2015
    theANMATOR2b likes this.
  28. TokyoDan

    TokyoDan

    Joined:
    Jun 16, 2012
    Posts:
    1,080
    In IK is there a way to set angle limits that can keep joints from assuming impossible angles? e.g. keeping an elbow joint from bending backwards?
     
  29. HeroicNate

    HeroicNate

    Joined:
    Jan 3, 2016
    Posts:
    1
    I was having problems getting my animations to come out properly in my game testing. What I discovered is that you have to have the Update Mode set to Animate Physics in the animator component. I must've missed that step in tutorials but I wanted to throw that out there for anyone else that might be having problems.
     
  30. TheRealBanbury

    TheRealBanbury

    Joined:
    Dec 15, 2013
    Posts:
    248
    Sorry for not answering earlier. The forum doesn't send me messages every time.
    I tried implementing joint limits. But in the end they aren't all that useful for 2D animation. Unlike 3D in 2D there aren't any physical limitations to how the limbs should move. You just want to bend them so that they look good. And sometimes that includes weird angles.

    This might be something new in Unity 5. At least I can't remember any 'Update Mode'. But I haven't touched Unity well over a year now.
     
  31. playemgames

    playemgames

    Joined:
    Apr 30, 2009
    Posts:
    438
    Are you using the latest from my fork? https://github.com/playemgames/UnitySpritesAndBones

    If so can you send me an example? I cannot seem to see this being an issue.

    I have a little New Year present for everyone, I added an easy way replace gameobject heirarchies by name in the Animation Heirarchy Editor:

    upload_2016-1-3_7-39-49.png

    Just enter the Original Path Text and the Replacement Path Text and hit the Replace All Paths button and it will replace all the paths with the new text you enter. This is often better than manually replacing each entry with a new one so I thought this would make life easier for myself and others that work a lot with animations and changing stuff around.

    I also created a new tool to do something similar with just sprites:
    upload_2016-1-3_7-47-17.png

    Under Window/Animation Replace Sprites you can use this tool similar to the AnimationHeirarchyEditor except it is only for sprite replacement. Select all the animation clips you want to change. Just enter the Original Sprite Text (all or part of the name you want to change) and the Replacement Sprite Text and press the Replace All Sprites button and it will change all the sprite references in the clip to the new names you have assigned.

    This is great for duplicating animations and changing the sprites in the tool without having to do any special reskinning code. Or if you have or want to just change the sprites in your base animation without having to rename a bunch of files.

    You can see the new files under my fork: https://github.com/playemgames/UnitySpritesAndBones

    Happy New Year everyone, happy animating in 2016!
     
    theANMATOR2b and MD_Reptile like this.
  32. Shibli

    Shibli

    Joined:
    Feb 9, 2015
    Posts:
    6
  33. Deleted User

    Deleted User

    Guest

    Sprites and bones really amazing asset, thank you. And, i dont know why, Inverse Kinematics make huge lags on PC. Screens:Enable IK (left) and Disable IK (right) . 10 skeletons on scene - 10-15fps. Old version Sprite and Bones (1.2.2) have stable 60 fps with 100 skeletons+
     

    Attached Files:

    Last edited by a moderator: Jan 21, 2016
  34. WInDArt

    WInDArt

    Joined:
    Jan 31, 2014
    Posts:
    9
    Hello. I have some problems with skin 2D. (Unity 5.3.1f1 (64-bit)) Windows 7 (64-bit). I use last version SaB on github (https://github.com/playemgames/UnitySpritesAndBones)
    Why when i use skin 2D on object without "skeleton" i get black sprite? step1. step2. Select object. step3.
    how to get color back?
     

    Attached Files:

  35. playemgames

    playemgames

    Joined:
    Apr 30, 2009
    Posts:
    438
    That is because the Skin2D component requires a Skeleton and a Bone. Without seeing your project it is really hard to tell what is going on.

    Probably because a lot more is going on in Skeleton than before, 1.2.2 is ancient so I can't even compare that one. Without a project to see what is going on, there is little I can do seeing those screenshots to see where the performance hits are. Maybe do a deep profile to see where in Skeleton the IK function is getting hammered?
     
    theANMATOR2b likes this.
  36. WInDArt

    WInDArt

    Joined:
    Jan 31, 2014
    Posts:
    9
    Oh, no. Prefabs don't work with skin 2D? Sprites with skin 2D pink color and dont have texture.
     

    Attached Files:

    • Bug.png
      Bug.png
      File size:
      364.7 KB
      Views:
      977
  37. playemgames

    playemgames

    Joined:
    Apr 30, 2009
    Posts:
    438
  38. WInDArt

    WInDArt

    Joined:
    Jan 31, 2014
    Posts:
    9
    I create new project for test it.
    step 1. Create Skeleton and add sprite on bone. Use skin 2D fpr sprite. Create Control Points.
    step 2. Open Sort Layers and Material. (Failed to call static function Reset because an object was provided)
    step 3. Create material. (NullReferenceException: Object reference not set to an instance of an object)
    What's my mistake? Thank You.

    Block is empty (SortLayerMaterialEditor).
     

    Attached Files:

    • s1.jpg
      s1.jpg
      File size:
      284.3 KB
      Views:
      821
    • s2.jpg
      s2.jpg
      File size:
      346.8 KB
      Views:
      893
    • s3.jpg
      s3.jpg
      File size:
      369 KB
      Views:
      982
    Last edited: Feb 3, 2016
  39. playemgames

    playemgames

    Joined:
    Apr 30, 2009
    Posts:
    438
    Just create a material for the Skin2D then click on the create Prefab button.
     
  40. WInDArt

    WInDArt

    Joined:
    Jan 31, 2014
    Posts:
    9
    But i can not create a material. i get error (NullReferenceException: Object reference not set to an instance of an object). Look on my project please.
     

    Attached Files:

  41. mochakingup

    mochakingup

    Joined:
    Apr 14, 2014
    Posts:
    212
    Hi guys, just wanted to hop in and say thank you so much for this,
    I'm using Sprite and Bones on our current game. it took a little bit of time to figure things out and set everything up, but once the rig is ready, animating is a breeze and fast, especially love the IK.
    Here's what we have so far
     
  42. PanMadzior

    PanMadzior

    Joined:
    Jun 4, 2015
    Posts:
    10
    Hi. First i'd like to thank you for this asset!
    But I've got strange problem with bones and scaling them. When I scale skeleton without parent it works ok (2). Also it works when i scale parent of skeleton (3). But things go wrong when i move this scaled parent to another game object with (1,1,1) scale or any other scale (4).

    Some screenshots:
    1. All transforms have scale (1,1,1) - works ok.


    2. Skeleton has scale (0.5, 0.5, 0.5) - works ok.


    3. Skeleton is (1,1,1) and First parent is (0.5, 0.5, 0.5) - works ok.


    4. Skeleton is (1,1,1), First parent is (0.5, 0.5, 0.5) and Second parent is (1, 1, 1) - armagedon.


    It looks like bones are scaling only with "the highest" parent.
    Is there any known solution for this?

    Regards
     
  43. erikhallgren

    erikhallgren

    Joined:
    Feb 2, 2015
    Posts:
    9
    Thanks for a sweet asset! We're using it to manipulate the IK from code for sort of a ragdoll effect. I have an issue though whith parenting which might be related to 0x6D6164's problem.
    Everything works fine as long as I don't parent the skeleton to anything, if I do all bones get reset to 0 length if I click them in the hierarchy. As long as I don't touch them all is ok! So it seems to recalculate the Skeleton position to that of the parent and subsequently all bones to this one. OR I missed something which is entirely possible :) I'm running the latest version.

    If skeleton is highest parent or I refrain from clicking the bone objects:
    upload_2016-2-9_12-25-15.png

    Clicking the bone objects (undo doesn't work to restore the original state)
    upload_2016-2-9_12-28-1.png

    Any ideas what is going on?
     

    Attached Files:

  44. playemgames

    playemgames

    Joined:
    Apr 30, 2009
    Posts:
    438
    Looking great!

    I just updated the project on Github so it should create default materials for you, and if you have one set up it will create a reference material for you as well.

    For the parenting issues, this is behaving as expected. Unless you retool how the bones are made and IK is handled, the root object controls the scaling of everything. As far as I know there is no way around this unless you recode a lot of the codebase to handle how bones are created and positioned and how IK is handled.

    Look in Bone.cs and InverseKinematics.cs if you are interested in finding a solution. You can see the use of transform.root.localScale in both.
     
    Last edited: Feb 20, 2016
    PanMadzior likes this.
  45. PanMadzior

    PanMadzior

    Joined:
    Jun 4, 2015
    Posts:
    10
    Thanks for good suggestion. I changed transform.root.localScale in both to lossyScale of skeleton. For now it works.

    • in Bone.cs
    Code (CSharp):
    1. //old:
    2. v.Scale(gameObject.transform.root.localScale;
    3.  
    4. // new:
    5. if(skeleton != null)
    6.     v.Scale(skeleton.transform.lossyScale);
    • in InverseKinematics.cs
    Code (CSharp):
    1. // old:
    2. angle *= Mathf.Sign(t.root.localScale.x);
    3.  
    4. // new:
    5. angle *= Mathf.Sign(skeleton.transform.lossyScale.x);
     
  46. playemgames

    playemgames

    Joined:
    Apr 30, 2009
    Posts:
    438
    So long as you don't rotate the objects this will work, but if you plan on rotating them in any way, this is where lossyScale gets messy. I also don't believe flipping will work accurately using lossyScale, it may work in your edge case but that is why I've stuck with the localScale on the root. You may actually want to use this for the bone:
    Code (CSharp):
    1.  
    2. public Vector2 Head {
    3.     get {
    4.       Vector3 v = Vector3.up * length;
    5.       v = transform.TransformPoint(v);
    6.       return v;
    7.     }
    8.   }
    9.  
    Actually it is more or less the vertex position placement, if you can find a way where it doesn't rely on scale and more or less a relative position to the other object than it can have a more universal solution. I just haven't had the time to figure out a better solution for this, since all my characters are not parented to anything else.

    For the InverseKinematics, it is a bit trickier, I don't have time to go through that one. But everything will be ok, unless you start rotating the objects, then that is when you will see the messiness start to happen.
     
    Last edited: Feb 21, 2016
  47. playemgames

    playemgames

    Joined:
    Apr 30, 2009
    Posts:
    438
    MD_Reptile, WInDArt and theANMATOR2b like this.
  48. AstralAngel

    AstralAngel

    Joined:
    Aug 6, 2014
    Posts:
    6
    Helllo! Firstly thank you for that beautiful tool. I want to ask, is there any huge (hard) examples like http://i.imgur.com/0XeILHa.gif to see how the bones are configured?
     
  49. WInDArt

    WInDArt

    Joined:
    Jan 31, 2014
    Posts:
    9
    Last edited: Mar 26, 2016
  50. Janjanus

    Janjanus

    Joined:
    Sep 17, 2015
    Posts:
    4
    Thank you for the cool asset! I have two questions:

    1: Is the code in this repository: https://github.com/playemgames/UnitySpritesAndBones the latest available?

    2: I am trying to deform a mesh of a sprite using Bones but I have a hard time to get it working! I have a Skeleton with some bones in it. I added sprites as childs to some of the bones. Now I add a Skin 2D component to the sprite using the menu 'Sprites And Bones > Skin 2D'. The component is added but when I move the bones the mesh is not altered? Do I need to set the Root Bone of the Skinned Mesh Renderer so yes to which bone? Also when I try to weight paint I receive the error 'SkinnedMeshRenderer not assigned to any bones, Recalculate Bone Weights' When I assign the parent bone and recalculate the weights I still receive the error... how do I get this to work?

    Thanks for your time :)