Questions tagged [ui-toolkit]

For questions related to the development of UI using UI Toolkit, and its various components, behaviors or problems encountered while using it. UI Toolkit, however is different from the other technologies/components offered by Unity3D such as the uGUI and IMGUI. To avoid confusion please add other appropriate tags such as [unity3d], [mono], [il2cp], [C#], [android], etc.

UI Toolkit is a technology that encompasses a collection of features, functionality, resources, and tools for developing user interfaces (UI) in Unity3D whether to develop custom UI for the Unity Editor or for Runtime UI.

Its development was heavily inspired by the technologies used in web development like Cascading Style Sheets to specify styling choices and markup file to denote the UI structure similar to how its done with HTML on web pages. This helps developers who are more accustomed with web development, transfer a lot of their knowledge to the design of UI in Unity3D.

This technology however is still on its early development stage lacking some of the features offered by uGUI and IMGUI

Questions or problems related to this tag should:

  1. Not be related, in its greatest part, to other UI systems like uGUI, IMGUI or third party components like those found in the asset store.
  2. Be previously checked for syntax problems or mismatch of variable/property names
  3. In case of being related to specifically to the format or style, provide the appropriate markup excerpts from USS and UXML files.
  4. Follow the general Stack Overflow guidelines for asking questions.

Structure


UI toolkit uses UXML(Unity Extensible Markup Language) to indicate the general structure of the UI. It also offers a way to create and modify the structure visually with a Editor GUI, which just writes changes in the UXML for the user.

Some frequently used structure components are Visual Element(a generic container), Label, Button and Slider

Example of a button with the style class "ButtonStyleClass" and a text reading "Click Me!"

<ui:Button name="Button1" class="ButtonStyleClass" text="Click Me!"/>

Style


For style, UI toolkit relies on USS (Unity Style Sheet) which is very similar to how CSS(Cascading Style Sheet) is structured

Heres an example on how to style a text that would align itself at the center, display itself as bold, with a big font size and the font color being blue

.HeaderTextBold{
    align-self: center;
    justify-self: center;
    font-size: 80px;
    -unity-font-style: bold;
    color: rgb(68, 138, 255);
}

To note that a lot of features are lacking from USS that are present in the a modern implementation of CSS. As in the example above(-unity-font-style), some attributes don't share the same nomenclature as standard CSS and some have a different behavior or even properties.

Behaviour

In place of javascript, UI toolkit relies on standard C# scripts to manipulate the UI behaviour. Unity Software provides some examples along with the documentation to help developers reach their objective

uGUI, IMGUI and UI Toolkit


Unity Software offers a comparison web page for developers to better choose which system to rely on when developing UI.

Some confusion is generated due to the nomenclature of these different tools, to note that usually when using UI Toolkit these namespaces are used.

using UnityEngine; 
using UnityEngine.UIElements; 
using UnityEditor;
using UnityEditor.UIElements;

While uGUI uses

using UnityEngine; 
using UnityEngine.UI; 
using UnityEditor;
using UnityEditor.UI;
23 questions
3
votes
2 answers

Is there a way to easily bind data to UI in runtime

Context So after researching a bit about UI toolkit, i decided to use it for my project as i am very used to CSS and i despise the "default/legacy" UI system Unity3D offers. Unfortunately its on a very early stage of development and they seem to be…
Imeguras
  • 436
  • 6
  • 18
2
votes
1 answer

How to get localPosition of pointer within a VisualElement without a callback

I have an issue with the input system that I can't figure out. I have a VisualElement (using the UI Toolkit), and I need to get the "localPosition" of the pointer on click. (It's going to be a game for touch and mouse so I use pointer.) I can get…
KeepCool
  • 497
  • 1
  • 6
  • 24
2
votes
0 answers

Unity UI toolkit are there box-shadow?

I cannot find a good solution for CSS shadows (box-shadow) I am accustomed to. Unity provides USS that has many options to offer and so common to natural CSS though It lacks shadows (I guess). Can you explain what I can do to get shadows?
2
votes
1 answer

Unity UxmlAttributeDescription not setting values (resetting values)

I'm using the UI Builder for my UI and I'm creating some custom controls. I've already managed to make a custom control which works perfectly fine. But the second one has some problems I can't understand. The problem: I'm able to put my custom…
Daweed
  • 75
  • 6
2
votes
2 answers

Unity UI Toolkit: DropdownField styling

I'm in the process of implementing a form view with Unity's new-ish UI toolkit, and styling my own stuff is simple, using the UI builder. No biggie. When it comes to Unity's pre-built "Controls", styling in the UI builder is very limited. I can set…
Eldamir
  • 9,888
  • 6
  • 52
  • 73
1
vote
1 answer

Unity UI Toolkit doesn't match the game

After a couple of days struggling with UI Toolkit i just dont know what to do. My problem: I have a scene, camera and a gameview from simulator that doesnt match UIDocument Look like this: But gameview: If I build the UI to look from the "Game",…
AlBel
  • 11
  • 1
1
vote
1 answer

Unity-UI Toolkit Binding multiple fields

I was wondering if there is a way how to bind data to multiple properties on the same Visual Element or is it strictly that one element can only have one binding-path at any given time? Something similar what you can achieve in C#/WPF. lets say I…
Aldoras
  • 111
  • 7
1
vote
0 answers

Is it possible to add keyboard and controller support to UI Toolkit buttons in Unity?

I tried looking around online, but it doesn't seem like there's support for keyboard and controller inputs for buttons in the relatively new UI Builder for Unity. From what I can tell, the old button system used Event Systems, but I wasn't able to…
1
vote
1 answer

Does Unity UI Toolkit support CSS media queries?

I would like to override the alignment for elements in my UI on small screens. I've added the following code to the style sheet, but it is not applied to my canvas in UI Builder and does not show up in the USS preview within UI Builder. @media…
Bacon Nugget
  • 107
  • 11
1
vote
0 answers

Text is always black with any imported font in Unity

I'm using UI toolkit. I have imported few different fonts, and set up a label. But when I assign custom font and font asset, changing text color becomes unresponsive and text is stuck on black. There are no additional styles. I tried - swapping…
Dvole
  • 5,725
  • 10
  • 54
  • 87
0
votes
0 answers

Unity UxmlTraits uxmlChildElementsDescription not loading its child, therefor not saving any states

Simply traying to create a custom visual element that could show/hide only one of it's child by setting an enum attribute in inspector, however the whole states reset after saving the UI builder which is using this UI element with two child, what am…
Ehsan Zargar Ershadi
  • 24,115
  • 17
  • 65
  • 95
0
votes
1 answer

Unity UI Toolkit - Unable to select child element

I am trying to select the highlighted element using the selector shown in the search box: #StateEvent > * > .unity-foldout__input But it doesn't seem to be able to find it - no search results found. And in code it is unable to be found too with the…
asker
  • 198
  • 2
  • 11
0
votes
2 answers

How to add an array of gameObjects to an Editor window in the new Unity UI ToolKit?

I can't find how to add an array of gameObjects to an Editor window in the new Unity UI ToolKit like in the picture: I don't find an array component in the UI Builder library and the ListView does not seem to be the right choice for me.
ouzari
  • 397
  • 3
  • 12
0
votes
1 answer

Remove selection from ListView element in UI Toolkit

When I drag the elements inside the ListView component, in the new UI Toolkit system, the element selected get white background but I want it to be transparent. I just want to drag the elements like a list but without changing the elements…
0
votes
1 answer

Cannot save Shape drawing as Image to Photos with ImageRenderer View

I've this View with which I want to let user draw over an image, and then save the image + drawing as Image in Photos. import SwiftUI struct DrawView2: View { var image: UIImage @State var points: [CGPoint] = [] var body: some View { …
1
2