docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Write custom processors

    Create your own processors to change the values that bindings, actions, and controls produce.

    You can use custom processors with bindings, actions, and controls in the same way as the built-in processors, both in the Input Actions Editor window and in code.

    To create a custom processor:

    1. Add a processor class.
    2. Register the processor with the Input System.
    3. Optional: Customize the Editor UI for the processor.

    Add a processor class

    Create a class that derives from InputProcessor<TValue>, and override the Process method:

    /// <summary>
    /// Example custom processor that adds a fixed offset to incoming float values.
    /// </summary>
    public class MyValueShiftProcessor : InputProcessor<float>
    {
        /// <summary>
        /// Number to add to incoming values.
        /// </summary>
        [Tooltip("Number to add to incoming values.")]
        public float valueShift = 0;
    
        /// <summary>
        /// Adds <see cref="valueShift"/> to <paramref name="value"/>.
        /// </summary>
        /// <param name="value">Value to process.</param>
        /// <param name="control">Control from which the value originates.</param>
        /// <returns>The shifted value.</returns>
        public override float Process(float value, InputControl control)
        {
            return value + valueShift;
        }
    }
    
    Important

    Processors must be stateless, because they aren't part of the input state that the Input System keeps. Don't store values in a processor between calls to Process.

    The public fields of a processor are its parameters, which you can set in the Input Actions Editor window or in code. Parameters must be primitive types, such as float, int, or bool, or enums. A parameter of an unsupported type, such as Vector3, causes the error Don't know how to convert PrimitiveValue to 'Object'. To use a vector as a parameter, add a separate parameter for each component. For example, the built-in ScaleVector3 processor has the parameters x, y, and z.

    Register the processor with the Input System

    Call InputSystem.RegisterProcessor when your code loads, both in the Editor and in builds. The following example registers the processor from a separate static class:

    • [InitializeOnLoad] registers it in the Editor.
    • [RuntimeInitializeOnLoadMethod] registers it in builds before the first scene loads.
    #if UNITY_EDITOR
    [InitializeOnLoad]
    #endif
    static class MyValueShiftProcessorRegistration
    {
        #if UNITY_EDITOR
        static MyValueShiftProcessorRegistration()
        {
            Register();
        }
    
        #endif
    
        [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
        static void Register()
        {
            InputSystem.RegisterProcessor<MyValueShiftProcessor>();
        }
    }
    
    Important

    Register processors with [InitializeOnLoad] and [RuntimeInitializeOnLoadMethod], not with the code lifecycle attributes that Unity 6.5 and later provide in the Unity.Scripting.LifecycleManagement namespace, such as [OnCodeLoaded]. The Input System initializes with [InitializeOnLoad] and [RuntimeInitializeOnLoadMethod], so these attributes ensure that the Input System is ready when you call RegisterProcessor. For more information about the lifecycle attributes, refer to Accessing the code lifecycle (Unity Manual).

    The processor is now available in the Input Actions Editor. To add it in code, use its registered name. The Input System registers a processor under its class name without the Processor suffix, so MyValueShiftProcessor becomes MyValueShift. Names aren't case-sensitive. For example:

    var action = new InputAction(processors: "myvalueshift(valueShift=2.3)");
    

    Customize the Editor UI

    To customize the UI for editing your processor, create a class that derives from InputParameterEditor<TObject>. The Input System finds the class automatically, so you don't need to register it.

    Implement both of the following methods, because different parts of the Editor use different UI frameworks:

    • OnDrawVisualElements: draws the UI in the Input Actions Editor window, which uses UI Toolkit. Add your controls to root, and call onChangedCallback whenever a value changes so that the editor saves it.
    • OnGUI: draws the UI where the Editor uses IMGUI, such as InputAction fields in the Inspector window. Return early unless InputSettings.useIMGUIEditorForAssets is true. Otherwise, the Input Actions Editor window displays your controls twice.
    #if UNITY_EDITOR
    /// <summary>
    /// Example custom Editor UI for <see cref="MyValueShiftProcessor"/>.
    /// </summary>
    public class MyValueShiftProcessorEditor : InputParameterEditor<MyValueShiftProcessor>
    {
        private GUIContent m_SliderLabel = new GUIContent("Shift By");
    
        /// <summary>
        /// Draws the UI in the Input Actions Editor window, which uses UI Toolkit.
        /// </summary>
        public override void OnDrawVisualElements(VisualElement root, Action onChangedCallback)
        {
            var slider = new Slider(m_SliderLabel.text, 0, 10) { value = target.valueShift };
            slider.RegisterValueChangedCallback(evt =>
            {
                target.valueShift = evt.newValue;
                // Notify the editor so that it saves the new value.
                onChangedCallback();
            });
            root.Add(slider);
        }
    
        /// <summary>
        /// Draws the UI where the Editor uses IMGUI, such as InputAction fields in the Inspector window.
        /// </summary>
        public override void OnGUI()
        {
            // The Input Actions Editor window uses OnDrawVisualElements instead.
            // Without this check, it displays the controls twice.
            if (!InputSystem.settings.useIMGUIEditorForAssets)
                return;
    
            target.valueShift = EditorGUILayout.Slider(m_SliderLabel,
                target.valueShift, 0, 10);
        }
    }
    #endif
    

    Additional resources

    • Introduction to processors
    • Built-in processors
    • Add processors to bindings and actions
    • Add processors to controls
    In This Article
    Back to top
    Copyright © 2026 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)