- Home /
How can I create a AnimatorStateTransition Condition with a bool set to false
I am creating two animation states that is controlled by a bool condition. I am trying to programatically create everything because I plan to do create variations of this animator often.
// Create controller and hook up transitions.
var controller = AnimatorController.CreateAnimatorControllerAtPath(path);
var openState = GenerateTriggerableTransition(closeName, controller);
var closeState = GenerateTriggerableTransition(openName, controller);
// Add a transition property
controller.AddParameter("Open", AnimatorControllerParameterType.Bool);
// Add an any state transition
var transition = openState.AddTransition(closeState, false);
transition.AddCondition(AnimatorConditionMode.If, 1, "Open"); //this condition is Open = true
transition = closeState.AddTransition(openState, false);
transition.AddCondition(AnimatorConditionMode.If, -1, "Open"); //this condition is Open = true, but should be Open = false
Answer by Roark114 · Aug 19, 2015 at 11:00 PM
transition.AddCondition(AnimatorConditionMode.If, -1, "Open");
Should be:
transition.AddCondition(AnimatorConditionMode.IfNot, 0, "Open");
The value parameter of AddCondition does not affect the bool in the mode! Hope that helps :)
Answer by shaunevans · Aug 30, 2020 at 11:15 AM
This should save an hour of someone else's time:
Use "AnimatorConditionMode.IfNot" instead of "AnimatorConditionMode.If" in order to get the conditions being false:
transition.AddCondition(AnimatorConditionMode.If, 0, "Open"); //this condition is Open = true
transition = closeState.AddTransition(openState, false);
transition.AddCondition(AnimatorConditionMode.IfNot, 0, "Open"); //this condition is Open = false
Your answer
Follow this Question
Related Questions
Mecanim Transition Conditions - Can they be "or"? 1 Answer
Animator dont transition to self or any sub state 2 Answers
How do I make an animation transition condition for a top down shooter? 0 Answers
[C#] [2D] Animation mostly not working 1 Answer
How can I smoothly transition my player camera from manual control into an animation? 1 Answer