question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Animation is not playing problem

See original GitHub issue

Hi there, I have created a simple animation using Dragonbone pro, now when I want to use that animation in unity it stuck on last frame in another word no animation is played but stack on one frame. Here is the code I use:

`using System.Collections; using System.Collections.Generic; using UnityEngine; using DragonBones;

public class Player : MonoBehaviour {

private UnityArmatureComponent player;

// Use this for initialization
void Start () {

	player = this.gameObject.GetComponent<UnityArmatureComponent>();
		
}

// Update is called once per frame
void Update () {

	if(Input.GetKey(KeyCode.LeftArrow)) {
		
		player.animation.Play ("walk", -1);

	} else if(Input.GetKey(KeyCode.LeftArrow)){
		
		player.animation.Play ("walk", -1);
	
	} else {
	
		player.animation.Play ("stand", -1);
	}

}

} `

Any help is much appreciated.

Issue Analytics

  • State:open
  • Created 7 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
chriswaldron15commented, Jan 18, 2017

No problem!

So basically before, an animation was being started every frame, and usually the same animation. DragonBones won’t check whether that animation is already playing and ignore the new Play call, so it will start the animation from its first frame every Update call. So the animation never gets past the first frame.

Perhaps Unity’s animation checks whether that animation is already playing and so doesn’t start it from the beginning again, but it’s a bit more complicated because it uses states.

If you want to check whether an animation is already playing, you can call:

player.animation.GetState("Walk").isPlaying;

This might be cleaner than the code I was providing! And then only call Play(“Walk”) if that animation is not playing.

2reactions
chriswaldron15commented, Jan 17, 2017

The issue here is that every update you are starting an animation. This means either the walk or stand animation is starting every single frame, so it never goes past the first frame.

This might work a bit better:

void Update() 
{
	bool moveKeyPressed = Input.GetKeyDown(KeyCode.LeftArrow) || Input.GetKeyDown(KeyCode.RightArrow);
	bool moveKeyUp = Input.GetKeyUp(KeyCode.LeftArrow) || Input.GetKeyUp(KeyCode.RightArrow);
	bool moving = Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.RightArrow);
	// if any move key was pressed down this frame, start walk animation
	if (moveKeyPressed){
		player.animation.Play("Walk", -1);
	}
	// else if not moving at all and a movement key was released
	else if (!moving && moveKeyUp){
		player.animation.Play("stand", -1);
	}
}

The gist of it is you only play the stand animation the frame that the player stops moving completely.

Read more comments on GitHub >

github_iconTop Results From Across the Web

CSS Animations Not Working? Try These Fixes
Another reason why your animation isn't working might be that you're attempting to animate a CSS property that isn't animatable. Check our list ......
Read more >
Animation not playing correctly - Scripting Support
I have successfully scripted a “swing bat” animation, but it does not play fully. The ingame result is here: And the actual Animation...
Read more >
Animator not playing animations
I'm new to unity trying to set up a simple UI that makes a wolf 3D character sit. I set up a two...
Read more >
Pressing "Play Animation" Not Doing Anything
In may case "Play animation" button played one frame forward and played normally backward. There was no sound.
Read more >
What should i do if animation is not working
Okay thanks. The first thing I suggest is to make sure all the options under [your profile icon] > Photos settings > Photo...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found