[Input System] IInputInteraction: The String Dependency Blocking Dynamic UI
Under Audit
Unity 2021.3.x - Unity 6.0.x
Published Wed, Mar 18
The InputActions API currently requires defining IInputInteraction instances through string parsing, preventing direct object instantiation and manipulation, which complicates dynamic UI elements.
The InputActions API currently mandates the use of strings for adding InputInteractions. For example, action.AddBinding("<Gamepad>/leftStick").WithInteractions("Hold(duration=0.8)"); implicitly converts the provided string into a HoldInteraction object and applies it. There is no publicly exposed API variant that directly accepts an IHoldInteraction object, such as action.AddBinding("<Gamepad>/leftStick").WithInteractions(new HoldInteraction(duration: 0.8f));. This design choice, despite the engine performing string-to-object conversion internally, introduces complexity when attempting to translate InputActions into dynamic on-screen UI prompts, as it requires developers to manage string formatting rather than object instances.
- Dynamically construct the InputInteractions string using programmatic logic to reflect desired interaction parameters.
- Implement a custom serialization/deserialization layer to convert your
IInputInteractionobject representations into the required string format. - Utilize a scripting solution to parse and reconstruct interaction strings, potentially employing string interpolation or
StringBuilderfor complex cases.
Editor's Note:
Related Posts Haven't quite found a solution to your problem? We think these posts might help you.
Content inspired by a Unity discussion post.