Search Unity

Custom processor fails to register in builds

Discussion in 'Input System' started by samlletas, Aug 10, 2021.

  1. samlletas

    samlletas

    Joined:
    Jan 2, 2016
    Posts:
    30
    I have created the following custom input processor:
    Code (CSharp):
    1.  
    2. using UnityEngine;
    3. using UnityEngine.InputSystem;
    4. using UnityEditor;
    5.  
    6. namespace Game._Input
    7. {
    8. #if UNITY_EDITOR
    9.     [InitializeOnLoad]
    10. #endif
    11.     public class DigitalStickProcessor : InputProcessor<Vector2>
    12.     {
    13.         public float deadzone = 0.5f;
    14.  
    15.         public override Vector2 Process(Vector2 value, InputControl control)
    16.         {
    17.             // Do stuff
    18.         }
    19.  
    20. #if UNITY_EDITOR
    21.         static DigitalStickProcessor()
    22.         {
    23.             Initialize();
    24.         }
    25. #endif
    26.  
    27.         [RuntimeInitializeOnLoadMethod]
    28.         private static void Initialize()
    29.         {
    30.             InputSystem.RegisterProcessor<DigitalStickProcessor>();
    31.         }
    32.     }
    33. }
    34.  

    The processor registers and I can enable it in the editor:



    Everything works fine in play mode, but when building and running the game (IL2CPP on Windows) the logs show that the processor was not registered, and inputs are not detected:


    InvalidOperationException while resolving binding 'Direction:2DVector(mode=2)' in action map 'Controls (UnityEngine.InputSystem.InputActionAsset):Gameplay'
    ...
    ...
    InvalidOperationException: No processor with name 'DigitalStick' (mentioned in 'DigitalStick') has been registered
    ...


    Does anyone has an idea of what I could be doing wrong?
    Thanks in advance.

    Unity: 2021.1.14
    Input System: 1.0.2
     
    Last edited: Aug 10, 2021
  2. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    Use
    Code (CSharp):
    1.         [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
     
    samlletas likes this.
  3. samlletas

    samlletas

    Joined:
    Jan 2, 2016
    Posts:
    30
    That fixed it, thanks!
     
  4. huseyin19

    huseyin19

    Joined:
    Jun 27, 2021
    Posts:
    5
    i have the same issue and the the answer didn't work in my case any idea why
    here is my code

    Code (CSharp):
    1. #if UNITY_EDITOR
    2. [InitializeOnLoad]
    3. #endif
    4. public class TopdownPointerAim : InputProcessor<Vector2>
    5. {
    6.    #if UNITY_EDITOR
    7.    static TopdownPointerAim()
    8.    {
    9.       Initialize();
    10.    }
    11.    #endif
    12.  
    13.    [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
    14.    static void Initialize()
    15.    {
    16.       InputSystem.RegisterProcessor<TopdownPointerAim>();
    17.    }
    18.  
    19.    public override Vector2 Process(Vector2 value, InputControl control)
    20.    {
    21.       var result = (value - InputManager.screenCenterOffset).normalized;
    22.       return result;
    23.    }
    24. }
    and i attached a ss of the log message i am getting on my build
     

    Attached Files:

  5. thekevinbutler

    thekevinbutler

    Joined:
    Feb 1, 2017
    Posts:
    2
    I just experienced this too! I did the RuntimeInitializeOnLoadMethod steps and it still wasn't registering in my builds.

    Where I went wrong was that I nested my custom Processor scripts inside of an Editor folder! I moved them out of my Assets/Editor and into a new folder called Assets/Input (can be whatever you want as long as there is NO folder named Editor in the path). Now that its outside the Editor assembly, it can be packaged in the build correctly
     
    AqueuseAkaLLO likes this.