- Home /
Change animation parameter through entering a state?
I know you can set an event in an animation and it will send a message to a script where you can then change parameters, but is there a way to have an animation parameter change simply by entering or exiting an animation state or going through an animation transition. Really any way to do it outside of a script?
Answer by FM-Productions · May 05, 2017 at 01:48 PM
In the animator, go to your desired animation state, click on "Add behaviour" and create a new one. Then you can communicate with the animator in certain event functions. An example from my code:
public class AnimatorResetBoolAtEnd : StateMachineBehaviour {
[SerializeField]
private string booleanVariableName;
// OnStateExit is called when a transition ends and the state
//machine finishes evaluating this state
override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
animator.SetBool(booleanVariableName, false);
}
}
If you still haven't found it, on this page is a good picture of it:
https://docs.unity3d.com/$$anonymous$$anual/State$$anonymous$$achineBehaviours.html
Select an animation state in your animator, then in the Inspector view you should see a button "Add Behavior"
Answer by serseralci · May 05, 2017 at 01:18 PM
You should be using StateMachineBehaviour. You may reset the value of your animation parameter to its default value to prevent state changes.
Answer by MarsBellona · May 22, 2017 at 05:06 AM
I'm running the " RollerBall " scene from the standard assets pack , running over various NPC's I've added . I want them to die when a collision occurs . I can't get the " Any State " in the Animator component to work .
Your answer
![](https://koobas.hobune.stream/wayback/20220612093800im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Changing Animator Animations from script 0 Answers
How can I make my model invisible before trigging the animation ??? 0 Answers
Is there a way to select animation events on the dopesheet beside clicking on them? 0 Answers
Dope sheet animation-fire animation problem 0 Answers
Animator question: need to play animation ONLY if current animation is at a particular frame 1 Answer