Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

TextMesh Pro Code to fix TMP_InputField to support new InputSystem

Discussion in 'UGUI & TextMesh Pro' started by Rafael_CS, Jan 29, 2020.

  1. Rafael_CS

    Rafael_CS

    Joined:
    Sep 16, 2013
    Posts:
    160
    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:

    1. in line 1438 (LateUpdate) you must replace

      Code (CSharp):
      1. if(Input.GetKeyDown(KeyCode.Mouse0))
      to

      Code (CSharp):
      1. if (m_ProcessingEvent != null && m_ProcessingEvent.rawType == EventType.MouseDown && m_ProcessingEvent.button == 0)
    2. and in line 1712 (OnPointerDown)

      Code (CSharp):
      1. bool shift = Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift);
      to

      Code (CSharp):
      1. Event.PopEvent(m_ProcessingEvent);
      2. bool shift = m_ProcessingEvent != null && (m_ProcessingEvent.modifiers & EventModifiers.Shift) != 0;
    3. Check null in line 3996 (DeactivateInputField) to prevent exception when unity stop playing... this appears to be a bug in TextMeshPro Preview 3
      Code (CSharp):
      1. if(inputSystem != null)
      2.     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
     
    Last edited: Jan 29, 2020
    cxode likes this.
  2. cxode

    cxode

    Joined:
    Jun 7, 2017
    Posts:
    268
    @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.
     
  3. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,588
    @Rafael_CS Thank you for the time you took to investigate the above and providing those changes.

    @JimmyCushnie 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.
     
    RaphaelBuquet, NanushTol and cxode like this.
  4. dotRollen

    dotRollen

    Joined:
    Mar 28, 2019
    Posts:
    2
    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
     
  5. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,588
    Changes are in 2.1.x. Make sure you are using 2.1.1 with Unity 2019.4.x.
     
  6. dotRollen

    dotRollen

    Joined:
    Mar 28, 2019
    Posts:
    2
    Thanks that did the trick. Appreciate the hard work you guys are doing bringing us these awesome packages!
     
  7. Lissa_xyz

    Lissa_xyz

    Joined:
    Oct 30, 2015
    Posts:
    1
    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.
     
    gareth_untether likes this.
  8. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,588
    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.
     
  9. wanfei

    wanfei

    Joined:
    Dec 22, 2018
    Posts:
    19
    @Stephan_B Hi, In InputSystem,the keyboard not trigger InputField from InputSystem.QueueStateEvent.How to Solve it?
    Thank you very much
     
    Claytonious likes this.
  10. MaxLohMusic

    MaxLohMusic

    Joined:
    Jan 17, 2022
    Posts:
    45
    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.
     
  11. Claytonious

    Claytonious

    Joined:
    Feb 16, 2009
    Posts:
    881
    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.
     
  12. cp-

    cp-

    Joined:
    Mar 29, 2018
    Posts:
    77
    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...