Code to fix TMP_InputField to support new InputSystem

Hello @Stephan_B
As your TMP_InputSystem throw exception in new InputSystem i made a minor changes in your code to add support to both events systems:

  • in line 1438 (LateUpdate) you must replace
if(Input.GetKeyDown(KeyCode.Mouse0))

to

if (m_ProcessingEvent != null && m_ProcessingEvent.rawType == EventType.MouseDown && m_ProcessingEvent.button == 0)
  • and in line 1712 (OnPointerDown)
bool shift = Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift);

to

Event.PopEvent(m_ProcessingEvent);
bool shift = m_ProcessingEvent != null && (m_ProcessingEvent.modifiers & EventModifiers.Shift) != 0;
  • Check null in line 3996 (DeactivateInputField) to prevent exception when unity stop playing… this appears to be a bug in TextMeshPro Preview 3
if(inputSystem != null)
    inputSystem.imeCompositionMode = IMECompositionMode.Auto;

The new input system handles the IMEEvents too so we must use than instead of Input.GetKeyDown, etc

Best Regards

Rafael

1 Like

@Stephan_B can we get an update on this? This is still not fixed in TMP 2.1.0 preview 4.

You can use #if ENABLE_INPUT_SYSTEM and #if ENABLE_LEGACY_INPUT_MANAGER to have separate code with the legacy and new input systems. See the docs.

@Rafael_CS Thank you for the time you took to investigate the above and providing those changes.

@cxode Thank you also for the feedback.

I went ahead and made the above changes which will be included in Preview 5 of the TMP package. I only had time to do very quick testing so please anyone reading this be sure to thoroughly test Preview 5 for Unity 2019.2 or higher and report any additional issues.

3 Likes

I installed the latest 2.1.1 and still have the same error message. Did this get moved to 3.0.0 instead of 2.1.X ? I don’t see it mentioned in the changelog for 2.1.X

Changes are in 2.1.x. Make sure you are using 2.1.1 with Unity 2019.4.x.

Thanks that did the trick. Appreciate the hard work you guys are doing bringing us these awesome packages!

Just a heads up, I started a new project yesterday using Unity ver 2019.4.10f1 & TMP 2.1.1 and was still receiving errors. I had to select the EventSystem object and click a button in the inspector window to convert to InputSystemUIInputModule.

1 Like

This message and conversion is coming from the New Input System and is how it handles the conversion of existing scenes and objects affected by the switch to the new system.

I would suggest posting in the New Input System forum section to see if they have any additional information / plan on handling this conversion in the future.

@Stephan_B Hi, In InputSystem,the keyboard not trigger InputField from InputSystem.QueueStateEvent.How to Solve it?
Thank you very much

1 Like

This error still happens. We have to delve into the guts of Unity components themselves just to use the “New Input System” on a text field? “New Input System” should never have been a “recommended” way to go if it’s causing errors in Unity itself.

This is still a problem. Did you ever find a solution?

Specifically, we are using the new input system’s ability to generate input events for our unit/integration tests and it works wonderfully! (It’s almost a miracle). However, TMPRO input fields do not seem to receive any keyboard input when we use InputSystem.QueueStateEvent, even though other parts of the game do.

See TMP_InputField.OnUpdateSelected:

TMP_InputField does not use the “new” InputSystem in any way: It just bypasses it by using the legacy UnityEngine.Event (the one being cool beans in 2007). It just polls the legacy Events every frame when it is selected and decides if it should react to it (e.g. when it is a key press).

It also does not really use the “old” EventSystem, it just uses it to get a nice update callback als long as the TMP_InputField is currently selected (hence the method name OnUpdateSelected).

This is why you cannot use the InputSystem’s ways to push synthetic events to the TMP_InputField.

And this is also why there is no sane way of making keyboard input via InputSystem (e.g. for your player controller) play nice with TMP_InputField…

1 Like