I am trying to create a custom interaction according to the manual below
https://docs.unity3d.com/Packages/com.unity.inputsystem@1.8/api/UnityEngine.InputSystem.IInputInteraction.html
the custom interaction runs well at first,but suddenly cause error “No IInputInteraction with name ‘XXX’ has been registered” 。
So confused!!!
I can’t understand why it sometimes runs well and suddenly broken ! !
using UnityEditor;
using UnityEngine;
using UnityEngine.InputSystem;
#if UNITY_EDITOR
[InitializeOnLoad]
#endif
public class RepeatInteraction : IInputInteraction
{
public float repeatDelay = 0.5f;
public float repeatRate = 0.1f;
static RepeatInteraction() => InputSystem.RegisterInteraction<RepeatInteraction>();
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
private static void Initialize()
{
InputSystem.RegisterInteraction<RepeatInteraction>();
// Will execute the static constructor as a side effect.
}
public void Process(ref InputInteractionContext context)
{
Debug.Log("Process");
var defaultActuation = InputSystem.settings.defaultButtonPressPoint;
switch (context.phase)
{
case InputActionPhase.Waiting:
if (context.ControlIsActuated(defaultActuation))
{
context.PerformedAndStayStarted();
context.SetTimeout(repeatDelay);
}
break;
case InputActionPhase.Started:
case InputActionPhase.Performed:
if (!context.ControlIsActuated(defaultActuation))
{
context.Canceled();
}
else if (context.timerHasExpired)
{
context.PerformedAndStayStarted();
context.SetTimeout(repeatRate);
}
break;
}
switch (context.phase)
{
case InputActionPhase.Waiting: break;
case InputActionPhase.Started: break;
case InputActionPhase.Performed: break;
}
}
public void Reset() { }
}
Example IInputInteraction
[Error] [14:04:50.251] (6) No IInputInteraction with name ‘Repeat’ (mentioned in ‘Repeat’) has been registered