EntropicEquanimity

Good day stranger, as the title suggests, I've been wracking my head around trying to figure out why some animations won't play when I set them to play using SetAnimation()

Just a short description of the project I'm working on: Mobile Auto Chess Style drag n drop heroes/characters and they fight automatically.

Basically I have a setup where upon starting the game, the character will enter the initial state with events added on to the Complete event and Event event. It looks something like this in code:
TrackEntry trackEntry = _animState.SetAnimation(mainTrack, skillOneAnim, false);
trackEntry.Event += SkillOne;
trackEntry.Complete += delegate { TransitionCheck(); };
return trackEntry;
TransitionCheck is basically a big if else function that will switch states depending on whether or not the requirements are fulfilled for each individual character. It will direction call another function that is basically identical to the snippet above.

Now the problem lies in how sometimes the animation will initialize and start playing (It calls the Start event as well) but in reality the animation isn't playing. What I mean by that is that it enters say, for example, the animation for this character's skill one but the animation really playing is the previous animation that was set. The Event event and any other events on the trackentry are just seemingly discarded after the initial trigger of the Start event.

What confounds me is that it seems to be random for each character. Sometimes none of the characters can use their abilities, all they can do is loop attack and movement animations. Other times, one character can use their skills and others can't. And the changes seem to be happening randomly, without me changing anything to their controller.

One of the most peculiar problems I've encountered so far is that no matter what I do, none of the characters can use their Ultimate (Basically skill 0). I just don't understand why because their logic is identical to the other skills'.

Ok, I kinda ranted a bit there but I've been stuck on this for a week with no progress in sight. Here's a quick recap of all that I've noticed:

    1. Recompiling the project files seems to give me different results from time to time. (As in skills being successfully used)
    2. ALL the characters have the exact same animation names and event names. Just so I won't get mixed up.
    3. When the problem occurs, the Start event of the Animation is triggered but nothing else. The correct animation doesn't play and the other events in said Animation don't trigger either.
    4. (Probably unrelated) Sometimes parts of the characters disappear during animations, also completely at random, or so it seems. It's always the same parts for the same characters. Like one character's face just disappears occasionally. Another just loses a hand and the shield he's holding.

Is there a known bug like this or am I just missing something super obvious in my code? I haven't had the time to pour over the forum yet...
EntropicEquanimity
  • 記事: 2

Nate

The complete event occurs only once the animation time has reached the animation duration. Likely the animation time has actually exceeded the animation duration by a small amount. If you set a new animation and use a mix duration, the current animation for the track will be the one you set, but the previous animation will also be applied during the mix duration. If your first animation is set to loop, you'd see it start over during the mix duration. If not, you'd see the last frame during the mix duration.

Next, events are still fired for the animation being mixed out (the previous animation during the mix duration, described above). That means you can receive a complete event for an animation being mixed out and that may trip you up. You can check the TrackEntry for the event to see if it is the current entry TrackEntry using AnimationState getCurrent or if TrackEntry getMixingTo is not null then it is not the current entry.

When you set an animation, are you using a mix duration? If you want to use the complete event to set the next animation, you may want to use a mix duration of 0. You will never get a complete event for the previous animation if the mix duration is 0. Otherwise you may want to set the next animation before the complete event for the current animation, so the mix duration happens before the animation duration is reached. FWIW, when you use AnimationState addAnimation to queue an animation and you pass 0 for delay, it uses a delay equal to the previous animation duration minus the mix duration, so the mix completes just as the previous animation reaches its duration.

I'm afraid I can't tell why you'd see an animation start event and then nothing else. The AnimationStateListener events provide precise guarantees about when they fire and the code for that is well tested. For example, if you see start you should always see end some time afterward, if another animation is playing.

Ideally you can create the simplest possible Unity project that shows the problems you are having. I know they seem to be intermittent, but maybe you can isolate the issue. Unfortunately we can't review your entire application code.

Otherwise you could try to debug the problem. AnimationState is a complex beast, so I don't recommend trying to understand it all, but maybe you could breakpoint when start is happening when you think it shouldn't and then step through to figure out where that TrackEntry goes.
アバター
Nate

Nate
  • 記事: 11351

EntropicEquanimity

Hey Nate, thanks for the reply.

I will try to isolate the issue as best as I can, probably starting with figuring out why the events after
Start
don't fire.

I'm using a 0.1 mix duration and I call SetEmptyAnimation whenever a skill animation is about to play. Prior to using SetEmpyAnimation, I used ClearTrack but that led to characters being left in wonky positions, like 30 degrees tilted forward.

If I have any breakthroughs I'll update this thread :)

---

LOL ok so I figured out the problem earlier today. It had nothing to do with Spine whatsoever. I just... missed an else in the list of if-else statements...... hahaha. Anyways, lesson learned.

In short, the first skill was being called and added to the queue but almost immediately afterwards, it would be interrupted by another state. I suppose there was enough time between when the first else if statement was invoked and the other proceeding states were called to allow the Start event to fire but not any of the other events.
EntropicEquanimity
  • 記事: 2

Nate

Ah well, glad you figured it out!
アバター
Nate

Nate
  • 記事: 11351


Return to Unity