Search Unity

  1. Looking for a job or to hire someone for a project? Check out the re-opened job forums.
    Dismiss Notice
  2. Unity 2020.2 has been released.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

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

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

  1. MarkSutton


    Sep 25, 2017
    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...