UnityRef is currently in early development. Some features may be incomplete and/or not functioning.

UNITYREF

Your Pit Stop For Solving ANYTHING in Unity

architecture

[Input System] IInputInteraction: The String Dependency Blocking Dynamic UI

Under Audit

input systemgame designuser experienceproject architecture

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.

Issue

 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.

Experimental Fixes
  • Dynamically construct the InputInteractions string using programmatic logic to reflect desired interaction parameters.
  • Implement a custom serialization/deserialization layer to convert your IInputInteraction object representations into the required string format.
  • Utilize a scripting solution to parse and reconstruct interaction strings, potentially employing string interpolation or StringBuilder for complex cases.

Editor's Note:

The above fixes have not been verified by our audit team yet. They are provided exclusively for your own technical research. We recommend creating a backup of your project before proceeding with any attempts. Utilize at your own discretion!

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.