Search Unity

Possible bug with Custom Processor?

Discussion in 'Input System' started by TehNinjor, Nov 17, 2019.

  1. TehNinjor

    TehNinjor

    Joined:
    Jan 18, 2015
    Posts:
    3
    Im using 2019.2.12f1

    Sorry if I'm missing something dumb, I'm new to the Input System and only just getting a grip on it.

    The InputAction is defined within a MonoBehaviour, and binding is set in the inspector. I will see if this happens in an ActionMap asset as well.

    I'm trying to write a simple processor to smoothDamp() a Vector2. I copy-pasta'd Unity's example of a custom processor and put my bit of code in. So it's registering correctly etc (or at least how they say so as of yet).

    My code worked fine (smoothing correctly, although a tad glitchy when the stick centers), and when I removed the processor from the Binding (via the inspector, editing the Mono), it disappeared from the processors list when I went to re-select it.

    I commented out all my code, and simply returned the input value on Process() (in case it was my doing), but it didn't pop back up.

    There are no errors in the console.

    It wasn't untill I restarted my Editor it reappeared.

    I can re-create this pretty successfully; if I remove it from the binding, it disappears. All the Unity ones seem okay.

    Hopefully this formats right, but here's the class. My code is left commented out just to rule it out, it disappearing exactly as you see it now. It is copy+paste of the example aside from my commented out bits.

    Code (CSharp):
    1. using UnityEditor;
    2. using UnityEngine;
    3. using UnityEngine.InputSystem;
    4.  
    5. #if UNITY_EDITOR
    6. [InitializeOnLoad]
    7. #endif
    8. public class SmoothVector2 : InputProcessor<Vector2>
    9. {
    10.     //public float smoothCoef = 0.1f;
    11.     //private Vector2 _vector = new Vector2(0, 0), _vectorRef = new Vector2(0, 0);
    12.  
    13. #if UNITY_EDITOR
    14.     static SmoothVector2()
    15.     {
    16.         Initialize();
    17.     }
    18. #endif
    19.  
    20.     [RuntimeInitializeOnLoadMethod]
    21.     static void Initialize()
    22.     {
    23.         InputSystem.RegisterProcessor<SmoothVector2>();
    24.     }
    25.  
    26.     public override Vector2 Process(Vector2 value, InputControl control)
    27.     {
    28.        //_vector = new Vector2(Mathf.SmoothDamp(_vector.x, value.x, ref _vectorRef.x, smoothCoef),
    29.        //     Mathf.SmoothDamp(_vector.y, value.y, ref _vectorRef.y, smoothCoef));
    30.        // return _vector;
    31.  
    32.         return value;
    33.     }
    34.  
    35.     //...
    36. }
     
  2. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    That indeed sounds like a bug. Not sure why it would disappear. Shouldn't. Could you file a bug with your repro using the Unity bug reporter? Would like to take a closer look.
     
  3. TehNinjor

    TehNinjor

    Joined:
    Jan 18, 2015
    Posts:
    3
    Sent.

    Not sure what files you'd need exactly, so I just let it send my entire project folder, it's not too big or complicated. I've pointed out the relevant file names in my report.

    If needed, I could record a video of me recreating it, but I think my guide should cover it pretty well, presuming it happens for you too.

    Thanks!
     
    Rene-Damm likes this.
  4. TRS6123

    TRS6123

    Joined:
    May 16, 2015
    Posts:
    246
    I think I'm having the same issue. All custom processors, composites, and interactions disappear from their respective menus after entering playmode. Only ways to get them registered again is to restart the editor or force a domain reload.
     
  5. TehNinjor

    TehNinjor

    Joined:
    Jan 18, 2015
    Posts:
    3
    Yeah that sounds about the same actually, just I thought it was when I removed it form the list. Didn't think to try trying to see if it was still there before removing it.

    I really do appreciate the work-load and time this process takes, but wondering if there's any news about this? If you're having any issues re-creating it I'm happy to do that video and/or help out any way I can etc... :)
     
  6. huulong

    huulong

    Joined:
    Jul 1, 2013
    Posts:
    224
    Same issue here, the custom processor appears and disappears sporadically... I force domain reload by checking Domain Reload and playing the game in the editor, then stopping. But it doesn't always work either, so I cannot have a perfect issue repro nor workaround. Last time I had to modify a random line of code to trigger recompile, then re-enter Play Mode, but I don't know if it's necessary.
     
    skaughtx0r likes this.
  7. hyagogow

    hyagogow

    Joined:
    Apr 25, 2014
    Posts:
    26
    I have a similar problem with my custom Processor (implemented as the official docs shows).
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.InputSystem;
    3.  
    4. #if UNITY_EDITOR
    5.     [UnityEditor.InitializeOnLoad]
    6. #endif
    7. public sealed class DeadzoneProcessor : InputProcessor<Vector2>
    8. {
    9.     [Tooltip("Minimum absolute value allowed for this stick.")]
    10.     public float min = 0.25f;
    11.     [Tooltip("Maximum absolute value allowed for this stick.")]
    12.     public float max = 0.80f;
    13.  
    14. #if UNITY_EDITOR
    15.     static DeadzoneProcessor()
    16.     {
    17.         Initialize();
    18.     }
    19. #endif
    20.  
    21.     [RuntimeInitializeOnLoadMethod]
    22.     private static void Initialize()
    23.     {
    24.         InputSystem.RegisterProcessor<DeadzoneProcessor>();
    25.     }
    26.    
    27.     public override Vector2 Process(Vector2 value, InputControl _)
    28.     {
    29.         var absValue = value.Abs();
    30.  
    31.         if (absValue.x > max) value.x = Mathf.Sign(value.x);
    32.         else if (absValue.x < min) value.x = 0F;
    33.  
    34.         if (absValue.y > max) value.y = Mathf.Sign(value.y);
    35.         else if (absValue.y < min) value.y = 0F;
    36.  
    37.         return value;
    38.     }
    39. }
    My WebGL build displays the following error message for the first time my InputAction is loaded:

    InvalidOperationException: No processor with name 'Deadzone' (mentioned in 'Deadzone(min=0.5)') has been registered.
    But I can confirm that the DeadzoneProcessor is working in the editor and builds.
    I really don't know why this error message keep showing on my builds since it's working fine (I hope).
     
  8. huulong

    huulong

    Joined:
    Jul 1, 2013
    Posts:
    224
    So I got a reply from Unity on my bug report:

    Note that the doc for stable 1.0 has not been updated, and the doc for 1.1 only partially updated (RegisterLayout sample code uses BeforeSceneLoad, but not RegisterProcessor sample code itself).

    I myself could not check that the bug is fixed by this in particular, as I switched project *and* upgraded Unity version in the meantime, and I do not see any errors in a dev build (on Linux Unity 2020.2.4f1 at least). But from now on I'll add (RuntimeInitializeLoadType.BeforeSceneLoad) just in case.
     
    RaphaelBuquet and Pawciu like this.
  9. huulong

    huulong

    Joined:
    Jul 1, 2013
    Posts:
    224
    After reloading some scripts I noticed that my custom Processor didn't appear in the list when adding a Processor in the Input Actions window. I tried RuntimeInitializeLoadType.AfterAssembliesLoaded which seemed to work as I see my processor again now, but since this is the kind of issue that disappears after any change + recompile, it's difficult to say if it will actually fix future issues or if it just got fixed because of the recompile (for instance, if I revert to BeforeSceneLoad, the processor still shows).

    However you have the same issue frequently, you can try different values of RuntimeInitializeLoadType and see.
     
    Xriuk likes this.