UITK: How to get Panel Text Settings to work or be used?

Panel Settings isn’t working for me, or I’m doing it wrong. How do I get VisualElements to default to using the font linked to the Panel Settings?

According to the manual “UI Toolkit stores project-wide text settings” in this asset. I linked a Font Asset to the Panel Settings, which is linked to the UIDocument in the scene, but it doesn’t seem to be linked to anything in my project. If I go to the linked VisualElement and delete the font reference, all the text in the panel disappears. How is this supposed to work? Is there a way to define a font globally for my project and have it used everywhere by default?

This is extremely confusing indeed and needs to be addressed. If you don’t mind please log a ticket to ensure we look into it.

The default UI Toolkit theme has a FontAsset defined and thus labels always have a FontAsset assigned and it never fallbacks to this default Font field.

The best way to override the default FontAsset in UI Toolkit is through USS with something like:

:root {
  -unity-font-definition: url("path-to-your-font");
}
1 Like

Thanks @HugoBD-Unity for the help. Follow up:

  1. Where should the font go? When I create a Panel Text Settings is hardcodes the path prefix to “Resources/” implying that the font needs to go into Resources folder. In your suggestion above, if I put the path as “Resources/UI/MyFont SDF” it gets an error (“Invalid asset path: ‘Assets/UI Toolkit/Resources/UI/MyFont SDF’” which implies it expects the font in the project (although Resources is a sub-folder, this isn’t how Unity normally works with Resources)? EDIT: I think the answer is you can use “url” OR “resource” as the prefix for the path and then it finds it in Resources? If that’s true, the question is still relevant in terms of what is actually needed at Runtime and where do things go though.
  2. And is it expecting a Font Asset or the SDF font?
  3. And also related to this, I posted another question here. Where should the related fonts go?

Really appreciate your help. Hopefully these threads will help others when they find it too :slight_smile:
Cheers,
Brett

Hey!

The FontAsset path in Panel Text Settings is needed only if you plan to load fonts through rich text tags like <font="my-font">.

Otherwise, FontAssets can be placed anywhere in your project. As long as they’re referenced in USS and the USS is part of a scene, they’ll be included in the build.

It looks like the issue might be due to a missing asset extension. Try specifying it like this: -unity-font-definition: url("/Assets/Resources/Fonts/Roboto-Regular_SDF.asset");

We recommend using FontAsset instead of Font, as Font is legacy and will automatically convert to FontAsset behind the scenes.

1 Like

Thanks for the info!

1 Like