Using DragonBones in Unity


I recently came across this Animation tool called DragonBones. Which looks very light and easy and compatible to unity using this Unity C# Plugin. Though the plugin is really lacking documentation, it comes up with a demo project which can give you an idea about how to use it. So here I am posting a easy guide here for get started with it fast.

Creating animation

First I created parts of my character as images. And then put them together in DragonBones with a bone structure. Then created few animations, such as Walk, Jump, Run etc.

Exporting for Unity

Dragonbones saves the project as a *.dbproj file. It can be exported to a compatible for for unity plugin.

Screen Shot 2017-07-08 at 5.34.47 PM

It creates 3 files. A *_tex.png file which contains texture atlas, a *_tex.json file which contains texture information and a *_ske.json file which contains the skeleton and animation information.

Setting up DragonBones Plugin for Unity

For setting up only the DragonBones & MiniJSON has to be imported into your unity project. i.e. Just copy the DragonBonesCSharp/Unity/Demos/Assets/Scripts/DragonBones folder into your unity project Asset folder.

Importing in Unity

Put the exported json and png files under Asset/Resources in your project. Open a scene in your project. Create a new empty object. Add new component to that object as “Unity Armature Component”.

Screen Shot 2017-07-08 at 5.52.29 PM.png

Select a your *_ske.json file as DragonBones Data. A Create button would appear. Pressing that would import the model and animations.

Screen Shot 2017-07-08 at 5.56.46 PM.png

Using Plugin for Animations

Animations can be easily handled from code by accessing the UnityArmatureComponent component. Attach your C# code to the same GameObject and try adding a code similar to the following code.

 UnityArmatureComponent armatureComponent = GetComponent<UnityArmatureComponent> ();
 armatureComponent.animation.FadeIn ("Walk", 0.25f, -1);

The default animation for my “Rama” character was “Idle”. This would make the a transition to “Walk” animation in 0.25 seconds, and loop in “Walk” animation infinitely (-1).

The GotoAndStopByProgress function can be used to control an animation frame by frame. Such as moving hand of the character according to mouse movement.

public void LoadArrow(float arrowLoadProgress) {
    armatureComponent.animation.GotoAndStopByProgress (loadArrowAnimation, arrowLoadProgress);

And the is a few more similar functions in the library. These can be mixed to create awesome animations. The following video shows result of a small implementation.

Just for information, I have used Unity 5.3 and DragonBones Pro 3.9.

I have uploaded the example project in BitBucket. Please find it in the following link if you require help. Animation related operations are available in Assets/Scripts/CharacterAnimation.cs.

Repository Link: external_link-512

Please leave your comments if you liked or disliked my post.


18 thoughts on “Using DragonBones in Unity

  1. Hello, great tutorial. Can you please upload this examples code on github or somewhere else? Can’t handle using FadeIn or Run in Update() game cycle. But in this video animation changes in a runtime.

  2. hi Rakesh

    Wow this is so inspiring, Thank You! 🙂

    I have been trying out DragonBones animations in my Unity Projects lately and I have been making lots of progress UNTIL I tried to build my game with Unity’s compiler. No matter what I tried I kept getting this same compile error:

    Error building Player because scripts had compiler errors

    The scripts work well and the game plays well in Unity until compilation then this UnityArmatureComponent.cs error appears. My search on the web revealed nothing yet. I would just like to know if you had a similar serror compiling DragonBones scripts in UNity? Any feedback would indeed be greatly appreciated as I am Loving working with DragonBones so far and it would be a shame to ditch it now because of this failure to compile the game. Thanking you in advance 🙂

    1. Hi, Glad that you found it helpful. 🙂

      But I didn’t get any such errors. Could you mention what were the compilation errors and what platform you were trying to build for. And you can try getting help from Unity Forum or Unity Answers. I mean post your issue there. It’s quite helpful.

  3. Hello, your tutorial really help much! 🙂

    But I’ve encountered a problem where dragonBones armature cannot show up in unity canvas.

    Is it possible to use armature in unity canvas?
    Can you make a tutorial on using armature in unity canvas?
    Or the only way is to export an image sequence then use it in Canvas Image?

    1. The plugin does not show the armatures on Unity canvas. It only shows the images and animation. If you need to do any changes in armatures, you need to do that in DragonBones application and reimport it in Unity

  4. Hey Rakesh. So you mean to say that we can control animations through unity’s Animation functions or dragonbones ones. The functions of db lack documentation. I don’t know how fade in works and and what parameters and all to pass.

    1. No it’s not through unity’s animation function. UnityArmatureComponent is a DragonBones class.
      And yes, there is very little documentations and whatever is there is in Chinese i think. Only the demo project that comes along with the plugin helps a little to learn about it. You can refer my test project too. its available in this page.

      1. Rakesh. Okay but not all makes sense since my coding skills are bit rusted. Can I reach out to you by social media say Twitter in case I have doubt?

  5. “The GotoAndStopByProgress function can be used to control an animation frame by frame”…… i would really like to get to know more on this cause i am making a game where the player shoots and would love to use this method …. one question is how do you set it up in dragon bones cause i am guessing there is sprite attachment so that when you import it in unity you could control the character

    1. There isn’t much about the function except what is mentioned up this page.
      GotoAndStopByProgress(animation, progress).

      The sprite sheet will be generated when you export an animation from dragonbones software. Importing the json file in Unity will import the sprite too.

      And for both your questions, you can take a look at my example project linked in this page. There is a very simple character animation. Let me know if it helped 🙂

  6. How can I play 2 animation on a sequence. because if i just put another animation below, only the last animation that will be executed.

    1. You need to play 2 animations in separate layers
      armatureComponent.animation.FadeIn(“animation 1”, 0.05f, -1, 0 /*layer 0*/);
      armatureComponent.animation.FadeIn(“animation 2”, 0.05f, -1, 1 /*layer 1*/)

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s