# Use the new input system

## Input handler

As mentioned in previous sections, an input handler must be created specifically for Unity's new input system. The following code shows one way to do it.

```csharp
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Utilities;
using Lightbug.CharacterControllerPro.Implementation;


public class InputSystemHandler : InputHandler
{
    [SerializeField]
    InputActionAsset inputActionsAsset = null;

    [SerializeField]
    bool filterByActionMap = false;

    [SerializeField]
    string gameplayActionMap = "Gameplay";

    [SerializeField]
    bool filterByControlScheme = false;

    [SerializeField]
    string controlSchemeName = "Keyboard Mouse";


    Dictionary< string , InputAction> inputActionsDictionary = new Dictionary<string, InputAction>();

    protected virtual void Awake()
    {
        
        if( inputActionsAsset == null )
        {
            Debug.Log("No input actions asset found!");
            return;
        }

        inputActionsAsset.Enable();

        if( filterByControlScheme )
        {
            string bindingGroup = inputActionsAsset.controlSchemes.First( x => x.name == controlSchemeName ).bindingGroup;
            inputActionsAsset.bindingMask = InputBinding.MaskByGroup( bindingGroup );
        }

        ReadOnlyArray<InputAction> rawInputActions = new ReadOnlyArray<InputAction>();
        
        if( filterByActionMap )
        {
            rawInputActions = inputActionsAsset.FindActionMap( gameplayActionMap ).actions;

            for( int i = 0 ; i < rawInputActions.Count ; i++ )
                inputActionsDictionary.Add( rawInputActions[i].name , rawInputActions[i] );
        
        }
        else
        {
            for( int i = 0 ; i < inputActionsAsset.actionMaps.Count ; i++ )
            {
                InputActionMap actionMap = inputActionsAsset.actionMaps[i];

                for( int j = 0 ; j < actionMap.actions.Count ; j++ )
                {
                    InputAction action = actionMap.actions[j];
                    inputActionsDictionary.Add( action.name , action );
                }

            }

            
        }
        

        for( int i = 0 ; i < rawInputActions.Count ; i++ )
        {
            inputActionsDictionary.Add( rawInputActions[i].name , rawInputActions[i] );
        }

    }

    public override bool GetBool( string actionName )
    { 
        InputAction inputAction;

        if( !inputActionsDictionary.TryGetValue( actionName , out inputAction ) )
            return false;

        return inputActionsDictionary[actionName].ReadValue<float>() >= InputSystem.settings.defaultButtonPressPoint;
    }

    public override float GetFloat( string actionName )
    {       
        InputAction inputAction;

        if( !inputActionsDictionary.TryGetValue( actionName , out inputAction ) )
            return 0f;
        
        return inputAction.ReadValue<float>();
    }

    

    public override Vector2 GetVector2( string actionName )
    {
        InputAction inputAction;

        if( !inputActionsDictionary.TryGetValue( actionName , out inputAction ) )
            return Vector2.zero;
        
        return inputActionsDictionary[actionName].ReadValue<Vector2>(); 
    }

}


```

{% hint style="warning" %}
It is **recommended** to put the class file **outside CCP's main folder** in order to prevent missing reference errors. This happens because CCP's [asmdef file](/ccp/package/using-the-package.md#assembly-definition-file) does not include references to any external packages such as Unity's input system, Cinemachine, etc.
{% endhint %}

## InputAction assets

Keep in mind that the *InputActionAsset* action names must match with the character actions names, otherwise actions will not be registered by the input handler. For example:

![](/files/-MUOPx8t45rbUNxCenX0)

## Downloads

{% file src="/files/AzXmJRqP6QGlgmoK5Lfy" %}

This file includes:&#x20;

* *InputSystemHandler.cs (code)*
* *CharacterActions.inputactions*
* *CameraActions.inputactions*


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://lightbug14.gitbook.io/ccp/how-to.../implementation/actions/use-the-new-input-system.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
