Search Unity

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

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

  1. TheRealBanbury

    TheRealBanbury

    Joined:
    Dec 15, 2013
    Posts:
    248
    @playemgames: I will make the tutorial right away :).

    @Rirath:
    I have no idea, how masking could be used for "moving, scaling and deforming a texture". As I understand it, a mask is an area where underlying image(s) can be seen. Everything outside the mask is hidden. I guess it could be done with render textures. But I don't own Unity Pro. Render textures really should be in Unity Free.
    And thanks for the advertisement.
     
  2. Rirath

    Rirath

    Joined:
    Dec 5, 2013
    Posts:
    30
    We can certainly hope render textures come to Free some day like other features (navmesh, force text assets, etc) have - I sincerely hope to be able to do Oculus Rift development with Unity Free some day. (Pro required for distorting the image.) Oculus is working closely with Unity, and I have to imagine they'll push for it. Would benefit us all.

    Nothing much comes to mind for masking that'd be worth a pro only feature (or using performance heavy workarounds) though, I must admit. Just food for thought, I guess. And happy to advertise for someone who's giving such awesome tools to the community. Any luck with getting in the Asset Store? I feel like the popularity of this will explode once you are.
     
  3. TheRealBanbury

    TheRealBanbury

    Joined:
    Dec 15, 2013
    Posts:
    248
    No luck with the Asset Store so far. Support is ignoring me. Probably they have no hurry to upload an asset, that could dilute the business of paid assets.
     
  4. TheRealBanbury

    TheRealBanbury

    Joined:
    Dec 15, 2013
    Posts:
    248
    And here's the promised tutorial on how to use Sprites And Bones for image morphing.

     
  5. playemgames

    playemgames

    Joined:
    Apr 30, 2009
    Posts:
    438
    Cool! I'll have to play around with this then :)
     
  6. TheRealBanbury

    TheRealBanbury

    Joined:
    Dec 15, 2013
    Posts:
    248
    I found a bug with the mesh weight colours. I've uploaded a new version.
     
  7. jvt619

    jvt619

    Joined:
    Jul 4, 2013
    Posts:
    53
    did you pass this asset on the asset store?
     
  8. Kelde

    Kelde

    Joined:
    Feb 28, 2012
    Posts:
    629
    oh amn...this is shaping up and actually surpassing the larger assets that does this! Cant applaude u enough! I have some characters im gonna give it a go now, i was basicly waiting for some deformation and here we are!

    Great job man, one of my top 3 assets now!:D
     
  9. TheRealBanbury

    TheRealBanbury

    Joined:
    Dec 15, 2013
    Posts:
    248
    I tried. But there's some bug in the Asset Store Tools. And Support has to offer any solution, yet.

    @Kelde: Thanks, man. I hope you enjoy it.
     
  10. 30markom

    30markom

    Joined:
    Feb 7, 2014
    Posts:
    7
    I have a problem with your asset. When I create a mesh from a sprite it does not apply any skin information, so it can't be used with Skin2D, I get an error where it says that mesh has no skinning information.
    Anyhow the tool is great and easy to use, great work!
     
  11. TheRealBanbury

    TheRealBanbury

    Joined:
    Dec 15, 2013
    Posts:
    248
    The mesh needs to be added to the Mesh Filter of the Skin2D component. Also you need a skeleton assigned to the Skeleton field in the Skin2D component. Pressing the 'Calculate weights' button combines the mesh with the Skin2D component.

    This is all described in detail in this tutorial: http://vimeo.com/83922532.
     
  12. 30markom

    30markom

    Joined:
    Feb 7, 2014
    Posts:
    7
    Thank you for your answer
    I did everything like in your tutorial, but I still have problems. On your prefab mesh there are uv,colors and skin properties and with that one it works just fine. But when I make a mesh from a sprite in Unity it only generates a mesh with uv and colors and no skin. When I add the mesh to the Mesh Filter of the Skin2D component, Unity gives me an error that mesh is lacking a skinning or blendshape information and I can't do anything. I also added the skeleton in Skin2D which is a parent of skeleton. Also when I add the mesh it is black and not pink as it should be when everything is fine
     
  13. TheRealBanbury

    TheRealBanbury

    Joined:
    Dec 15, 2013
    Posts:
    248
    The bones also need unique names for the weight calculation to work. Or you missed a step somewhere.

    It's difficult to find the problem, without seeing your project. If you can't find a solution, you'll have to make some screenshots or upload your project somewhere, so I can have a look.

    Are there any error messages in the console window?
     
  14. 30markom

    30markom

    Joined:
    Feb 7, 2014
    Posts:
    7
    Here is the error in the console window: SkinnedMeshRenderer requires a mesh with skinning or blendshape information.
    UnityEditor.DockArea:OnGUI()
    And here is the mesh I created from image http://speedy.sh/zCK4F/New-UnityEngine.Mesh.asset
    The problem is in the mesh, everything other works fine
     
  15. TheRealBanbury

    TheRealBanbury

    Joined:
    Dec 15, 2013
    Posts:
    248
    I was unable to import this asset file. Could you please zip the whole project and upload it?
    Also could you describe, how you created the mesh. Preferably step by step.
     
  16. 30markom

    30markom

    Joined:
    Feb 7, 2014
    Posts:
    7
    Well I created the mesh according to your tutorial, I added the sprite file to the scene, then Window->Sprites->CreateMesh, seleted the sprite then Generate Polygon and Create Mesh and that's it. Skin2D requires the mesh to be skinned right? Well my isn't. Maybe I'm missing some steps, or I should skin newly created mesh in order to work. I deleted the project, but if you need it I will gladly do it again. Maybe I need to skin the mesh in Blender and then import it to Unity, I don't know. In your tutorial you are working on a skinned mesh
     
  17. 30markom

    30markom

    Joined:
    Feb 7, 2014
    Posts:
    7
  18. TheValar

    TheValar

    Joined:
    Nov 12, 2012
    Posts:
    760
    It's pretty lame that Unity has not approved this for the asset store/offered feedback on why it's not approved...
     
  19. TheRealBanbury

    TheRealBanbury

    Joined:
    Dec 15, 2013
    Posts:
    248
    There's something I've forgotten to mention in the tutorial. To create the mesh from the sprite, the sprite must be readable. In the Project window select the sprite and change 'Texture type' to 'Advanced'. Then check 'Read/Write enabled'. Now recreate the mesh. There should have been an error message. I'm surprised, that it created an empty Asset instead. I will have a look at this, to provide a better message.

    I got some feedback today. They asked me to try it again with a new version of the Asset Store Tool. Sadly it still doesn't work.
     
  20. 30markom

    30markom

    Joined:
    Feb 7, 2014
    Posts:
    7
    Yes, I already did that with the import settings. I'm close to get it work. I'm having some problems with calculating weights, but I will manage somehow. I think that the problem was with the bones influence, when I enlarged them weights were relatively good calculated, probably that is the problem
    Thank you very much for your help and your wonderful tool. I will keep you updated if I manage to do it right
     
  21. TheRealBanbury

    TheRealBanbury

    Joined:
    Dec 15, 2013
    Posts:
    248
    The size of the influence is the important part here, indeed. See that you cover the whole mesh.
     
  22. 30markom

    30markom

    Joined:
    Feb 7, 2014
    Posts:
    7
    That was the problem, I didn't have the whole mesh covered with influence, so when calculating weights some parts of the mesh weren't created. Thank you again very much and good luck with the Asset Store
     
  23. TheRealBanbury

    TheRealBanbury

    Joined:
    Dec 15, 2013
    Posts:
    248
    I'm glad we could clear this up.

    I'm still trying to add some kind of weight painting. But it's a lot more difficult than I expected.
     
  24. TheRealBanbury

    TheRealBanbury

    Joined:
    Dec 15, 2013
    Posts:
    248
    After almost giving up on it, I finally made some good progress with the weight painting. Maybe I can finish this up next weekend.

    My work is currently taking a toll on my productivity in my spare time. I really could use some help in developing Sprites And Bones. (Hint, Hint)
     
  25. Rirath

    Rirath

    Joined:
    Dec 5, 2013
    Posts:
    30
    Thanks for keeping at it. Hope you find some help (well out of my league, I'm afraid), though since you're already seemingly eclipsing many of the paid packages out there, good help may be hard to find. Unity and its community leans somewhat toward monetized assets, in my experience, save a few good open source projects and the Unity Wiki. I guess in part because the store just makes it so easy.

    You may want to put the call out in a few more community spots, like Reddit's /r/gamedev and /r/unity3d.
     
  26. TheRealBanbury

    TheRealBanbury

    Joined:
    Dec 15, 2013
    Posts:
    248
    At this point I would be happy for any kind of help I can get. If you're no programmer, you could help with testing or creating documentation. I really could use a nicer introductory tutorial.
    Thanks anyway for your promotion of Sprites And Bones on reddit and your constant encouragement. It makes a difference.
     
  27. Jesse_Pixelsmith

    Jesse_Pixelsmith

    Joined:
    Nov 22, 2009
    Posts:
    296
    Anything wrong with charging? I'd pay :)
     
  28. TheRealBanbury

    TheRealBanbury

    Joined:
    Dec 15, 2013
    Posts:
    248
    There are several problems with that. First of all I would get problems with the tax collector. I don't believe I would earn enough, to justify the trouble I'd get from that. Also I don't need the money. I'm earning a good salary.
    I'm doing this mostly for the fun of it. When people would start paying for Sprites And Bones, it would stop being fun and instead turn into work. The last thing I need is more work.
    Programming Sprites And Bones provides most of the fun on its own. But I have reached mostly what I intended to do. In order to keep this being fun, I need at few people at least, who use Sprites And Bones actively and give me feedback, bug reports and feature wishes. Contributors would be even better. Otherwise sooner or later (rather sooner) I will loose interest and start something else.
    Sprites And Bones is the biggest and best open source project I have done so far. I'd really hate to see it die ignominiously.
     
  29. Jesse_Pixelsmith

    Jesse_Pixelsmith

    Joined:
    Nov 22, 2009
    Posts:
    296
    Those are all very understandable and relate-able reasons! I'll be doing some small work with it over the next week I think and will give you feedback! Unfortunately my plate is spread way to thin to be able to contribute other than sending bug reports and feature requests. Maybe in the future that will change.
     
  30. TheValar

    TheValar

    Joined:
    Nov 12, 2012
    Posts:
    760
    I"m currently brainstorming a few updates I could reasonably make to this. It would be a fun way to learn about writing Unity extensions. I'm thinking of some simple stuff to help improve workflow such as automatically creating an ik helper for a given limb and possibly setting the right bones and parents to the appropriate sprites.
     
  31. AndreasO

    AndreasO

    Joined:
    Sep 25, 2012
    Posts:
    90
    Hi there,

    First of all, great software! Keep up the good work! :)

    I've played around with Sprites and Bones for a while and noticed that it's very picky about where I need to click in order to successfully select a bone. The current handles require one to really hit those 1px small lines of a handle. As far as I know this a limitation of the UnityEditor API. Still, I think it would be much better for a good workflow to have handles that are easier to select (maybe using custom sprites?).

    EDIT:
    Whoops, forgot to report a bug that I found while trying to use the Tab-Key to toggle between Edit and Pose mode. Using the checkmark in the Inspector panel works just fine, but when I use the Tab-Key the mode does not change (blue bones stay blue, for example). The checkmark is toggled in the Inspector panel but it doesn't seem to have an effect.
     
    Last edited: Feb 18, 2014
  32. TheRealBanbury

    TheRealBanbury

    Joined:
    Dec 15, 2013
    Posts:
    248
    This is indeed a problem, with the way Unity gizmos work. I have no idea, how to fix this. If you've watched my tutorials, you might have seen, that I always select bones in the hierarchy :).

    Yet another problem with Unity. The Tab key will only work, if you click on the skeleton beforehand. If any other control has the focus, nothing happens. Unity doesn't seem to support global keyboard shortcuts. So again I can't do any thing about it.

    Thanks for reporting it though.
     
  33. ManeFunction

    ManeFunction

    Joined:
    Feb 19, 2014
    Posts:
    2
    Perfect solution for 2D skeletal animation, really thank you for giving it absolutely free! I see only one problem with it: when I scale the skeleton only sprites scaled but not bones so it create a lot of chaos inside skeleton and doesn't work at all. Have you plan to fix it?
     
  34. ManeFunction

    ManeFunction

    Joined:
    Feb 19, 2014
    Posts:
    2
    I add scaling to the Sprites and Bones! We need to insert 2 changes:
    into Bone.cs change Head property like this:
    Code (csharp):
    1.  
    2. public Vector2 Head
    3. {
    4.     get
    5.     {
    6.         Vector3 scaleVector = new Vector2(gameObject.transform.up.x * gameObject.transform.lossyScale.x * length,
    7.                                           gameObject.transform.up.y * gameObject.transform.lossyScale.y * length);
    8.         return gameObject.transform.position + scaleVector;
    9.     }
    10. }
    11.  
    and into InverseKinematics.cs add this inside resolveSK2D method:
    Code (csharp):
    1.  
    2. float scale = (b.transform.lossyScale.x + b.transform.lossyScale.y) / 2;
    3. Vector3 root2tip = (tip.position + tip.up * b.length * scale - root).normalized;
    4.  
    instead old root2tip.

    So after that we can scale skeleton object and posing/animating works ok.

    Hope it helps, 'cause it's very useful for me (for mobile games with zooming for example) :)
     
    Last edited: Feb 19, 2014
    Bralgs likes this.
  35. TheValar

    TheValar

    Joined:
    Nov 12, 2012
    Posts:
    760
    In the interest of mutually beneficial self promotion, here's a small WIP gameplay video of one of my current projects which uses this plugin for all character animations.

    WIP Thread

    Webplayer Demo

    www.youtube.com/watch?v=hxhlGscr03k
     
  36. TheRealBanbury

    TheRealBanbury

    Joined:
    Dec 15, 2013
    Posts:
    248
    @Kiichi:
    Thanks for the code snippet. If it has no unpleasent side effects, I will add it for certain.

    @TheValar:
    That's really nice. A game using Sprites And Bones is what I really wished for. Can I link to it on a 'Games made with' page?
     
  37. msbranin

    msbranin

    Joined:
    Jan 19, 2009
    Posts:
    104
    Hrmm Could you possibly explain how you are handling that melee in your video? I have been trying to impliment melee in my 2D sidescroller but so far every tutorial I find focuses on ranged combat (IE Shooting)


     
  38. TheValar

    TheValar

    Joined:
    Nov 12, 2012
    Posts:
    760
    Yes go ahead although it's not a finished product yet. I'll be sure to let you know when it's done and you can update whatever links you have.
     
  39. TheValar

    TheValar

    Joined:
    Nov 12, 2012
    Posts:
    760
    For this game my solution was pretty simple. I have 3 box colliders as children of the dwarf. One above, below, and in front. They basically cover the arc of the axe attack. In the attack animation I activate/deactivate the boxes at the appropriate time and in the non combat animations I make sure they are deactivated. This is nice because if you have different animations for different weapons you can use the same colliders.

    I set the colliders as triggers and then just program the interactions in the enemy's components.

    If you want more explanation pm me or repost on my WIP forum, I don't want to hijack this thread.
     
    theANMATOR2b likes this.
  40. oleg9419

    oleg9419

    Joined:
    Feb 7, 2014
    Posts:
    9
    I added a collider2D to my sword (which is a part of my character sprite sheet) but it doesn't move with the bone animation I made.I thought maybe creating a bone where my sword is and adding the collider2D to it ? still didn't work.

    Question : How can I move my collider2D along with my sword?

    Thank you very much!:)
     
    Last edited: Feb 21, 2014
  41. TheRealBanbury

    TheRealBanbury

    Joined:
    Dec 15, 2013
    Posts:
    248
    I tried it and it works for me.

    Here's how I've done it:
    Create a skeleton with bones. Add the sword sprite as a child of the hand bone (drag it on the bone in the hierarchy window). Now you can add a collider component either to the bone or the sword. Both the sword and the collider will now follow the bone.
     
  42. oleg9419

    oleg9419

    Joined:
    Feb 7, 2014
    Posts:
    9
    I added the collider to the sword(of course the sword is added as a child to the hand bone) sprite but still the collider doesn't with my animation (I didn't put a rigid body to the sword , do I need to?)

    I added then the collider to the bone hand (adjusted it so that it fits with the sword) and it worked only if I have IK enabled , without it doesn't.

    In this image animation is running and the collider is not , if I enable IK it does.

    A little bit of help please ?

    Thank you ! )
     

    Attached Files:

    Last edited: Feb 22, 2014
  43. TheRealBanbury

    TheRealBanbury

    Joined:
    Dec 15, 2013
    Posts:
    248
    I made more tests and it works for me. There must be something wrong on your side.
    The only thing I can think of right now, is, if you're using IK in an animation, you can't turn it off globally. Otherwise the animation will no longer work. If you need to switch IK on an off, you can animate this. Just click on the checkbox, while you're animating.

    If you can't get it to work, you'll have to upload your project somewhere, and I'll have a look.
     
  44. oleg9419

    oleg9419

    Joined:
    Feb 7, 2014
    Posts:
    9
    That would be just wonderful , but quite frankly I don't know which files of my project to upload(I'm new in unity).

    Thanks for the help
     
  45. TheRealBanbury

    TheRealBanbury

    Joined:
    Dec 15, 2013
    Posts:
    248
    Just pack up the whole thing.
     
  46. oleg9419

    oleg9419

    Joined:
    Feb 7, 2014
    Posts:
    9

    http://www.fileswap.com/dl/259PGJeqRz/

    If I did something wrong with the IK and hence bad animation ,or bad practices please let me know .

    Thanks again !
     
  47. TheRealBanbury

    TheRealBanbury

    Joined:
    Dec 15, 2013
    Posts:
    248
    The problem indeed is in the way you're using the IK.

    You have two IK components on the same bone chain pointing to the same target. That won't work. If you watch my tutorial, you'll see that I use one IK component for the forearm and a second on the upper arm with its own target. The second IK is there, to have the elbow point in the right direction.

    I suggest, that you use the same setup. This way you can animate the hands manually, but the arm still follows the IK target.
     
  48. oleg9419

    oleg9419

    Joined:
    Feb 7, 2014
    Posts:
    9
    Problem solved , thanks :).
     
  49. TheRealBanbury

    TheRealBanbury

    Joined:
    Dec 15, 2013
    Posts:
    248
    I'm almost finished with the weight painting. But currently I'm stuck on a problem. Everything works fine, but I can't save the changed weights back to the prefab. This is rather infuriating. Does anyone know how to do this?
     
  50. TheValar

    TheValar

    Joined:
    Nov 12, 2012
    Posts:
    760
    Just made a pull request. I added the ability to designate a file name when you save a pose. Just getting my feet wet :)

    Still getting comfy with GIT so hopefully I didn't mess anything up. I did not create a new unitypackage.