Character Controller Pro (1.4.x)
  • Introduction
  • The package
    • Content
    • Versioning scheme
    • Importing the package
    • Using the package
    • Known issues
  • Fundamentals
    • Core
      • Character
      • Character body
      • Character actor
        • States
        • Stable movement features
        • Velocity
    • Implementation
      • Character state controller
      • Character state
      • Character brain
  • How to...
    • Core
      • Create a basic character
      • Add behavior logic to your character
      • Move the character
      • Rotate the character
      • Leave grounded state (e.g. jump)
      • Change the size of the character
      • Disable collisions (ghost)
      • Use the character information (with examples)
      • Use root motion
      • Detect a character using a "detector"
      • Add a static one way platform
      • Add a dynamic one way platform
    • Implementation
      • Organize the character hierarchy
      • States
        • Add and configure the state machine
        • Create a state
        • Transition from one state to another
        • Handle animation
        • Modify an IK (inverse kinematics) element
      • Actions
        • Define your own actions
        • Use the character actions
        • Use a custom Input Handler
        • Use the new input system
        • Create your own AI movement logic
Powered by GitBook
On this page
  • One state
  • Multiple states
  1. How to...
  2. Implementation
  3. States

Transition from one state to another

One state

Let's say you want to go from StateA to StateB if someCondition is valid. For this you need to implement the CheckExitTransition in StateA (since you want to leave this state):

// StateA.cs --------------------------        
public override bool CheckExitTransition()
{
     if( someCondition )
     {
        // Add StateB to the queue
        CharacterStateController.EnqueueTransition<StateB>(); 
     }     
}

If someCondition is true, then StateB will have to handle the transition. To control the result you'll need to implement the CheckEnterTransition in StateB. By default the CheckEnterTransition will accept the transition (returning true).

Let's say StateB can be entered only from StateA:

// StateB.cs --------------------------        
public override bool CheckEnterTransition( CharacterState fromState )
{
     // True if fromState is StateA. False otherwise
     if( fromState == CharacterStateController.GetState<StateA>() )
          return true;
     
     return false; 
}

Multiple states

Let's say you have two or more states that can be triggered by the same initial condition (someCondition from the previous example). Both uses the same condition, but the target state has some extra conditions as well (CheckEnterTransition). If you need to evaluate multiple states you can enqueue them, one after another.

// StateA.cs --------------------------        
public override bool CheckExitTransition()
{
     if( someCondition )
     {        
        CharacterStateController.EnqueueTransition<StateB>(); 
        CharacterStateController.EnqueueTransition<StateC>();
     }
     
}

PreviousCreate a stateNextHandle animation

Last updated 4 years ago