aditya

Okay so i've just started using spine in unity, my problem is that my character just have one animation on it and i don't want it to loop as it is a jump animation which i only want to play when i touched my phone screen ... animation is playing for the first time (when game loads) but after that there is no animation playing on touching my phone screen ... plus as soon as i turned my character into a prefab, the script that is handling the animation getting an error in inspector which is saying something like this "ERROR : must have reference to SkeletonData asset" or something like this, what is this as it is only appearing when i m making prefab of my character
aditya
  • Mesajlar: 4

Pharan

Sorry, that was confusing.

What's wrong and what are you trying to do?
Kullanıcı avatarı
Pharan
  • Mesajlar: 5366

aditya

Pharan yazdı:Sorry, that was confusing.

What's wrong and what are you trying to do?
I want my character to jump and i unchecked the LOOP option coz i don't want this jump-animation to loop, but now this jump animation is only playing when my game loads but after this it is not playing at all, i used both functions that is SpineAnimation.AnimationName and SpineAnimation.state.SetAnimation, nothing is working
aditya
  • Mesajlar: 4

Pharan

Can you post your code where you're trying to control the animation?
Have you tried leaving the Animation in the inspector dropdown empty?
Kullanıcı avatarı
Pharan
  • Mesajlar: 5366

aditya

No i didn't left the Animation dropdown empty ... plus i only have one animation that is the jump animation

Here is the code :
public bool isOnGround;

private bool touched;
private Touch scrTouch;

[SpineAnimation]
public string jumpAnim;

private SkeletonAnimation skelAnim;

void Start(){
skelAnim = GetComponent<skeletonAnimation>();
isOnGrounnd = false;
touched = false;
}

void Update(){
handleTouch();
if(touched){
touched = false;
isOnGround = false;
}

if(!isOnGround){
//skelAnim.state.SetAnimation(0, jumpAnim, false);
skelAnim.AnimationName = jumpAnim;
}
}

void handleTouch(){
if(scrTouch.phase == TouchPhase.Ended && scrTouch.phase != TouchPhase.Canceled)
touched = true;
}
the isOnGround variable is handle by another script that is checking if character is on ground or not, if yes then that script will set this variable to true
aditya
  • Mesajlar: 4

Pharan

I recommend using SetAnimation. Its behavior is more predictable.

AnimationName is just a property detached from the thing that's actually playing the animation.
Changing it plays a new animation. If you say AnimationName = jumpAnim and AnimationName was already == jumpAnim. It won't do anything.

SetAnimation will search for the animation with the name you gave it, then play that animation.
Fundamentally, it functions very differently from AnimationName = x
skeletonAnimation.state is the actual thing managing the progression of the animation.
When you call SetAnimation, the animation starts playing from the beginning.

But your controller logic is flawed for that.
It's actually flawed for other uses too. You'll fix that yourself, I guess.

But if it says
void Update () {
if (!isOnGround) {
skelAnim.state.SetAnimation(0, jumpAnim, false);
}
}
Whatever is inside Update gets called every frame.
It keeps calling SetAnimation,
SetAnimation keeps playing the animation from the beginning,
and you end up seeing is the first pose of the animation every frame.

This is closer to what you want:
void Update () {
if (!isOnGround) {
MySetAnimation(jumpAnim, false);
}
}

// Non-overriding SetAnimation stump
void MySetAnimation (string animationName, bool loop) {
const int TRACK = 0;
var state = skelAnim.state; if (state == null) return;
var current = state.GetCurrent(TRACK);

if (current == null || current.Animation.Name != animationName) {
state.SetAnimation(TRACK, animationName, loop);
}
}
But this is just to get it working.

If you're making something that controls animation, it needs to detect changes in the character's state, and make sure to change the animation only at the points when the state changes. This is pretty much true anywhere, even if it's done for you implicitly.

Spine's AnimationState doesn't take that route since it's designed to be flexible and its uses still spans a pretty broad range of animation control styles.
Kullanıcı avatarı
Pharan
  • Mesajlar: 5366

aditya

Thnx a lot Pharan it worked ... how stupid i m by not thinking about the UPDATE thingy :)
aditya
  • Mesajlar: 4


Dön Unity