Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

TextMesh Pro [TMP 1.4] - Input field ResetOnDeactivate issue

Discussion in 'UGUI & TextMesh Pro' started by Micito, Apr 2, 2019.

  1. Micito

    Micito

    Joined:
    Dec 5, 2014
    Posts:
    16
    Hey everyone,

    We found out that after updating to TMP 1.4 ResetOnDeActivation in TMP InputField is not working correctly anymore.
    In 1.3 we were able to set it to false, and the cursor and selection on input field will remain visible while input field wasn’t selected, and enabling it would clean it up immediately if it’s deactivated.
    In 1.4 once you enable it, the selection and cursor are not hiden/removed. And we have tried multiple ways of refreshing it (disabling then enabling input field, ForceLabelUpdate, ..) and they didn’t work.

    Also, in 1.4 there can be only one input field with selection active. As you can see in 1.3 both input fields have visible selections at the same time, while in 1.4 only one input field can have selection visible at a time.

    TMP 1.3
    TMP-1-3.png

    Elements:
    -InputField 1 (Green) - ResetOnDeActivate is disabled
    -InputField 2 (Yellow) - ResetOnDeActivate is disabled
    -Button (Orange) - Button to click to take focus away from input field (can be done by clicking no elements as well (ie. clicking on blue background)

    Steps:
    1. Click input field 1 (Green) and select part of text
    2. Click button to deactivate input field
    3. The input field remains selected (this is acutally fine, this is how it’s supposed to work)
    4. Enable ResetOnDeActivate (selection and caret are hidden/removed instantly)
    TMP 1.4
    TMP-1-4.png

    Elements:
    -InputField 1 (Green) - ResetOnDeActivate is disabled
    -InputField 2 (Yellow) - ResetOnDeActivate is disabled
    -Button (Orange) - Button to click to take focus away from input field (can be done by clicking no elements as well (ie. clicking on blue background)

    Steps:
    1. Click input field 1 (Green) and select part of text
    2. Click button to deactivate input field
    3. The input field remains selected (this is acutally fine, this is how it’s supposed to work)
    4. Enable ResetOnDeActivate (this is the issue, the text remains selected, while in 1.3 selection and caret were cleaned)
     
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Since it is almost 4:00 AM, I'll take a closer look at this tomorrow but wanted to quickly provide some feedback before going to sleep.

    In version 1.4, selecting another input field will cancel / release the selection of the previous input field. This is consistent with input fields in Unity / Editor. This is also consistent with other applications.

    Clicking on some other control which could be a button or scrollbar, will not release the selection of the currently active input field as these other controls might be use to interact with the input field. Double Clicking will release the selection.

    These changes are by design but if your use case requires the ability to maintain multiple selections, then please provide me with some better insight / explanation of this use case.

    P.S. I believe setting resetOnDeActivation to false and then calling DeactivateInputField() should allow you to control / disable the selection.
     
    Last edited: Apr 2, 2019
  3. Micito

    Micito

    Joined:
    Dec 5, 2014
    Posts:
    16
    Hi Stephan,

    First of all thanks for a quick answer, we really appreciate it.

    We do not require ability to have multiple input fields active. We want to have only one active at a time.

    What we have is input field that has ResetOnDeActivate = false and has some text inside with part selected. This input field is not selected by EventSystem and both selection and caret are visible (this is the desired effect)

    What we need is that, once we toggle ResetOnDeActivate to true, input field's selection and caret be hidden. This is the way it was working in 1.3 (as described in the example above)

    Currently in 1.4, once we toggle ResetOnDeActivate to true nothing happens. Selection is still visible and caret is blinking.

    We have tried:
    • ForceUpdateLabel() on input field after we toggled ResetOnDeActivate
    • ForceUpdateLabel() on input field few frames after we toggled ResetOnDeActivate (just in case)
    • Disabling input field, and then enabling it (selection and caret are hidden while it's disabled, but appear once it's enabled)

    Is there any other methods like ForceUpdateLabel that could help? Any hacky solutions we can try at least? Or is this maybe a bug or consequence of other changed?

    Thanks in advance,
    Milan
     
  4. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Is there a reason you were toggling ResetOnDeactivate other than to clear the selection?

    For instance, if I was to introduce a new function like ReleaseSelection() which would do the same thing without having to change the ResetOnDeactivate, would that be a workable solution?

    ReleaseSelection() would make the caret or selection go away but still be maintained internally where re-activating the input field would restore these.

    I could also add an optional parameter to DeactivateInputField() like:

    Code (csharp):
    1. public void DeactivateInputField(bool clearSelection = false)
     
    Last edited: Apr 3, 2019
  5. Micito

    Micito

    Joined:
    Dec 5, 2014
    Posts:
    16
    That can work. Can we try it?
     
  6. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Add the following function above the DeactivateInputField function.

    Code (csharp):
    1. public void ReleaseSelection()
    2. {
    3.      m_SelectionStillActive = false;
    4.      MarkGeometryAsDirty();
    5. }
     
  7. Micito

    Micito

    Joined:
    Dec 5, 2014
    Posts:
    16
    As far as I know, I don't have access to TMP source, how can I change this?
     
  8. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    The package manager versions of TMP (ie. all versions for Unity 2018.1 or newer) include source code. Packages are located in the local cache which on Window is "C:\Users\...\AppData\Local\Unity\cache\packages\packages.unity.com\com.unity.textmeshpro@1.4.0".

    Furthermore, I believe you should be able to see the Packages folder in your local project as seen below:

    upload_2019-4-4_1-24-53.png
     
  9. Micito

    Micito

    Joined:
    Dec 5, 2014
    Posts:
    16
    That works great. Thanks a lot!

    I have one question though. If I change tmp scripts through unity, will that affect all new projects created, or will that change apply only to the current project?
     
  10. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    If the change is made to the local cache package version, it will apply to all projects. However, I believe (I could be mistaken) that in Unity 2018.3 where there is now a local PackageCache in the local project Library folder that it is possible the changes are just local to the project. But again, this is something that needs to be verified / tests. Ie. I haven't had time to test.

    Having said all that, the change you requested "ReleaseSelection()" will be included in the next release which will be version 1.4.1.
     
  11. Micito

    Micito

    Joined:
    Dec 5, 2014
    Posts:
    16
    Ok, I understand. Thanks a lot for help
     
  12. Micito

    Micito

    Joined:
    Dec 5, 2014
    Posts:
    16
    Just a quick update:

    I changed the script by opening it from Unity. I checked the scripts in other existing projects and new project (both using TMP 1.4.0) and confirmed that changes weren't there. So it appears that the changes were applied only to changed project alone.
     
  13. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Thank you for testing this and sharing the info :)