Search Unity

TextMesh Pro vertex colour issue in Input Field - please help!

Discussion in 'UGUI & TextMesh Pro' started by MarkSutton, Feb 13, 2020.

  1. MarkSutton

    MarkSutton

    Joined:
    Sep 25, 2017
    Posts:
    2
    I don't normally resort to forums, but this one is driving me mad.

    I'm writing a coding-game that needs a multi-line input box, implemented as a TextMeshPro Input Field, where users enter code. I need to colour text in this box as a visual aid for coding (I have a custom parsing system that tells me which colour each character should be). I don't want to use RTF tags for colour, as I also need to be able to read the text string back from the input field whenever anything is changed, and I suspect stripping all the tags out again is going to be slow and generate a lot of string-garbage. I also don't want users inputting text that can be interpreted as RTF tags (but can't simply ban < and > characters as they are used in language the users are writing in).

    It looks like the correct way to do this is to directly modify the vertex colours directly. I have found samples that show me how to do this, but I can't work out WHEN I should be doing it, if/when I am meant to turn the renderMode flags on and off, and if so how to drive the correct types of redraws from code. This stems I'm sure from my imperfect understanding of the render/draw sequence that TMPro uses, but I can't find any clear documentation for this. What I want to happen is:
    • When I change the text content from code, I want to set all the vertex colours straight away using my custom code, then let TMPro take over as normal.
    • When the user changes the text in the input field, I want to re-run my vertex colouring code as soon as possible, ideally before TMPro has had a chance to redraw the text box (with incorrectly coloured characters), as this would cause a flicker.

    My attempts to do this at the 'obvious' points (i.e. directly after setting the text string, and in the OnValueChanged handler) simply don't apply any colour at all, though I know that my colouring-code DOES work as it shows properly if I apply it every frame in an Update handler. Clearly TMPro is replacing my custom colours with default ones somewhere in it's pipeline. I just don't understand how to stop it doing this.

    Does anyone have a good handle on how to do this?

    Thanks! Happy to elaborate further if explanation above is still fuzzy...
     
  2. Kaith

    Kaith

    Joined:
    Jan 26, 2013
    Posts:
    2
    Hi Mark, did you manage to solve this? I'm trying something similar.