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
    I wonder how many 'resources' they saved. I hope it was worth breaking compatibility for it. :rolleyes:
    Could you be so good, to open an issue on Github? I'll try to fix it over the weekend. And I'll look, what else MS removed in their infinite wisdom.
     
  2. TheValar

    TheValar

    Joined:
    Nov 12, 2012
    Posts:
    760
    I submitted an issue shortly after posting here. I've just added a comment to it summarizing the cause of the issue.
     
  3. playemgames

    playemgames

    Joined:
    Apr 30, 2009
    Posts:
    438
    OK noted, and done, any changes that I'll want to integrate I'll put in my unstable branch, I've created an "upstream" branch for all the changes that I want to stay for myself or for others that may prefer my changes. Yeah I want to be able to change the colors per skeleton so if I have multiple skeletons in a rig, they will be able to differentiate from one another easier.

    Oh I also made a change to the Recalculate Weights button for Skin2D so that it weights it to the parent when pressed. Otherwise the sprite would disappear and need to be weight painted again anyway, if one wants to use the influence then they can press the Calculate Weights in Skeleton.
     
    Last edited: Jul 29, 2014
  4. TheRealBanbury

    TheRealBanbury

    Joined:
    Dec 15, 2013
    Posts:
    248
    My repositiory is 'upstream', because you forked from it. So not to muddy the waters, the 'upstream' branch should be the one with changes, I should merge.
     
  5. playemgames

    playemgames

    Joined:
    Apr 30, 2009
    Posts:
    438
    OK no problem I have not changed anything in either branch so I'll sort it all out when I get a chance. Right now my upstream branch and unstable are identical.
     
  6. HappyLDE

    HappyLDE

    Joined:
    Apr 16, 2014
    Posts:
    56
    Hello and thanks for making such a tool. I am looking forward to installing it right now and using it :D
     
    Last edited: Aug 1, 2014
  7. HappyLDE

    HappyLDE

    Joined:
    Apr 16, 2014
    Posts:
    56
    I have a slight problem when i Flip() the player:

     
  8. TheRealBanbury

    TheRealBanbury

    Joined:
    Dec 15, 2013
    Posts:
    248
    As usual, I can't help you, without a sample project. This could be a problem with your IK setup or a bug in the flipping method. But I can't tell from a screenshot :).
     
  9. HappyLDE

    HappyLDE

    Joined:
    Apr 16, 2014
    Posts:
    56
    First, thank you for responding :)

    For the issue, it's very simple to reproduce:

    1 - Doubleclick the SpritesAndBones.unitypackage to import into unity.
    2 - Drag one of the prefabs into scene, say the Orc.
    3 - Change the local x scale to -1



    Edit: BUT if i rotate on the Y axis by 180° it seems to solve the problem.
     
    Last edited: Aug 4, 2014
  10. TheRealBanbury

    TheRealBanbury

    Joined:
    Dec 15, 2013
    Posts:
    248
    If you look at your screenshot, you will see a button called appropriately 'Flip'. A lot of effort was made to put it there. You might consider using it ;).
    Scaling just doesn't work, because the IK calculations go all wonky. The Flip button makes sure, that all is rotated correctly. If you're using lights, you'll have to use the 'Use Shadows' button, too. This will flip the normals.

    Other than that, the rule remains: if you want support, create a sample project.
     
  11. TheValar

    TheValar

    Joined:
    Nov 12, 2012
    Posts:
    760
    Alternatively, if you are just wanting to flip your skeleton at runtime to handle different walk directions the following should work (this is how I do it)...

    1. Create Empty Gameobject named skeletonHolder (or whatever)
    2. make skeleton a child of skeletonHolder
    3. when you want to flip the character set skeletonHolder scale x = -1

    This may still screw up if the skeleton is in edit mode when you do it but if it's during gameplay it should not be in edit mode anyway.
     
  12. HappyLDE

    HappyLDE

    Joined:
    Apr 16, 2014
    Posts:
    56
    Thank you! Indeed i just saw the Flip buton :) and i see it rotates by 180deg on y axis which is easy to do in code too.

    If scaling cause these behaviours i'll just use the flip button instead. Thanks!

    Also thank you TheValar for an alternative just in case :D

    So problem solved!
     
  13. TheValar

    TheValar

    Joined:
    Nov 12, 2012
    Posts:
    760
  14. TheRealBanbury

    TheRealBanbury

    Joined:
    Dec 15, 2013
    Posts:
    248
    I'll promote it to all my loyal Twitter followers. All 12 of them :).
     
    TheValar likes this.
  15. TheRealBanbury

    TheRealBanbury

    Joined:
    Dec 15, 2013
    Posts:
    248
    I'm currently preparing a bugfix release for Sprites And Bones. If you know of any bugs, report them here.
     
  16. playemgames

    playemgames

    Joined:
    Apr 30, 2009
    Posts:
    438
    I fixed a few things related to saving poses and control points in Skeleton and Pose, and also had a minor change to PolyMesh, I'm sorry I have not had time to sort it out, but you may want to look at if you want to merge any my changes. Just ignore the color stuff I put in Skeleton if you want to keep it in Preferences. I also added that when recalculating bone weights in Skin2D and Bone so it automatically skins the mesh to the parent bone so it is visible. Skeleton calculate weights uses the influence for the original functionality.
     
  17. TheRealBanbury

    TheRealBanbury

    Joined:
    Dec 15, 2013
    Posts:
    248
    I will have a look at your fixes.
    Regarding the colors: How about a switch, that overrides the colors in the preferences?

    I have just added a tool to convert a skeleton into a ragdoll with a single click. And I fixed the Windows Phone 8 stuff.
     
  18. Keith90

    Keith90

    Joined:
    Sep 27, 2013
    Posts:
    116
    Hello,

    I just downloaded the asset and started to mess around with it. I must admit, I'm a little confused as to how to get the bones to match up with the sprite. I watched the first video and seen how to make a chain but when watching the second video, it automatically has a sprite set up.

    I'm use to animating in Adobe Flash so this is new to me, along with the IK (which I'm not 100% sure what it is, I believe it's moving a part of a body and having the other parts act accordingly?). Does anyone have any quick explanations regarding both? Instead of making a chain, I'd like to have the first bone be used as the torso and work off that, or is that not possible?

    Thanks for any advice/information.

    - Keith

    Edit: I forgot there were prefabs, so I think I'm going to try to use one of the examples to line of my sprites. Is it possible to add colliders to each bone so you can have different objects react with different parts of the body?
     
  19. TheValar

    TheValar

    Joined:
    Nov 12, 2012
    Posts:
    760

    Setting up sprites:
    Bones and sprites are all just game objects so just manually position the sprite in the scene so that it's lined up with the bone and then drag the sprite onto the bone in the gameobject hierarchy to make the sprite a child of the bone. You could do this in the opposite order as well (i.e. make sprite a child then position correctly).

    IK:
    Ik is basically just a convenient way to position multiple bones realistically and dynamically. For example you can use an IK point that ties into a wrist elbow and shoulder so that when you move it the whole arm will bend and straighten accordingly. You could also move the IK point via code to achieve cool effects like making the character point his arm at something or position his leg on a step.

    Colliders:
    bones are just gameobjects so you can apply colliders to them like you would any other object. Personally I would probably add colliders directly to the sprites however rather than the bones.

    "Instead of making a chain":
    Just uncheck "snap to parent" in the bone gameobject inspector. This will make it so you can position it freely.
     
  20. Keith90

    Keith90

    Joined:
    Sep 27, 2013
    Posts:
    116
    Wow. Thanks.

    I had just finished setting up a sprite, adding it to the bones. Very simple process it seems. I'm going to have to try IK since moving the limbs of the prefab without IK makes the arm rotate without moving the rest of the body. Unless I messed something up?

    Is there a reason for adding colliders to the sprites instead of bones? Reason I ask this, is if I wanted to allow a user to switch what the character looks like by swapping sprites on the bones, I'd lose the colliders. I think the solution to that might be is to add an empty game object to each bone and give that a collider.

    Also, in regards to your Dwarf in the Woods game, I'm curious on how you got the body parts to fly and move in arches when the enemies explode. Could you give some insight to that?

    I greatly appreciate it. Thanks.
     
  21. TheValar

    TheValar

    Joined:
    Nov 12, 2012
    Posts:
    760
    First off for character customization it's probably better to just switch out the sprite assigned to the gameobject rather than the whole gameobject. That way you wouldn't lose the colliders. But at the end of the day adding them to the bones would really work just as well.

    I achieved the exploding body parts effect by duplicating every sprite that was in the skeleton and adding a rigidbody component to it. So for example I would duplicate the head and make it a child of the original head. then add a rigidbody component and polygoncollider2d component to the duplicate and deactivate the object. Of course I also added particle effects and what not to each body part. When the character dies I iterate through each rigidbody body part, set active = true, parent = null, and apply a force to it. Then destroy the original character leaving only the body parts.

    If you want more info on that particular effect ask it in my Dwarf in the Woods showcase thread as it's not directly related to this plugin and I don't want to threadjack.
     
    theANMATOR2b likes this.
  22. Keith90

    Keith90

    Joined:
    Sep 27, 2013
    Posts:
    116
    Do you know if ragdoll physics are possibly with the bones or at all in Unity 2D? I know it is in 3D, not sure about 2D though.

    Edit: How easy is it to do animations with the bones? It seems the hands don't bend at the wrists when I move the IK.Hands.

    Edit 2: I think I may just animate the character in Adobe Flash, then have colliders match each sprite. It's a lot easier for me to animate that way. I may still try the bones to see how it works out.
     
    Last edited: Aug 7, 2014
  23. TheRealBanbury

    TheRealBanbury

    Joined:
    Dec 15, 2013
    Posts:
    248
    Yes, that's very possible. The next version will include a tool to turn a skeleton into a ragdoll. The effect is really cool, if I may say so myself. But you can add 2D colliders and hinges to the bones yourself, if you don't want to wait.

    It's easier than without bones.
    If you want the IK to control the hand, attach the IK component to the hand bone. Then set the length of the IK chain to the number of bones in the arm.
    2D or 3D - the principle is the same. I suggest watching a few IK tutorials for Blender. Sprite And Bones's IK is loosely modeled after Blender's.
     
  24. Keith90

    Keith90

    Joined:
    Sep 27, 2013
    Posts:
    116
    I'll have to give it a shot. See what animation method works best for me. Thanks. :)
     
  25. playemgames

    playemgames

    Joined:
    Apr 30, 2009
    Posts:
    438
    Maybe that would be ok, or a menu item under "Sprites And Bones" for Skeleton colors. Personally I just like editing it right in the skeleton. I fixed a minor bug in Skin2D with the parent to bone weighting, also I think it might be worth while to look into that Pretty Poly code I posted earlier for a better way to create Polygon meshes for the SkinnedMeshRenderer, the Polygon collider method is ok, but leaves very little control over the way the triangles are made, I think something a bit more robust in this area would make mesh deforms all the better if they can be made easier right in Unity. I find myself using a lot of trial and error when creating deform meshes with the Polygon collider in creating a decent mesh. I don't have a lot of time to work with it right now, but maybe you can make more sense on how to do it than I can. The code to look at is here:

    https://bitbucket.org/q_bert_reynol...79043a4436b04/Scripts/PrettyPoly.cs?at=master

    And the drawing method for creating the polygons is here:

    https://bitbucket.org/q_bert_reynol...4436b04/Editor/PrettyPolyPainter.cs?at=master

    Really neat stuff, I wish I had more time right now to wrap my head around it, hopefully you can see if it can be implemented for creating better deform meshes than the methods we have now.
     
  26. TheRealBanbury

    TheRealBanbury

    Joined:
    Dec 15, 2013
    Posts:
    248
    I watched the PrettyPoly video and it's pretty awesome. The source code seems to be straight forward enough. The mesh creation looks downright simplistic. Are you sure, it creates better meshes than the triangulator class, I'm using already?
     
  27. playemgames

    playemgames

    Joined:
    Apr 30, 2009
    Posts:
    438
    I am not sure, but it may even use it as well. I think in our case it may be better to draw or paint the points and have them triangulate as they are drawn (like for every 3 points triangulate). Then have a button like in the weight painting to stop the mesh creation when finished. That way at least there is a bit more control over how points are drawn and triangulated on the mesh.
     
  28. mayhemandeggs

    mayhemandeggs

    Joined:
    Apr 12, 2014
    Posts:
    7
    Does this work with Unity 4.2?
     
  29. Maskimus

    Maskimus

    Joined:
    Apr 6, 2013
    Posts:
    4
    Hi, first of id like to thank those involved with this plugin, it looks to be just what i need.

    So i'll get straight into it, I'm having a bit of trouble with the mesh deformation, im wondering if anyone would be nice enough can point me in the right direction.

    Iv followed this tutorial with both my own sprite and the ones provided and keep running into the same issues. -


    First issue is, the sprite isn't showing up in the scene/game window only the mesh, and i receive this error constantly.

    "SkinnedMeshRenderer requires a mesh with skinning or blendshape information.
    UnityEditor.DockArea:OnGUI()"

    ScreenShot : http://i.gyazo.com/9ad35d75dd453a137db4b87b97bb536e.png

    Second issue (which i assume is related to the first) is I get to the point of calculating weight bones, and nothing happens, mesh doesn't turn blue, and bones aren't linked to the mesh.

    Thanks
     
  30. TheRealBanbury

    TheRealBanbury

    Joined:
    Dec 15, 2013
    Posts:
    248
    Yes, it does.

    The error message says, that your mesh has no vertex weights setup. That's also why the texture doesn't show up. Since you haven't calculated the weights correctly, that's normal.
    It's difficult to guess, what step you missed. Rewatch the video and try to follow it as closely as possible. If you can't get it to work, tell me every step you did (each button click and whatnot).
    Settting up a deformable mesh, is obviously still too complicated. I guess, I have to find an easier way.
     
  31. TheRealBanbury

    TheRealBanbury

    Joined:
    Dec 15, 2013
    Posts:
    248
    I'm rewriting the whole skinned mesh code, since users have so much trouble using it. I will streamline the whole thing into a single component, that will create the mesh from a sprite and bind the bones to the mesh. Afterwards the user can fine-tune the mesh and the bone weights.
    I hope this will make it easier to work with deformable meshes.
     
  32. mayhemandeggs

    mayhemandeggs

    Joined:
    Apr 12, 2014
    Posts:
    7
    OK I'm a noob when it comes to Unity but when I open up the test scenes in 4.3 I get blank scenes and error messages on the scripts "The associated script cannot be loaded. Please fix any compile errors and assign a valid script."
     
  33. mayhemandeggs

    mayhemandeggs

    Joined:
    Apr 12, 2014
    Posts:
    7
    error CS0234: The type or namespace name `Sprites' does not exist in the namespace `UnityEngine'. Are you missing an assembly reference?
     
  34. TheRealBanbury

    TheRealBanbury

    Joined:
    Dec 15, 2013
    Posts:
    248
    I'm not missing any assembly references, but you might ;). Seriously, I'm no mind reader. Please provide a download for a project with your error, or I can't help you.
     
  35. mayhemandeggs

    mayhemandeggs

    Joined:
    Apr 12, 2014
    Posts:
    7
    But I just created a new project and tried to open one of the test scenes so I don't think sending you an empty project will help... I really am a newb, I know next to nothing about scripting and I'm no Unity expert. I come from an animation background and I just wanted to give this a try.
     
  36. TheRealBanbury

    TheRealBanbury

    Joined:
    Dec 15, 2013
    Posts:
    248
    If you're using an empty project, than you don't have to be surprised, if it doesn't work. You need to import the whole package into your project, including all the script files.

    This reminds me of the time, I was working in support. A guy called me, who had problems starting our software. Turns out, he 'cleaned up' the application folder, by deleting all those 'superflouus' DLLs. :)
     
  37. TheValar

    TheValar

    Joined:
    Nov 12, 2012
    Posts:
    760
    do you mean "empty" as in New Project > Import Sprites and Bones > open test scene?
     
  38. playemgames

    playemgames

    Joined:
    Apr 30, 2009
    Posts:
    438
    First off, I do not believe it will work with 4.2 as a lot of the new code works with Unity 4.5 (probably minimum 4.3) including Unity's sprites. That is probably why you are getting the error of the Sprites missing in the UnityEngine namespace.

    I wish I had time to do a tutorial on this, but the easiest way is to just select the sprite after it has been parented to a bone, and go to the menu "Sprites And Bones/Skin2D" and it should automagically create a mesh and assign the vertices to the parent bone. That is if you are using the latest version from my unstable branch. I don't see how it can be mush easier than that.

    Otherwise if the created mesh is not good enough, you can create a polygon collider on a sprite, then use "Sprites And Bones/Create Mesh" from the menu. This will only create the mesh, you can replace the mesh in the Mesh Filter Component of Skin2D and then press the "Recalculate Bone Weights" which should weight all the vertices to the parent bone. To do any manual re-adjusting of the bone weights of the mesh you have to go the menu "Sprite And Bones/Weight Painting" and make sure the Skinned Mesh Renderer that you want to change the weights is selected and change the bone you want to weight it to in the drop down menu to paint the weights for that bone.


    Interesting, let me know when you start so I can look at it, I'll see if I can help when and where I can. I also don't want to break any of the rigs I am working on. Will you be creating a tool to go with the mesh creation/fine tuning of the mesh?
     
  39. TheRealBanbury

    TheRealBanbury

    Joined:
    Dec 15, 2013
    Posts:
    248
    @playemgames: I've written a new component, that eventually should replace Skin2D. In its current state all that's needed, is to assign a root bone and a sprite, and the component creates a mesh and a material and binds the mesh to the bones. It's a two click affair and everything is setup. That's the good news. The bad news is, that creating prefabs and the weight painting are broken. If you could look at these areas, it would be a great help. Honestly Unity is driving me crazy right now. Working with assets and prefabs is especially awful. Whoever designed this should have his programmer's license revoked.
    I will push the changes in a minute.
     
  40. playemgames

    playemgames

    Joined:
    Apr 30, 2009
    Posts:
    438
    Alright let me see what you've done with it. I've basically been creating rigs these past few weeks to prep for my game's animations and still working on one now. I don't necessarily think the way we have it now is bad, just needs to be documented with the changes we have made. As I said I think the only thing that needs work on is the deform mesh editing since it is very rudimentary at this point. Click on a sprite parented to a bone and pressing "Sprites And Bones/Skin2D" is not bad, but the mesh editing is. I think if you want to stray from using assets and prefabs, you could look into saving the format of the bones/mesh/pose/whatever into a json format or xml or something that can be saved/loaded easily by Unity and can also be used in other programs. It just needs a good structure for loading/saving the data is all.
     
  41. playemgames

    playemgames

    Joined:
    Apr 30, 2009
    Posts:
    438
    You did a lot of moving around of functions, so I'm going to have to look into it a bit more when I have time. It looks like the way the mesh creation is being done might be the culprit. Maybe in calculating the initial weights is why the Weight Painting is broken, as for Prefab generation, there is a lot of new code to sift through so I am not sure where that is breaking exactly.

    I think generating the mesh initially through the function I wrote using the sprite's original mesh is better than the triangulate functions you are using now since it is doing calculations that are unnecessary since a sprite mesh already exists (using Vector2[] vertices2D = UnityEditor.Sprites.DataUtility.GetSpriteMesh(sprite, false); int[] indices = UnityEditor.Sprites.DataUtility.GetSpriteIndices(sprite, false).Select(element => (int)element).ToArray() ). I've had some images not triangulate using the bitmap functions properly because some of the image doesn't triangulate well. Using the SpriteMesh.CreateSpriteMesh() function I wrote should be all you need to generate the mesh, but as I mentioned earlier, to edit or create a new mesh from scratch using points would be a good addition.

    Look into some of the changes I made for the weighting the mesh to the parent's bone, it's a pretty simple and effective method really, if you create a Skin2D from a sprite that is parented to a bone, it will just automatically map the vertices to that bone, you can fine tune it later with Weight Painting, if someone wants to weight it using bone influence, they can do the Calculate Weights button under Skeleton. All the functionality to make things simple already exists, it just needs some documentation to make it clearer, the current tutorials should be considered outdated now.
     
  42. TheRealBanbury

    TheRealBanbury

    Joined:
    Dec 15, 2013
    Posts:
    248
    I didn't change that much of your SpriteMesh functions. I made them static and renamed one. The rest of the code I've added is mostly reused from my own code in the original Skin2D. I believe the main problem is my abusing of the OnValidate function. It's not really meant for what I'm doing.
    I'll have a look at your changes, when I can stand looking at Unity again :).
     
  43. TheRealBanbury

    TheRealBanbury

    Joined:
    Dec 15, 2013
    Posts:
    248
    I have just released version 1.2.1 of Sprites And Bones. Read all about it here.
     
  44. Petrol

    Petrol

    Joined:
    Aug 7, 2014
    Posts:
    12
    Hello,

    I first want to thank you for this addon which looks amazing.

    I followed the first tutorials without any problem and found the addon really to use. Again you are really doing a great job !

    Sadly when I tried to build the project (which only contains the addon and an empty scene), I had the following error :

    Assets/SpritesAndBones/Scripts/Skin2DX.cs(29,7): error CS0246: The type or namespace name `UnityEditor' could not be found.
    Are you missing a using directive or an assembly reference?
    Then I added a #if UNITY_EDITOR around the "using UnityEditor;" in the files Skind2DX and SpriteMesh (which had the same error).

    After that I got another error :

    Assets/SpritesAndBones/Scripts/Skeleton.cs(275,18): error CS1061: Type `Skin2D' does not contain a definition for `CalculateBoneWeights' and no extension method `CalculateBoneWeights' of type `Skin2D' could be found (are you missing a using directive or an assembly reference?)
    All that to say that I didn't solve anything and that I'm now looking for your help : )

    I'm using Unity v4.5.2 and a fresh SpritesAndBone just downloaded from your Repo.


    The following link is a zip with the current project that give me the errors ( an empty project with the addon freshly imported)

    https://app.box.com/s/p6bwkk202ggrnphm1to7

    Thanks !





     
  45. TheRealBanbury

    TheRealBanbury

    Joined:
    Dec 15, 2013
    Posts:
    248
    Oh bother! I really should remember to compile a game now and then. Shows that nobody is really using this stuff. I will correct the bug and release another version.
     
  46. TheRealBanbury

    TheRealBanbury

    Joined:
    Dec 15, 2013
    Posts:
    248
    I have uploaded version 1.2.2. Creating a standalone game should now work.
     
  47. Petrol

    Petrol

    Joined:
    Aug 7, 2014
    Posts:
    12
    Thank you !
     
  48. Priabudiman

    Priabudiman

    Joined:
    Dec 22, 2012
    Posts:
    6
    @TheRealBanbury i cant move the bones after all after create IK and Assign a Helper, when i drag helper around its just move the helper alone, not the bone.

    I embed the video showing the Anomaly.



    Thank you so much! hopefully there's a fix on this or maybe i did something wrong, please let me know.
     
  49. Petrol

    Petrol

    Joined:
    Aug 7, 2014
    Posts:
    12
    I guess that's because you must exit the edit mode before moving the Helper :

    Select your Skeleton and hit [TAB]
     
    Last edited: Aug 17, 2014
  50. iKonrad

    iKonrad

    Joined:
    Jun 23, 2013
    Posts:
    179
    Hi!

    I've tried to apply this awesome plugin into our project, but I've encountered a problem - maybe you'll be able to help me with this one.

    I've got a character that consists of separate image parts: legs, hands, head, spine etc. I have converted these sprites into meshes, so all the parts are smoothly bendable, but from what I've seen in your tutorial, only one mesh can be used for bone skinning (assigned in 2D skin). Is there a way to use multiple meshes?

    Thanks
     
    Last edited: Aug 17, 2014