Search Unity

TextMesh Pro - How to set the font to null in the inspector

Discussion in 'UGUI & TextMesh Pro' started by Cris_2013, Feb 7, 2019.

  1. Cris_2013

    Cris_2013

    Joined:
    Nov 25, 2017
    Posts:
    39
    Hi there,

    I've created a small localization system that dynamically loads and unloads font assets based on the language and the text that needs to be played.
    I'd like the GameObjects that I have in scenes or prefabs to not have any font assigned to them (to avoid loading unnecessary fonts).
    I have tried to click on the font field and then NONE but that doesn't work. I've also tried to make an editor script that access the component and sets the font to NULL but that doesn't work either :(

    Is there any way to achieve it?

    Many thanks!
     
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    As you have uncovered when the text component can't find a valid font asset, it will default to using the Default Font Asset specified in the TMP Settings. If the Default Font Asset field in the TMP Settings was left empty then those text components would also end up empty.

    I have not tested how a text component will behave without a valid font asset so make sure they are assigned a valid font asset prior to enabling them.
     
  3. Cris_2013

    Cris_2013

    Joined:
    Nov 25, 2017
    Posts:
    39
    Many thanks for your response.

    I've managed to make it work as you said.

    If the GameObject is active when the font is NULL then it gives a few warnings and it doesn't create the text even if I assign the font afterwards. But if I assign the font while deactivated and I activate it afterwards it just works fine :)