'How to cleanly remove InputAction callbacks?
I have a class which is responsible for setting up and tearing down callbacks to InputAction events (from Unity's Input System package). The relevant code looks like this:
private void SetupCallbacks(InputActionMap map)
{
InputAction action = map.FindAction("Action", true);
action.performed += ActionPerformed;
action.canceled += ActionCanceled;
}
private void TeardownCallbacks(InputActionMap map)
{
InputAction action = map.FindAction("Action", true);
action.performed -= ActionPerformed;
action.canceled -= ActionCanceled;
}
Clearly, there is a lot of duplication here and the code very nearly does the same thing. This looks like a breeding ground for bugs, especially as the number of actions increases. I'm hoping someone on here knows a cleaner solution. Please share your thoughts!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
