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

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 :slight_smile:

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