- تم التحرير
HELP! preventing AddAnimation's loop Q.q
My 'landing' transition animation different from 'falling' transition animation is working pretty fine except it loops even in syntax:
pcAnim.state.AddAnimation(0, "trans_fallToIdle", false, 0);
I lately read that looping is part of AddAnimation's nature, but I thought I had control over the loop since it had looping boolean?
What can I do to prevent this unwanted animation looping if I'm using AddAnimation? or is there a better way to connect from "loop_animation_A to non_loop_transition_animation_B?'
The reason I chose to connect these 2 was because of the nature of AddAnimation queuing animation instead of setting it interrupting in mid play of prior.
You mean you want to terminate A's loop and have B play when A finishes its current iteration?
31 Oct 2016, 09:34
You mean you want to terminate A's loop and have B play when A finishes its current iteration?
Xelnath wroteYou mean you want to terminate A's loop and have B play when A finishes its current iteration?
31 Oct 2016, 09:34
You mean you want to terminate A's loop and have B play when A finishes its current iteration?
It's the other way around. 'A' being the 'in air' 'falling' animation is working just fine. However, 'B' that is transition animation inbetweening 'falling to idle' is connecting just fine only that it loops after the good connection since I queued it via AddAnimation. What I need to terminate is the looping of 'B's and I find I need more than 'SkeletonAnimation.state.AddAnimation (0, "tansition animation", false, 0)' to prevent it and that's where I'm stuck at.
I tested if SetAnimation would fix this unintended looping of B but instead it just never connects right with A.
This is odd. If you add an animation and don't explicitly set it as looping... it doesn't loop.
Xelnath wroteThis is odd. If you add an animation and don't explicitly set it as looping... it doesn't loop.
Odd indeed. Since you told me you can't reproduce my error on your side I changed my controlling script to following :
#region In air animations
if (Input.GetKeyDown(KeyCode.Space) && player.onGround)
{
SetAnim("jump", false);
AddAnim("trans_jumpToFall", false);
}
else if (!player.nearLand && !player.onGround)
{
AddAnim("fall", true);
}
if (!player.onGround && player.nearLand)
{
AddAnim("trans_fallToIdle", false);
}
#endregion
And the result here I get is the fallToLand transition's queue working only when neither of the booleans(onGround & nearLand) are true. I speculate this due to another AddAnimation queued is overriding intended play order (i.e. idle animation is overriding its queue since both animations use those boolean checks atm).
So I was looking into more efficient way of triggering both animations in good separated checks, but struggling.
One thing I'm sure I need is way to store previous and current animation being checked so that I can signify my if statements. Any suggestions?
Note that if you add the animation several times, it will look like it's looping. But all it's doing is following several calls of AddAnimation.
If you placed this in Update()
, which is called once per frame, and your conditional resolved to true for several frames, it will call AddAnimation for several frames. That's just what your code does.
So yes, it's probably better for you to store states and check that so you know AddAnimation/SetAnimation isn't called repeatedly. There are several ways to do it. You could make an enum. You could store several bools. You could store the animation object reference. The animation name. Use whatever works best for your system.
Pharan wroteNote that if you add the animation several times, it will look like it's looping. But all it's doing is following several calls of AddAnimation.
If you placed this inUpdate()
, which is called once per frame, and your conditional resolved to true for several frames, it will call AddAnimation for several frames. That's just what your code does.So yes, it's probably better for you to store states and check that so you know AddAnimation/SetAnimation isn't called repeatedly. There are several ways to do it. You could make an enum. You could store several bools. You could store the animation object reference. The animation name. Use whatever works best for your system.
Thanks for the hints!
I'm getting such inconsistent animation triggering results via enum flagging, though..! Gosh the headache..!
I feel you, affinity!
I wrote my own state machine to drive adding and setting animation states