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
  1. How to...
  2. Implementation
  3. Actions

Use a custom Input Handler

The brain offers three human input modes:

  • Unity's Input Manager (old)

  • UI

  • Custom

The custom mode, as the name implies, allows you to use a custom input handler. For this, you will need to:

  1. Create a custom class that derives from the InputHandler abstract class.

  2. Implement its abstract methods using the input system API.

  3. Add the component created (1.) somewhere in the scene.

  4. Go to CharacterBrain and change the Human input type to "Custom".

  5. Drag & drop the input handler component (3.) into the input handler field (CharacterBrain).

Creating the class

Plain and simple C#.

public class CustomInputHandler : InputHandler
{
		public override bool GetBool(string actionName)
		{
				return SomeInputSystem.GetButton(actionName);
		}
		
		public override float GetFloat(string actionName)
		{
				return SomeInputSystem.GetAxis(actionName);	
		}

		public override Vector2 GetVector2(string actionName)
		{
				return SomeInputSystem.GetVector2(actionName);	
		}
}

For example, this is the default UnityInputHandler (Unity's Input Manager) that comes with the asset.

public class UnityInputHandler : InputHandler
{
		public override bool GetBool(string actionName)
		{
				return Input.GetButton(actionName);
		}
		
		public override float GetFloat(string actionName)
		{
				return Input.GetAxis(actionName);		
		}
		
		public override Vector2 GetVector2(string actionName)
		{
				// Not officially supported by Unity	
  				return new Vector2( 
  						Input.GetAxis( actionName + " X" ) ,
  						Input.GetAxis( actionName + " Y" ) 
  				);	
		}
}

PreviousUse the character actionsNextUse the new input system

Last updated 1 year ago