Search Unity

  1. We are migrating the Unity Forums to Unity Discussions by the end of July. Read our announcement for more information and let us know if you have any questions.
    Dismiss Notice
  2. Dismiss Notice

Bug custom interactions can not use in unity6 [input system version 1.8.2]

Discussion in 'Input System' started by FrankTMY, May 18, 2024.

  1. FrankTMY

    FrankTMY

    Joined:
    Nov 13, 2021
    Posts:
    6
    Last edited: May 18, 2024
  2. FrankTMY

    FrankTMY

    Joined:
    Nov 13, 2021
    Posts:
    6
    Code (CSharp):
    1. using UnityEditor;
    2. using UnityEngine;
    3. using UnityEngine.InputSystem;
    4.  
    5. #if UNITY_EDITOR
    6. [InitializeOnLoad]
    7. #endif
    8. public class RepeatInteraction : IInputInteraction
    9. {
    10.     public float repeatDelay = 0.5f;
    11.     public float repeatRate = 0.1f;
    12.  
    13.     static RepeatInteraction() => InputSystem.RegisterInteraction<RepeatInteraction>();
    14.  
    15.     [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
    16.     private static void Initialize()
    17.     {
    18.           InputSystem.RegisterInteraction<RepeatInteraction>();
    19.         // Will execute the static constructor as a side effect.
    20.     }
    21.  
    22.     public void Process(ref InputInteractionContext context)
    23.     {
    24.         Debug.Log("Process");
    25.         var defaultActuation = InputSystem.settings.defaultButtonPressPoint;
    26.  
    27.         switch (context.phase)
    28.         {
    29.             case InputActionPhase.Waiting:
    30.                 if (context.ControlIsActuated(defaultActuation))
    31.                 {
    32.                     context.PerformedAndStayStarted();
    33.                     context.SetTimeout(repeatDelay);
    34.                 }
    35.                 break;
    36.  
    37.             case InputActionPhase.Started:
    38.             case InputActionPhase.Performed:
    39.                 if (!context.ControlIsActuated(defaultActuation))
    40.                 {
    41.                     context.Canceled();
    42.                 }
    43.                 else if (context.timerHasExpired)
    44.                 {
    45.                     context.PerformedAndStayStarted();
    46.                     context.SetTimeout(repeatRate);
    47.                 }
    48.                 break;
    49.         }
    50.  
    51.         switch (context.phase)
    52.         {
    53.             case InputActionPhase.Waiting: break;
    54.             case InputActionPhase.Started: break;
    55.             case InputActionPhase.Performed: break;
    56.         }
    57.     }
    58.  
    59.     public void Reset() { }
    60. }
    Example IInputInteraction
    [Error] [14:04:50.251] (6) No IInputInteraction with name 'Repeat' (mentioned in 'Repeat') has been registered