- Home /
Mecanim when call setTrigger, plays next clip twice
I am working on a simple 2D matching game. The facedown state is a simple animation that is 1 second long and loops. The idle state is for the card when it is face up. A 2 second animation loop plays here for the character on the card. The flip state is an animation that rotates the card, simulating a flip.
I have a simple state machine:
![alt text][1] [1]: /storage/temp/20763-statemachine.png
Transitions:
faceDown -> Flip transition when the flipTrigger(Trigger) event is called
Flip -> Idle transition on Exit and if isFaceDown(boolean) = false
Idle -> Flip transitions when the flipTrigger event is called
flip -> faceDown transition on Exit and if isFaceDown = true
The problem though is that from both the faceDown and Idle states, when I call the flipTrigger, the flip state actually plays through the animation twice.
Loop Time for the flip animation clip is toggled off.
I'm really at a loss here. Any help would be much appreciated!
Thanks!
THE TRANSITION LENGTH $$anonymous$$UST BE SET TO ZERO - an annoying gotchya.
Answer by kento14 · Jan 02, 2017 at 10:15 AM
@LeandroExHuMeD hopes this helps :)
Here is the run animation running 2 times. 1 time of its full length, and one time with the starting bit, where it transitions over to the death animation.
Here is the exit Time set to a little under 1 and transition duration set to 0 that means that the run animation only will run 1 time of its full length and then go to the next animation. :)
This worked for me just. if you want to smooth transaction between animations set exit time to 0.75.
Answer by Vyross · Jan 26, 2014 at 02:03 PM
Just spent literally two hours trying to find out the answer to this. Here's what was going on with me:
I had two states: Fire and Idle. Under the transition between Idle -> Fire, there was a gradient. I had to scroll to the right (hold middle mouse button and drag). Fiddle with that, and you can adjust the timing, how many times each animation plays during the transition, and so on.
I spent about the same time messing around with the transition myself. However, I was not able to fix the multiple triggers. In the window that you are referring to, I made sure that each clip only appears exactly once. Still very strange!
same thing here, but i solved it. if your clip is very very short your condition is set to exit time, your exit time has also to be very very short. Else the clip gets triggert twice wich seems to be intended :)
good luck!
Had this problem, too. but my solution was rather simple and I found it out quickly. Anyway, in some cases this might be the problem, so I'm adding it here. I set the trigger in a if clause, condition Input.GetButton ("Jump"). This resulted in setting the trigger as long as the button is pressed, usually atleast a few frames. Due to the way trigger work, triggers only set themselves off when they are used (transitioning to jump). That means, if the trigger gets called atleast two and up to animationFrameCount-1 times in a row, your animation will play twice. The solution in my case was checking for Input.GetButton*Down* ins$$anonymous$$d:)
It worked for me :)
click on the transition, in the middle of the inspector, you should see a graph thing.
make sure the arrow and the eye are at the same place.
this will fix that very short animations run multiple times when you use triggers.
hope it helps.
what do you mean by "arrow" and "eye" ? I need to fix this problem.
@LeandroExHu$$anonymous$$eD hopes this helps
Here is the run animation running 2 times. 1 time of its full length, and one time with the starting bit, where it transitions over to the death animation.
Right method: Here is the exit Time set to a little under 1 and transition duration set to 0 that means that the run animation only will run 1 time of its full length and then go to the next animation.