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

Question How to set a font as default for every Label?

Discussion in 'UI Toolkit' started by curtispelissier, Oct 24, 2022.

  1. curtispelissier

    curtispelissier

    Joined:
    Jul 26, 2019
    Posts:
    39
    Hello,

    Is it possible to set a font as default in UI Toolkit? I want to make a "global" USS for the entire project (following the Figma rules for components), and all the Labels and Buttons must use the same font.

    The problem: we need to set the font on every label everytime we want to add one, even in runtime. I made a Panel Text Settings for my font and also a Theme Style Sheet but I don't understand how I can enforce the font on every element or juste make the font as default for all my game.

    upload_2022-10-24_17-42-15.png

    I even tried to use CSS to import my font, but I think USS is not working like this.

    upload_2022-10-24_17-47-20.png
     
  2. MousePods

    MousePods

    Joined:
    Jul 19, 2012
    Posts:
    755
    Can you make a global.uss or shared.uss stylesheet and add it to every UIDocument?
     
  3. curtispelissier

    curtispelissier

    Joined:
    Jul 26, 2019
    Posts:
    39
    It doesn't solve my problem. My labels font's are set to "none".
    upload_2022-10-24_17-56-40.png
     
  4. MousePods

    MousePods

    Joined:
    Jul 19, 2012
    Posts:
    755
    This is what I have, or maybe I am misunderstanding your issue.


    Code (CSharp):
    1. Label {
    2.     -unity-font-definition: var(--regular-font);
    3. }
     
  5. curtispelissier

    curtispelissier

    Joined:
    Jul 26, 2019
    Posts:
    39
    Ok, I tried you "unity font definition" but with mine text asset and it worked! I added those lines in my TSS file directly.

    Code (CSharp):
    1. * {
    2.     -unity-font: url("project://database/Assets/Resources/FontsMaterials/gamestationtext.otf");
    3.     -unity-font-definition: url("project://database/Assets/Resources/FontsMaterials/gamestationtext_UITK.asset");
    4. }
     
    MousePods likes this.