- Home /
Animator bug when activating a transition condition using SetBool
Hi everyone
I got a really weird behaviour with one of my scripts that drives an animator component. My game setup is as follows :
I got a ship game object with two moving parts : a mobile armor plate, and a laser weapon.
The armor must be opened before the laser weapon can be deployed.
It is possible to open the armor without deploying the laser weapon.
A script allows to operate this ship system by calling functions called OpenArmor, CloseArmor, RaiseLaser, and LowerLaser. Both operations can be interrupted and reversed before there are complete (e.g., OpenArmor is called, the opening animation starts playing, then when the armor is half open CloseArmor is called, and the animation plays backwards until the armor is closed again).
To achieve this, I have an Animator with two states (MoveArmor and MoveLaser) and two transitions to navigate between them (see image below). The transitions are controlled using a boolean parameter called ArmorMoving : The animator goes from state MoveArmor to MoveLaser when ArmorMoving is false, and vice versa when it is true. The animation playback speed is controlled by the script and is either 1 or -1 (depending on whever the scripts decides to play the animation forward or backwards).
The problem arises when the laser weapon is deployed and I call CloseArmor() : what I expect is that the deploying animation is played backwards in the MoveLaser state, then the state becomes MoveArmor and the armor animations is also played backwards. The script is in charge of setting the animation speed to -1 (backwards playback) and switching the boolean parameter ArmorMoving from 'false' to 'true' when appropriate, so that the animator controller can change state.
What actually happens is different : the weapon animation is played backwards (as expected). When this animation is fully rewinded, the ArmorMoving boolean parameter is set to true by a call to SetBool (also as expected). The Animator component does not switch back to the MoveArmor state however ! What I see when I display it while the game is running is a total nonsense ; as you can see on the screenshot below (which was taken at the moment when the animator should have switched state - I added the red text for clarity) Unity tells me that :
My boolean parameter was correctly set to true (see the checkbox at bottom)
Both states are simultaneously active (both have an animation progress bar) !?
They both have a negative progress, alost the progress bar normally displays data between 0 and 100% (the small blue bar on the left goes beyond the left bar limit) !?
As indicated by the vertical blue line which is progressing towards the bottom of the screen, the state is changing to ... a non-existent state !?
After a careful and prudent examination of this original problem, I came up with the following, considered analysis : What the hell :D !? - Did you already met that kind of problem ? Did I do something wrong, or is it a Unity bug ? I attach my script file to this message.link text
Your answer
Follow this Question
Related Questions
Animator conditions, no bool state selector. 1 Answer
Not able to use a Vector as a condition in Mecanim? 2 Answers
(Unity/Mixamo) Animation won't play all frames 2 Answers
Bug animation transitions, or am I the bug? 0 Answers
is it possible to read states / transitions from mecanim in runtime ? 2 Answers