Hi everyone. I’m an indie game developer, I’ve made a few things in Unity including one pretty well-known thing. I taught people to use Unity to make games for 8 years at NYU. In this thread I’m going to attempt to add a font to a drop down menu using UI Builder and UI Toolkit in the latest LTS build of Unity.
To get started I made an empty 3D project - there are no package dependencies since UI Toolkit is now a core element of Unity. I want to make a runtime menu to allow the user to select screen resolution for a game. So, following the docs I’ll start by right clicking in the project window and creating a ‘Default Runtime Theme File’. Without that I can’t make a runtime UI at all.
Inspecting that file, I can see it loads a ‘default’ style sheet.
Before we go any further, let’s see what’s in there by double-clicking it:
Looks like the real default theme is in a hidden location! Well, it’s not revealed where or what’s in there in the docs, so clearly we’re not going to be editing that code. Browsing the forums, I eventually deduce that I’m supposed to override this theme using my own .uss style sheet. That’s fine, I have years of experience making websites (thankfully! whew, I’m glad I wasn’t always a game developer). So let’s go ahead and make a new style sheet so we’ve got something we can work with. I right-click again to create a ‘Style Sheet’ called Menu.uss, and then I apply that as a reference in the UnityDefaultRuntimeTheme I created earlier (this wasn’t a documented process, but something I found an engineer mentioning in these forums).
Now I have what I need to override the default styles, and we’re ready to start styling things. Oh last thing, I’ll need a font for my dropdown. Let’s go with Lato, one of my favorite free fonts. I’ll drag the TTF into the project window. Next thing is to create a ‘font asset’ - it’s kind of like when you create font assets for Textmesh Pro, but it’s a new undocumented way. It’s not under Create/UI Toolkit; in this case you look under Create/Text and choose ‘FontAsset’. Be careful though! If you just right-click the project folder like you would to create any other type of file, nothing will happen at all! You have to right-click the font file and choose ‘create/text/font asset’ from there.
(continued)