#🧰┃ui-toolkit

1 messages · Page 20 of 1

ashen moss
#

Any reason you have not updated to the LTS of Unity 6? 2023 is such a dead product atm

#

OK, found a "workaround", by effectively wiring up to the "FocusIn" event and then selecting all text. But it feels "wrong"

textField.RegisterCallback<FocusInEvent>(evt => textField.SelectAll());
vocal gazelle
#

Also - two typos in this error; is there more details anywhere on how to avoid the instantiation workflow/issues?

trim torrent
#

Learning the Toolkit at the moment and I was about to post a message how I find the Dragon Crashers example confusing in that the UI Builder view doesn't match the game view at all. Then I found the the theme dropdown... It was set to Unity Default Runtime Theme 🙂 It all makes sense now 🎉

trail oasis
#

has any one made visual elements that can follow objects in the scene or is that not really possible with ui toolkit elements?

trim torrent
#

Not sure if it's not possible at all, but their documentation does not recommend using it for that.

dark blade
#

why click on clickable change pseudo state to active, but not with click event?

rough scarab
woeful mauve
#

You can try to implement UltraLight by yourself, but you cant use backdrop / post processing with this kind of solution

Other solutions exist to do that but performance are not really good :/

But i think its okay if you are using only one renderer for the ui

trail oasis
ashen moss
#

As I ever delve deeper in to UI Toolkit, I always seem to be hitting the most basic of questions which are not answered anywhere (although as Coop mentioned, maybe I should look more into castle crashers).

But here goes:

Which is better to NOT display UI Documents when not in use?

  • Disable the GameObject holding the UI Document? (or)
  • Set the CSS element to "display = none" ? for the panel

I've got several GameObjects for different screens in our application, each with their own UI Document but all sharing the same CSS. But for optimisation, which imethod is better/recommended for NOT displaying UX?

rough scarab
ocean snow
#

Hi guys!
Does anyone have any knowledge on how (if?) I could be able to place the old UI Canvas, INBETWEEN UI toolkit visual elements? Basically as follows:

#

this where the upper UI toolkit and bottom are the same document

#

It's my understanding that toolkit has no Z sorting, so I was wondering if there are other solutions

ashen moss
acoustic oyster
#

Hi everyone, I am struggling with one thing and that is figuring out how to have a custom element hold a reference to an asset. In the example below I have a simple button that I want to hold an audio clip reference and on hover play the sound.

I could after cloning the tree get all the custom button elements and then pass the audio clip to each individual element, but what if there are multiple types of custom UI elements that require such audio clip. That would mean I have to query a bunch of different types of elements, which is tedious and prone to error. Moreover, what if I have a custom element that after creating it, it creates custom buttons. That would make it tricky to pass the asset reference from the mono behaviour to that custom element.

How do you deal with such things with UIToolkit? I can't figure out an easy elegant solution to this. Would really appreciate the help

[UxmlElement]
public partial class CustomButton : Button
{
    public CustomButton()
    {
        RegisterCallback<PointerEnterEvent>(OnHoverEvent);
    }
    private void OnHoverEvent(PointerEnterEvent evt)
    {
        // Play Sound Effect
    }
}
<ui:UXML xmlns:ui="UnityEngine.UIElements" engine="UnityEngine.UIElements" editor-extension-mode="False">
    <CustomButton text="Button A" />
    <CustomButton text="Button B" />
    <CustomButton text="Button C" />
    <CustomButton text="Button D" />
</ui:UXML>
lone island
#

Appears to be a bug in AppUI RadioGroup. When I create an editor window and it appears, the group works properly, but if I dock the editor window, All of the Radios get set, and it breaks functionality of the group and radios.

#

<appui:ExVisualElement name="travel-options-container" class="action-group travel-options-container">
<appui:LocalizedTextElement text="Travel Options" />
<appui:RadioGroup name="travel-options-radio-group">
<appui:Radio key="none" label="None" value="true" name="travel-option-none" />
<appui:Radio key="follow_target" label="Follow Target" value="false" name="travel-option-follow-target" />
<appui:Radio key="spline" label="Spline" value="false" name="travel-option-spline" />
</appui:RadioGroup>
</appui:ExVisualElement>

lone island
# acoustic oyster Hi everyone, I am struggling with one thing and that is figuring out how to have...

html has the <audio> element which allows you to source a sound file, and it would be cool is uxml had the same thing.. I don't know if it does, but I do know that you can add an AudioSource component to the GameObject in your heirarchy view that holds your root UIDocument, add a reference to something that can play the AudioSource. I use a AppUI App instance to hold a reference to the AudioSource and then have it play when the hover event occurs.
appUIApp.Instance.hoverAudioSource.Play();

hexed heron
#

Why am I getting this error when I launch QuizU sample?

#
ArgumentNullException: Value cannot be null.
Parameter name: e
UnityEngine.UIElements.UQueryExtensions.Q[T] (UnityEngine.UIElements.VisualElement e, System.String name, System.String className) (at <39dcd6cb83f94d46afd27f779648424a>:0)
Quiz.BootloadScreen.SetVisualElements () (at Assets/Unity Technologies/QuizU - A UI Toolkit demo/Quiz/Scripts/UI/Screens/BootloadScreen.cs:62)
Quiz.BootloadScreen.OnEnable () (at Assets/Unity Technologies/QuizU - A UI Toolkit demo/Quiz/Scripts/UI/Screens/BootloadScreen.cs:35)
#

I haven't changed a single line of code

hexed heron
#

Other question:

private void Initialize()
{
    NullRefChecker.Validate(this);

    VisualElement root = m_Document.rootVisualElement;

    m_SplashScreen = new SplashScreen(root.Q<VisualElement>("splash__container"));
    m_StartScreen = new StartScreen(root.Q<VisualElement>("start__container"));
    m_HomeScreen = new MainMenuScreen(root.Q<VisualElement>("menu__container"));
    m_SettingsScreen = new SettingsScreen(root.Q<VisualElement>("settings__container"));
    m_LevelSelectionScreen = new LevelSelectionScreen(root.Q<VisualElement>("select__container"));
    m_GameScreen = new GameScreen(root.Q<VisualElement>("question-screen__parent"));
    m_PauseScreen = new PauseScreen(root.Q<VisualElement>("pause__container"));
    m_EndScreen = new EndScreen(root.Q<VisualElement>("end-screen__container"));

    // Notify the GameController the UIScreen for LevelSelection has been setup
    LevelSelectionEvents.Initialized?.Invoke(m_LevelSelectionScreen as LevelSelectionScreen);

    RegisterScreens();
    HideScreens();
}

I don't understand why they're created this way. As in:

m_PauseScreen = new PauseScreen(root.Q<VisualElement>("pause__container"));

means that we are creating a pause screen.
However, if PauseScreen doesn't exist yet, how is "pause__container" valid as a root node?

Is there a separation between the screen classes in a way that the UXML exists but the script isn't actually attached to it, Hence the need to pass it in?

lilac mortar
#

hm when i set .text on a Label from script it seems to remove whitespaces

#

why could that happen?

#

hm weird, it seems like it only does that in runtime ui

#

hm seems to happen when i have e.g. string text;
text += "hello " + "world";
then spaces at the end of e.g. "hello " get cut out
although when i print that text to console it works correctly

#

using \u00a0 works

fickle perch
#

okay I feel stupid

#

how do you disable WASD focus navigation in runtime UITK?

#

this is even like, one of the Qs in the the FAQ but it doesn't say how to selectively disable it, or how to disable it without having a ugui event system present, I think?

#

EventSystem.SetUITookitEventSystemOverride(null, true, false); throws because I don't have an EventSystem or ugui in the scene, I think

#

I thought it would be enough to consume/use/stop propagation of the events using navigation keys, but for some reason it doesn't seem to matter

#

guess I'll just remove wasd from input alt keys for now

fickle perch
#

okay I have another questrion

#

I want to detect alt+LMB dragging, but it looks like if alt starts being held outside of the app itself, uitk's modifers don't consider alt to be pressed, until after what I presume is the key repeat delay

#

which means that if you focus another app, and then you want to start using the camera (alt+lmb), it seemingly doesn't work until after like 0.4 seconds

#

and it looks like it's caused by uitk's mouse event modifiers not updating correctly

fickle perch
#

interestingly this only happens in editor, but it's fine in builds

storm prism
#

hi, is it possible to somehow unregister drag event from TreeView in C# script? View contains serialized structs which stores reference to sprite that i would like to edit by drag n drop, but it apparently interferes with parent, so i guess Unity tries to add this sprite to the list and i get null reference exception:

NullReferenceException: Object reference not set to an instance of an object
UnityEngine.UIElements.ListViewDragger.TryGetDragPosition (UnityEngine.Vector2 pointerPosition, UnityEngine.UIElements.ListViewDragger+DragPosition& dragPosition)

already fighting with this for too long ;/ and making UXML for such simple editor script feels overcomplicated

#

docs say "To enable dragging items, override canStartDrag."
but there is no .canStartDrag in TreeView ;_; (probably there is in Unity6, but i use older version actually there is, but its internal)

devout vine
#

Is it only me or does UI Builder sometimes just mess up elements out of thin air? I've noticed that it happens with elements that doesn't have a class with custom style on it (Unity 6000.24f1)

devout vine
#

Might add that I copy pasted some elements from another UXML and that could probably be the cause

strange hill
#

Any reason that UI is upside down in device simulator? 🫠

scenic brook
lunar rain
#

It being flipped only on the simulator, I’d guess the screen scale might make the scale negative

strange hill
#

In the game view it looks good. There is only problem in simulator

signal loom
#

Hey guys. I'm using ListView with ItemTemplate and data binding. It works, but I want to add extra logic for item template.
I've created script and template, but I don't understand how to access elements in this item template, because constructor is called, but i can't query elements because almost everything in TerrainTileRule is null

signal loom
flat crag
#

I'm using the ui builder for the first time and I'm trying to create something like this where when you're on a button (hovering or selected) there's this small square next to the button to indicate that as the button you're currently on.

It seems like this functionality is impossible with how ui builder buttons work? I would really appreciate being pointed in the right direction because I cant really figure it out.

strange hill
signal loom
restive bobcat
#

Any one make upto date or know of videos for this toolkit for unity 6 they can recommend?

vivid swift
#

so I have two canvases. On each I have a button which goes above another button on the other canvas

#

but I can't click on the button on top even if the other canvas is disabled

#

how come

rough scarab
vivid swift
#

sorry

fiery mountain
#

why in the world is unity not recognizing that my listview not respect having reorderable disabled? is there a known bug for that?

strange hill
#

I got template with button and text, how to change text binding (unity localization) for templates instances? I change icons adding differend classes. But don't know what to do with bindings.

fickle perch
#

is there a way to make a non-VisualElement an IEventHandler?

#

or, hm, that's possible

#

but rather

#

is it possible to use mouse capture on a non-VisualElement IEventHandler?

#

because the mouse capture currently checks types and just nopes out if it isn't matching

#

hmm looks like it's pretty hardcoded to be VisualElement based

#

hm. this feels like I'm trying the wrong solution for the problem

fickle perch
#

ok I think I worked around it with my own capture thingy c:

terse creek
#

does anyone know how to check if the mouse cursor is over any UI document? I don't want my inputs to work if the mouse is on any UI that needs scrolling, clicking. etc.
searching says the best way to do this is to keep a list of all UI documents, and use IPanel.Pick on each one, but it feels like a workaround. I'm using the new input system and unity 6
the inputs I have are like
if (C.get.Camera.Pan.triggered) {lastPanPosition = C.get.Camera.PanPosition.ReadValue<Vector2>();} (right click, triggers over UI)
if (C.get.Tiles.Select.triggered) {SelectFeature(feature);} (left click, triggers over UI)
camZoomInertia -= C.get.Camera.Zoom.ReadValue<float>() * zoomSpeed; (scroll wheel, triggers over UI)
does anyone have a simple solution or is IPanel.Pick() and keeping track of every UI document the best way?

SOLUTION: Add an EventSystem, and use EventSystem.current.IsPointerOverGameObject();
link: https://docs.unity3d.com/6000.0/Documentation/Manual/UIE-faq-event-and-input-system.html#mouse-over

wild onyx
#

Im currently battling with the TreeView and am having a lot of trouble with adding children. I succeeded in adding root items and a custom icon but the children are not being displayed somehow. Does anyone have an idea what the problem could be? Because it seems like the view adds the correct amount of children but just doesnt display it properly

sullen bay
#

Is it possible to force an element layour recalculation before it's rendered? The goal here is to recalculate element positions and then make some modifications based on the USS layout logic before drawing them.

#

So, for example:

_container.Add(new MyElement());
_container.RecalculateLayout(); // or whatever
foreach (var e in _container.Children()) {
  e.style.backgroundColor = Color.Lerp(Color.yellow, Color.red, e.rect.max.y / _container.rect.height);
}

The layout would be calculated, other styling options derived from that layout, then all drawn in one go.

devout vine
#

How do i use EnumField to change the value of a custom enum inside a script?

So, i have:

_enumField.RegisterCallback<ChangeEvent<Enum>>(OnEnumFieldChanged);

void OnEnumFieldChanged(ChangeEvent<Enum> evt){
  localEnum = (MyCustomEnum)evt.newValue;
}

But then the changes i made on the UI are not reflected on the enum inside the script, and if i try to explicitly cast from Enum to MyCustomEnum, Unity hangs and i need to terminate process inside Task Manager. Any guess in why this is happening?

Edit: It works fine, the issue i was having (Unity freezing) was not related to this at all. Also to initialize the field with a custom enum it needs to do _enumField.Init(MyCustomEnum.Value)

rugged matrix
#

Anyone here familiar with this particular part of UI Toolkit: Parallel tessellation ? Or could someone mention an example of a use case?

woven hinge
#

I've defined my style sheet and the doc like this, but the :hover selector never seems to select my button (neither in game view nor in the UI Builder viewport)

#

oh wow, I had a space between #Title and :hover, didn't know that wasnt valid ^^'

lilac mortar
#

does ui get re-rendered everytime you change something, or are all changes collected until end of frame to re-render?
e.g. if i set a label text e.g. 5 times in a frame, will it render 5 times or only render at end of frame?

dark blade
karmic isle
#

In property drawer CreatePropertyGUI, how can you align label like EditorGUI.PrefixLabel?
in the image, the above field is [SerializeField]int, and the below one is my class with CustomPropertyDrawer.CreatePropertyGUI.

golden fjord
#

There's no code completion on UXML and USS under Microsoft Visual Studio 17 (2022) ?
Syntax highlighting is present, but I'm not given any suggestions, and tools for formatting documents are not available.
However, MVS and Unity are up to date, including Visual Studio Tools for Unity.

golden fjord
#

I guess, as far as visual studio is concerned, we're just relying solely on the UI Builder for now.

dark blade
sick ice
#

Hi,

I have a scene with two cameras.
Maincamera output is set to none
Rendercam is set to a rendertexture.

In the unity editor game panel, the ui built with uitoolkit shows up correctly.
When I build the game, the ui doesn't show up at all.

The game has a canvas in it set to world space, which has two raw images under it.

#

Any suggestions of things I can look at?
It's set to dx11

#

Version 2023

lean yacht
#

Hi, how do I change the vertical scroll speed of the scroll view for keyboard/gamepad input?

fickle perch
#

is there a way to reload UITK's/the new input system's button state while running the game in editor?

#

I'm encountering an incredibly frustrating bug that basically delays all my keyboard inputs by about a second every time I focus back to the game view

#

it seems to be a bug in unity that, if you hold a key while unity's editor UI has focus, that key won't be registered as down in the game view, when switching to it, until after that second has passed

#

like, imagine the scene view alt+LMB camera always being delayed by 1 second every time you click back to it 💀

#

I've reported a bug and posted a thread about it here, but it'd be nice to find a workaround in the meantime

#

just some way to tell the input system to just, RefreshAllStatesNowPls();

#

I also tried this, no dice

void OnApplicationFocus( bool hasFocus ) {
    foreach( InputDevice device in InputSystem.devices )
        InputSystem.ResetDevice( device, true );
}```
flint bough
#

Hey everyone, my USS is not applied in the editor when I press play and I don't know why. This is my uxml

<engine:UXML xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:engine="UnityEngine.UIElements" xmlns:editor="UnityEditor.UIElements" noNamespaceSchemaLocation="../../../UIElementsSchema/UIElements.xsd" editor-extension-mode="False">
    <Style src="project://database/Assets/UI/Main.uss?fileID=7433441132597879392&amp;guid=caac3f53eded4a99a1894ed47608c26f&amp;type=3#Main" />
    //.... CONTENT
</engine:UXML>

So the content is loaded, it has the right classes but the styles from Main.uss are not being applied

#

they are applied in the builder etc, just not in the play mode window anymore. Does anyone know whats going on?

golden fjord
fossil smelt
#

Live Reload is only working when I click inside unity editor window.
How can I make it work when I am in my editor (Rider, vscode etc) and I edit the uxml or uss.
I want to be able to save and have the changes updated in Unity without having to click in the Unity editor.

last oracle
#

Hey. Anyone know how to restrict focus inside specific window(visual element)?

sick spoke
#

hey everyone

#

i just got unity 6 installed but i can't open it unless i use administration

#

can someone explain why?

ornate cliff
sick spoke
#

i rebooted my pc

#

now i don't need administration

#

i finally downloaded unity 6 after 2 days lol

still lantern
#

Is there any samples or anything for how to use the runtime binding in a 'real' project. The recommended approach in the Manual is basically an MVVM architecture. But it isn't quite clicking what they intend that to look like.

#

Or just recommendations for how to approach it.

lunar dove
#

Hmm, how do I overlay the UI Toolkit/UI Document on the Dummy Camera/Virtual Camera? I've prepared the UI Document for my Project but I'm unsure where to put it in since my 'Main' Camera is under my Dummy Camera as seen below:

rough scarab
#

put it wherever you want, it doesn't care about either

lunar dove
#

Ok

#

Issue is the game doesn't draw the UI after I put it in.

#

Just to confirm:

#

I've put in both Pannel Settings + Source Asset

rough scarab
#

Screenshot your panel settings, and use the UI Toolkit Debugger to validate where your elements are in the final setup

lunar dove
#

Gonna share it in here just incase.

rough scarab
#

I can't tell how that UI is set up, you should use the UI Toolkit debugger and try to see what's going on in the game view

lunar dove
#

Ok

rough scarab
#

fill the UI with a big element and see if that becomes visible

#

if either of those show your UI is in the scene then you know it's just off-screen

lunar dove
#

Ahh, its off-screen then

#

Strange, I had it matched to game view.

#

My Game View is in Full HD(1920*1080).

#

Ok

#

I fixed it

#

👍

rough scarab
#

you should probably be anchoring it correctly so it cannot be off-screen

lunar dove
#

Anchoring?

#

Like making sure its on the camera at all times?

lunar dove
#

Ah

#

Like this then(for the Anchoring) @rough scarab. Mind the canvas.

rough scarab
#

Instead of using absolute positioning you can use alignment

lunar dove
rough scarab
#

You can also use percentages

#

Basically I would rely on flex and alignment wherever possible

#

You can make a root element that's absolute positioned with 0, 0, 0, 0 offsets to take up the entire screen

#

and have it align its children to the bottom middle

#

and if this element is a child of that, then you've avoided hard-coding the offset

lunar dove
#

Ok, I got the idea on how the Anchor actually works @rough scarab

#

This Player_UI_Anchor will be my foundation and Anchor which Player_Character_UI will rest upon.

fickle perch
#

I feel stupid SCWWcrying

#

is it supposed to be super hard to figure out how to style hover/checked states of tree views?

#

I feel like I have to be missing something, like, some way to reference how unity styles them, rather than guessing over and over again where and if and how my css rules will take precedence over the default styles

#

like, I want to make it so that, when hovering an unselected item, I want there to be a specific background color

#

and when hovering something selected, I want to use the regular selected color, ie: not have a hover state

#

butuuuuh my selectors are not cooperating

#

is there a way to override unity's default runtime UITK styling without having selectors for every single case and element type?

#

like some global color variables or something at least

#

the default runtime theme seems to ignore and/or override me adding --unity-colors-button-background: rgb(63,127,255); to my USS

rough scarab
#

Are you putting your styles in a theme style sheet or a normal one?

fickle perch
#

a normal one I think!

rough scarab
#

Mmk, well then precedence should act somewhat normally. Your styles always have precedence over the theme style sheet, and follow normal precedence rules against other sheets

#

I had a very annoying time with theme style sheets, as they seem like a good place to define styles but then other style sheets always have precedence over them which makes the precedence rules totally useless

fickle perch
#

hmm, my theme file looks like this

@import url("GeoUSS.uss");```
#

not sure if it should

rough scarab
#

Yeah I wouldn't do that

#

Unless you don't plan on having sheets elsewhere...

fickle perch
#

what would you recommend?

#

I mostly just want to start with the default theme and then work my way away from it, ideally without having to do specificity surgery for every single element in every single situation

rough scarab
#

I'm not sure if it's the best way but it's what I'm doing on the current project: referencing a root sheet at the top of the UXML

fickle perch
#

is that possible to do with the UI builder?

#

or will it override it

rough scarab
#

If you have the theme just be the built in import, and you apply your sheets directly to the hierarchy then you take precedence always

steep flume
#

hello

#

i need help in unity

rough scarab
#

I am a little unfamiliar with the builder as we're not using it in the current project. I presume you can just add the sheet to its sheets section

rough scarab
fickle perch
#

yeah that adds a <Style src=" at the top

steep flume
rough scarab
steep flume
#

i can't make preject in unity

rough scarab
#

Ask in a relevant channel buddy

steep flume
rough scarab
#

Well looks like you never read the channel I linked because it explains where to go if that's the case in the first sentence

steep flume
#

i want room no location

fickle perch
rough scarab
fickle perch
rough scarab
#

I believe you shouldn't be fighting for precedence with this setup

#

You just get it if a selector matches at all

fickle perch
#

it's also really annoying that the default theme isn't (easily?) readable

rough scarab
#

Very annoying

fickle perch
#

like if I could read that then I could at least debug and see what selectors I should use

rough scarab
#

Is the debugger not showing you enough?

#

For me seeing the sheet would just be a great speed up, and would help avoid the weird stuff I have to do to see pseudo styles (like tabbing out to get them to stay active, occasionally pausing)

fickle perch
#

yeah I just want a list of "here are the selectors that might affect the look of this thing, also you can select this text to copy/paste later"

rough scarab
#

Maybe I'll make it a weekend mission to find out how to get them, or at least write a thing to convert them from the runtime. For now, sorry I couldn't be of more help

fickle perch
#

like, is there a way for me to tell where this color is coming from?

#

and the debugger is like "its from the unity stylesheet henlo " and im like yeah I know but given what selector and from what variable?

rough scarab
#

The .unity-button selector may just hard code it. I'm on my phone-does it usually show vars in that area?

fickle perch
#

it doesn't seem like it, but I'm not 100% sure

#

clicking through a bunch of elements I'm not finding a single variable indicator

rough scarab
fickle perch
#

yeah that's the one I'm setting everywhere to no avail ;-;

#

I don't understand why it's not getting picked up

#

(first one is :root)

#

if I select the root element in my UI in the debugger, it does show this variable in the list, but with unity's default value I think

#

i just want to edit the colors SCWWcrying

rough scarab
fickle perch
#

right!

#

yeah I mean the order here looks fine

#

it's just the button color variable that's not coming through, it seems

#

unless these buttons don't use that variable

#

which I don't know how to check

#

actually it might be coming from elsewhere

#

still don't know how to check though SCWWcrying

#

looks like the background color is set to this parent

#

coming from an unknown location in the default stylesheet

#

time to hunt for (0.792,0.792,0.792,1.000) manually ig ;-;

#

god this would be so much easier if I could just read the uss source

#

low key losing my mind over how hard this is, for no reason

#

and I can't just ditch the default theme without breaking layouts of built in controls/panels/scrollbars

rough scarab
#

I'd just not bother trying to override it like this, ignore these color variables and make your own

#

It seems like they're unused, I can't get them to work (I got out of bed and took a look)

#

like...

:root {
    --unity-colors-button-background: rgba(255, 0, 0, 1);
}

.unity-button {
    background-color: var(--unity-colors-button-background);
}

this works

#

so clearly the variable isn't used

#

I just think it's all hard-coded

fickle perch
#

;-;

#

it's just super hard to find the right selectors in some cases

#

or maybe I'm separately running into that logical vs physical child issue

rough scarab
#

is it supposed to be super hard to figure out how to style hover/checked states of tree views?
Are you still stuck on this one?

fickle perch
#

got sidetracked trying to figure out the variable override

#

gonna get back to that in a bit

#

that one was also annoyoing to debug bc idk how to add elements to tree views to I need to exit/enter play mode every time

#

(and hot reloading the ui breaks things in my case rn)

rough scarab
#

you may also want to use the UI Toolkit Samples

#

Window/UI Toolkit/Samples. Can be helpful to find things without making/using your own

fickle perch
#

hm, using what specifically?

rough scarab
#

Like, if I want to know what makes the hover color of the tree view (not sure what specific thing you're looking for, just using this as an example), I'd pull up the sample, and use the debugger to hunt it down

fickle perch
#

how do I get the hover state to stick?

#

although ig having them side by side helps me see regardless

#

unless I need my mouse

rough scarab
#

the picker causes the hover state in this case. Annoyingly while the debugger dynamically updates the Pseudo States field it doesn't do it for Matching Selectors 😦

hallow prawn
#

how do you remove the default click state on a button? It's changing the background color when i press it, and i don't want that. Is there any way to prevent that without creating custom uss classes?

lilac mortar
#

Is there a way to set up hotspots for cursors? Otherwise the functionality for cursors is completely useless, since the cursors are all offset...

rough scarab
lilac mortar
#

seems to work

still lantern
#

Not sure the best place to ask. I want to stop input from the new input system when clicking on a UITK element. Like, when I click on a button, I don't want my gameplay to also use the click.

stone pasture
#

Hey, anyone knows if there is a callback or an change event that happens when I'm using UIBuilder and edit a variable that has [UXMLAttribute] there?

lilac mortar
devout vine
#

How do i change the color of a ProgressBar using UI Builder?

#

i managed to do it

#

RightClick -> Add Seletor

On a greyed out element

rain wind
#

if i have a variable declared like

:root {
  --appui-sizing-800: 48px;```

how can I use/access this in a script? from documentation it sounded like it should be resolved via CustomStyleResolvedEvent but i think this is the wrong thing; i actually think this is the reverse of what i'm looking for

tldr: basically how do i do this `var(--appui-sizing-800)` from a style sheet but via code

[for anyone in the know, i'm trying to set sizing based off appui dynamic scaling. works fine from style sheet but i have a specific case i'd prefer to resolve via code]
rough scarab
rain wind
#

I just want to use appui variable sizes for width/height

rough scarab
#

Then I think you'll have to subscribe on the root element

rough scarab
#

@rain wind did that end up working?

rain wind
#

nope

#

CustomStyleResolvedEvent isn't even what i want, it's the wrong side of the equation

#

i don't want to add a custom style rule, i want to write a uss variable to an existing style (width/height)

#

iterating up the visual element tree looking at stylesheets i did find the uss variables on the root style sheet in the stylevariablecontext

#

all internal access of course

#

but no values associated

#

and at this point i realized this is becoming way too much effort and hacky

#

and just threw on a couple of line style sheet and moved on

#
.bl-vision-tab__texture {
    width: var(--appui-sizing-1050);
    height: var(--appui-sizing-1050);
}

.bl-vision-tab__index-button {
    width: var(--appui-sizing-500);
    height: var(--appui-sizing-320);
    padding: 0;
}

.bl-vision-tab__index-text {
    width: var(--appui-sizing-500);
    margin: 0;
    flex-grow: 1;
}```
lilac mortar
#

should i use controls like enumfield at runtime? it seems to work but it feels so janky, also dunno how to style it

dark blade
torn roost
#

Anyone know of a tutorial for runtime binding a ListView with data from multiple sources?

I.e each item in the list (custom component) gets data from list/array A and list/array B.

Specifically looking for information on how to set the dataSource / SetBinding.

viral coral
#

does anyone know how to make buttons switch pictures????

sick ice
#

Has anyone done a round progress bar in uitoolkit? Like going around clockwise

tidal lance
#

hello, anyone knows if ui toolkit suppor 2x resolution sprite automatic swap when combined with sprite atlas? We need to pack them due to performance reasons, but it looks like this functionality is not properly working unless directly specificed a sprite.

hallow prawn
#

Hello,

transition-animation on position doesnt seem to do anything? Is there any reason why this won't work in Unity 6 anymore?

rigid holly
#

hi! i'm trying to make a custom element using in c# for a custom inspector that needs 3 parameters from a script. I only managed to retrieve one of them by making the custom element a bindable element and putting the binding path in the UI inspector. Can please someone explain to me how i can add like another two of those editor binding path fields or a workaround to make a bind for the three elements?

lilac mortar
#

man this confuses me

#

unity says it cant parse the xml file if i use ui:Image

#

yet its in the docs

#

i guess it's engine:Image?
well, it seems like using visual element with a background is encouraged anyways

dark blade
rough scarab
lilac mortar
#

somehow in scrollview the scrollbar shows even when the content would fit

#

basically it takes the size of the content WITH the scrollbar being visible, not the size the content would have without the scrollbar

#

but only when the scrollbar is visible already

#

also when i have a scrollview in e.g. a window and the scrollbar is invisible. when i toggle my window, the scrollbar shows when making the window visible again, even though it wasn't before.

tough tusk
#

Is it expected the KeyDownEvent is not triggered for TextField element in runtime even though InputEvent and KeyUpEvent events are?

woven thicket
lilac mortar
#

makes sense

fiery mountain
#

how do you disable the drag reordering in a list view?

#

all the flags for reorder are disabled in the doc but it still does it

charred harbor
#

Is there carousel slider component available for UI toolkit? (free)

raven gyro
#

how do i change the ui:DropdownField background color (or any properties for the background)

not sure if this is the correct channel

merry schooner
#

I am currently trying to make a sidebar UI using a hexagonal layout, and I am currently using a script provided by uMathieu to read if the pixels the mouse is over are transparent. If they are, then clicking there won't do anything since it's not within the hexagon.

https://discussions.unity.com/t/clickable-area-of-a-button-for-non-rectangular-graphics/930850/5

My problem is that I am using Scale-To-Fit scale mode on these background images. It is not taking into account that the background image is scaled, and so it will read the pixels as if it were Stretch-To-Fit.

I don't see a way to get the amount the image is scaled by, any ideas on how to get around this?

#

Here is an example of one of the hexagonal buttons/background images

lilac mortar
cinder phoenix
#

Just noticed that when I hide my ingame menu, the buttons of the hidden UI are still interactable with my controller. What's the proper (intended) way of hiding the UI with UI toolkit?

broken dock
#

Hi Folks, is anyone aware of any tutorials for Unity 6 + UI Toolkit + Splitscreen? I can't seem to get a document to render for a specific split screen camera. Any ideas what I might be doing wrong? I've tried AI, but it keeps telling me nonsense 😉

cinder phoenix
broken dock
tough tusk
#

Is there a reason why a ListView that is not marked as resortable allow for clicking and dragging of items in that list view?

sonic shadow
#

Hi! What's the difference between binding property "Text" (red arrow) and Binding collapsable view at the top of the Inspector (yellow arrow)?

rough scarab
thick violet
#

How do i update this progress bar every time time changes?

[CustomPropertyDrawer(typeof(Stopwatch))]
public class StopwatchEditor : PropertyDrawer
{
    private SerializedProperty stopwatchProp;
    private SerializedProperty lengthProp;
    private SerializedProperty stateProp;
    
    public override VisualElement CreatePropertyGUI(SerializedProperty property)
    {
        stopwatchProp = property;
        lengthProp = property.FindPropertyRelative("length");
        stateProp = property.FindPropertyRelative("state");

        var root = new VisualElement();

        var header = new Label(ObjectNames.NicifyVariableName(property.name));
        root.Add(header);
        
        var infoBox = new Box();
        root.Add(infoBox);
        
        // Fix indents
        // TODO: There HAS to be a better way to do this
        header.style.paddingLeft = infoBox.style.paddingLeft; // Set to the default indent
        infoBox.style.marginLeft = EditorStyles.inspectorDefaultMargins.padding.left;
        
        var lengthField = new FloatField("Length");
        lengthField.Bind(lengthProp.serializedObject);
            
        var progressBar = new ProgressBar();
        progressBar.title = "Progress:";
        progressBar.lowValue = 0;
        progressBar.highValue = 1;
        progressBar.BindProperty(stopwatchProp.FindPropertyRelative("progress"));
        
        var stateField = new EnumField("State");
        stateField.Bind(stateProp.serializedObject);
        
        infoBox.Add(lengthField);
        infoBox.Add(progressBar);
        infoBox.Add(stateField);
        
        return root;
    }
}
#
[System.Serializable]
public struct Stopwatch
{
    public enum State
    {
        Idle,
        Counting,
        Finished
    }
    
    public float length;
    public float time;
    public State state;

    public float progress
    {
        get => time / length;
    }
    
    public void Start()
    {
        if (state == State.Counting)
        {
            Debug.LogWarning("Tried to start already-counting stopwatch");
            return;
        }

        time = 0;
        state = State.Counting;
    }
    
    public void Tick()
    {
        time += Time.deltaTime;
        if (time > length)
        {
            state = State.Finished;
        }
    }

    public float Progress()
    {
        return time / length;
    }
}
torn roost
#

https://docs.unity3d.com/6000.1/Documentation/Manual/UIE-runtime-binding-list-view.html
I'm trying to follow this, but my problem is with "Create the ListView item template in UI Builder". I'm using a C# custom control, and
https://docs.unity3d.com/6000.1/Documentation/Manual/UIE-create-bindable-custom-control.html
Works with inheriting from an already bind-able control, instead of showing how to make one by inheriting from Bindable Element

Anyone got any advice on making a custom element inheriting directly from bindable element?

lilac mortar
#

Anybody knows a way to make scrolling over an UI element block the scroll event to reach game input? (which would be zooming)

tough tusk
#

Does anyone know why when I have a ListView with Reorderable unchecked, I can still click and drag to reorder the items?

lilac mortar
tough tusk
brave anvil
#

Hello!
Im making an scrollable level map and I need my items in horizontal layout group be in different positions.
How should I do that??

brave anvil
#

Got it!!
I need layout element!

broken dock
#

Hi Folks, has anyone managed to get UI Toolkit to work with local multiplayer?

#

(i.e. splitscreen)

broken dock
#

I can't seem to get 2 documents to render on 2 different cameras at the same time

#

Do I have to render to RenderTexture? If so how does input interaction work?

rough scarab
#

Ah, does it care about the clipping rect?

broken dock
#

It just renders across both viewports

rough scarab
#

That's exactly what I would expect

broken dock
#

I'd like it to care about the camera 😂

rough scarab
#

Well, that's not how it works, so you'll have to divide the screen manually

broken dock
#

Ok, cool. Just checking I wasn't missing something

#

Is it possible to nest a document? Should I make a custom control and have have 4 instances of them in the document?

#

Where the custom control is essentially a full player menu

#

Thanks for your help BTW

rough scarab
broken dock
fickle perch
#

uuh how do I make a unity-inspector-like property gui with visual elements for a float field?

#

I know I could construct it myself with a label and a field and all that but it wouldn't match the layout etc etc

#

is there a shortcut?

#

oh I guess Toggle has a label field

#

context is I have an EditorWindow and I want to persist data between sessions

#

and I figured a ScriptableSingleton would be the way to do that these days?

#

also, I couldn't get ScriptableSingleton to cooperate with SerializedProperty, which might be related to the fact that those singletons have a hide flag set to don't save? (by design, by unity)

#

idk just feels like this should be straightforward and I'm doing something wrong lol

#

like yeah I could do it with EditorPrefs and writing my own controls and manually calling save on change detect but I shouldn't have to right?

woven thicket
fickle perch
#

oh, I did solve it eventually, it looks like the issue was related to serialization quirks with scriptableSingletons and legacy GUI input fields

#

I used the uitk property fields and it worked fine

#

ended up doing this

rough scarab
#

ScriptableSingleton and SerializedProperty have worked as expected for me in the past

#

If you were seeing everything as readonly you do have to do some nonsense to fix that

#

It's odd to me that you're doing SP logic but with reflection 😛

fickle perch
#

iirc there were some quirks around that

#

ok you know what it's not actually working

#

why did it seem to work earlier ;-;

#

okay I must be doing something wrong

#

ah it was just that the SerializedPropertyChangeEvent didn't bubble up

#

now it works henlo

tribal elk
#

hello i need help,, i want to have a text input field element that you can 'click out of' which disables it

i cant figure out how to do this because when i use the BlurEvent it occurs before the navigation submit event, so no submit is ever detected in my code?

also is there any way of avoiding keys being entered on the frame that it becomes enabled? eg press T to open text chat shouldnt type T into the chat, maybe a delay to when its enabled?

tribal elk
#

hello anyone able to help with ^ ?

#

basically i want a text input field that you can turn on and then type into but disables when you click out / loose focus on it OR submit the text (should be able to tell if you submit the text and do something with it)

#

i have spent days

#

i am wondering why is it that pressing ENTER on a text input field causes it to have a BlurEvent called on it

kind whale
#

So does the UIToolkit/UIElements List-View rebuild the list everytime an item is selected?

If so is this why transitions dont seem to work when selecting? It seems having events such as hover events even in the select state, wont fire until I re-hover the mouse. So are transition states not retained when the list-view rebuilds?

If that is also true then how can I go about animating my selections for the list-view?

kind whale
#

oh yeah lol

#

ur the one who reported it was reported my bad lol

tribal elk
kind whale
sudden steeple
#

how can I add a game object reference or a variable reference to this?

sudden steeple
#

sorry for the bad English, Is there a ui element I can add to the node that allows adding a gameobject or variable or script reference (Im using the experimental graph api)

vital totem
#

How to set binding in column and cell?For above list?

rough scarab
#

It's just a standard editor control, nothing to do with graph view

limpid grove
#

Hey, I am looking for info how to control UI toolkit with keyboard. I need to use arrows/wasd to navigate through UI and submit with enter etc. I found info that UI Toolkit is natively working with New Input system but how I specify what buttons do what?

tulip sundial
#

Have a look at your Event System object -- it should have an "Input System UI Input Module" component on it

#

It references an input action asset.

#

It should already be working, though -- you're just looking for WASD/arrow navigation, right?

clever crest
#

Hi, I am trying to instantiate a scriptable object after creating the so script.
Issue is, the script tries to create this SO instance before assets have been reloaded which results in it trying to create a non existent SO, as seen in the picture.
Here's the chunk of code reliable for creating the SO script: https://github.com/nnra6864/Nisualizer/blob/12372516f89124f08feb296ee161898a6985230d/Nisualizer/Assets/Scripts/SceneCreator/Editor/SceneCreator.cs#L62.
And here's the chunk of code tasked with instantiating that SO: https://github.com/nnra6864/Nisualizer/blob/12372516f89124f08feb296ee161898a6985230d/Nisualizer/Assets/Scripts/SceneCreator/Editor/SceneCreator.cs#L147
I would really appreciate somebody helping me with this, thanks in advance!

clever crest
#

please @ me if you are able to help

fickle perch
#

does it compile scripts in between? if not you might want to run
CompilationPipeline.RequestScriptCompilation() or so

#

@clever crest

clever crest
#

Welp, that might not even be the issue actually, I tried this CompilationPipeline.compilationFinished += x => CreateConfigDataSO(sceneName, sceneDir); and am still getting that same error.
Will try to figure this one out a bit later, thanks anyways!

fickle perch
#

does anyone know if it's possible to replace element types in the UI builder?

#

I often prototype with VisualElements, and style them, and then I sometimes want to replace them with a custom element

#

but I couldn't find a nice way to replace them and no nice way to copy over inline styles, and editing the uxml tag by hand, replacing VisualElement with my own custom element, also didn't seem to work, it kept saying the type was missing some uxml attributes

#

and so I have to like recreate an identical object, just starting with the custom element type, feels kinda silly

lean barn
fickle perch
#

I did, and it got me compiler errors

lean barn
#

And copy past the inline style to the ucss file

fickle perch
#

saying something about attributes missing tags

lean barn
fickle perch
#

ah, that I didn't do!

#

really wish there was a way to do it in the UI builder, it's a little clunky to do manual edits

lean barn
fickle perch
#

yeah :c

#

oh, so, I have another question

#

is there some way to jump into the rendering pipeline of uitk UI and queue up a command buffer?

#

so I'm making a tool right now, and I want to only render the viewport when I have to, ie: on input/ui interaction/etc.

#

and there's two issues at the moment

#

one is that, it seems like unity repaints UI aggressively even when nothing is changing, which I'm not entirely sure why

#

the second is that I want to be able to use the frame debugger, but it's uh, a little hard, when my rendering isn't part of any "frame", it only shows the UI rendering

#

right now my workaround is to just re-render everything in Update() but it feels hacky and heavy handed, and I can't ship with that

lean barn
#

No idea, you can't do anything shadery with uitookit for now (unless using render texture), but your issue is more an editor bug related no?

fickle perch
#

I don't think it's a bug for the frame debugger

#

I think it's just that my command buffer only renders on demand, and the UI renders more often, and it just draws the RT in the UI, so I can't actually debug the command buffer unless I also make that dispatch on every UI redraw

#

the UI updating even though nothing changes I think happens in builds too though, but maybe that's just because I had the frame debugger attached in a dev build?

lean barn
#

I don't no if any Unity UItoolkit developers are watching this discord

fickle perch
#

I'll have to investigate a little more! it could also just be my fault c:

lean barn
#

Welcome to UIToolkit where you never know if it's by design or your fault because everything is fresh and new

#

And I hope you will never try with a webgl build it's even wilder

fickle perch
#

it also doesn't help that I'm doing something kinda wonky on top of that

lean barn
fickle perch
#

oh this is all runtime!

#

not editor

lean barn
fickle perch
#

it's for half-edge, my 3D modeling tool!

#

look, runtime! a build! so to speak

lean barn
#

I know you always work on tools, that where the confusion comes from

fickle perch
#

yeah, it's pretty confusing to work on ngl~ especially when I'm starting to recreate GameObjects and transforms and a hierarchy and an asset manager and an undo system

#

but most of it is up and running! mostly missing frontend things for like, renaming objects and drag/drop for editing the hierarchy, that kind of stuff

lean barn
#

Also Unity introduced a Reducer like state manager in their App UI package that pretty much work like web redux

fickle perch
#

hm I don't think i've used bindings much yet

#

I know I have but I don't know if I've kept any

lean barn
#

It's pretty neat because you can use custom classes or even scriptable objects and the UI will keep in sync with the values without having to do anything manually

fickle perch
#

the trickiest one I've run into so far is the tree view, dealing with binding there, while also retaining the data structures I want for json serialization, is a bit of a wonky situation rn

#

because then I don't have the same data type on both ends

#

looks like converters might be solving for that? maybe

#

although it's structural in this case, hmm

lean barn
#

Yup converters are great if you only need to adapt the data structure to be displayed the way you want

#

And everywhere else in your code you can keep it the way you like

fickle perch
#

in this case I have a

class Thing(){
  List<Thing> children;
}``` type of structure
#

and the TreeView API was a little convoluted

#

I have a working solution but it's pretty brute force, you need to like, interleave TreeViewItemData types I think?

#

but that's pretty much what the docs do here, just convert it to a List<TreeViewItemData<Thing>> on demand

#

just feels a little, not allocation friendly!

lean barn
rough scarab
#

UI Builder produces really ugly UXML so I do understand why it feels like that though

clever crest
#

What's the proper way to set window titles via ui toolkit?
I did this:

        [MenuItem("Assets/Create/Nisualizer Scene", false, -202)]
        public static void ShowSceneCreator()
        {
            ResetEditorData();
            
            var wnd = GetWindow<NisualizerSceneCreator>();
            wnd.titleContent = new("Nisualizer Scene Creator");
        }

Yet the window title is still sometimes unset, as can be seen in the picture.
I reported a similar bug that's been fixed recently(for tooltips tho), but idk how to do it with ui toolkit windows.
https://issuetracker.unity3d.com/issues/linux-tooltips-have-an-unset-title-which-causes-the-inability-to-modify-tooltip-behavior-on-window-managers

#

This is really inconsistent and I can't easily replicate it, was just wondering if there is some other way to set titles, just to make sure it's all properly set up.

dark blade
rough scarab
#

Pinged the wrong person

dark blade
#

ehh sorry

clever crest
limpid grove
limpid grove
#

@tulip sundial Ok I was monkey, thanks for help

limpid grove
#

Ok, I am confused a bit. I recently discovered UI Toolkit sample from Unity "Unity Royale", and started to rework my UI toolkit to what they did becasue in my head it's much better solution than I had. I was having multiple ui documents and controllers instead of having script inside of ui builder etc. Only one thing that's annoying to me is that in constructor they register callback to GeometryChangeEvent with something like Init method and then unregister it. For me if I do this some UI part looses reference and if I don't do null propagator it sends errors, but If I do null propagator then click events aren't registered.
My question is why they did it in GeometryChangeEvent, and if there is better way of doing it?

#

PS. Unitys' example doesn't work for me anyway

#

If there is any doc about initialization runtime UI I would love to see it coz I had to miss it.

hard pewter
#

Is there any sort of escape character in uss so ":" isnt treatet as a pseudo class selector? Im writing custom editor and auto generated names for property fields contain ":" which is problematic a bit

rough scarab
dark blade
hard pewter
#

Yeah, eventually I had to do it in C#. Not big of a deal, just wondered if it was possible. Btw this marks important reason why not to include colons in names, so giving that default editor does it seems like a little oversight from Unity team

misty rampart
#

what might be the reason this label's transform isnt working when its text changes via binding?

#

shouldnt the binding changing the text also update the bounding box?

misty rampart
#

is there a way to force a refresh as a band aid fix?

misty rampart
#

if i move around the visual element every frame via

            _interactableText.style.left = new (new Length(_interactableText.style.left.value.value + 1 * Time.deltaTime, LengthUnit.Percent));

you can see it does update the layout but with a one frame delay(?)

vital totem
misty rampart
vital totem
#

oh

fickle perch
#

is there a version of GenericDropdownMenu that supports nesting? like, multiple levels deep of menu items

#

(in builds, not editor)

misty rampart
#

phew okay

        private void OnEnable()
        {
            _interactableText.RegisterValueChangedCallback(OnInteractableTextValueChanged);
        }

        private void OnInteractableTextValueChanged(ChangeEvent<string> evt)
        {
            VisualElement v = (VisualElement)evt.target;
            VisualElement parent = v.parent;
            parent.Remove(v);
            parent.Add(v);
        }
#

so you can force the translation to update by just removing it and adding it again

#

(dont do this in a geometry changed event because it will go into an infinite loop)

dark maple
#

How can i achieve this effect in UI Toolkit

#

In normal UI, I used to do this by applying mask to text and adding image as a child. But in UI Toolkit, it's just not happening, the overflow thing doesn't work, if I keep the image as a child, it just overlaps the text. The text is relative and the image is absolute position.

hexed heron
#

where can I read more about these properties?

rough scarab
#

It's how the UXML is serialised after it's imported, and it's irrelevant to using it

hexed heron
#

I don't "need to" per se. But the Template, Slots, etc sort of reminded me of web frontend frameworks (angular/vue/react).
Figured I would read more and see what that's all about

rough scarab
#

It's intended for the UIDocument and Unity's internal code, and no-one else

hexed heron
#

okay

#

thanks

tame vessel
#

Does UI Toolkit support particle effects and shaders yet?

wispy kernel
#

how do i align that to the bottom, been touching all the settings and it doesnt movee

rough scarab
rough scarab
#

I don't use UI Builder, but it may be that you can configure the same thing without an extra element by selecting the UXML root element in the hierarchy. But I'm not sure if they expose settings there

wispy kernel
#

how can i move freely the items? im new to this, there getting stuck to a specific alignment

rough scarab
#

If you want to ignore layout entirely you use absolute positioning

wispy kernel
rough scarab
#

have you gone through any tutorials or are you just trying to wing it based on prior UGUI knowledge? Because you should really look at some resources

wispy kernel
#

and it loooooks easy to manage, like a css and html buut im getting lost on all the menus and options

rough scarab
#

Parents control the layout of children, so create a parent to manage them, and set its align and justify settings until the children work how you expect

#

then if you want to position that element, create a parent for it and do the same

#

the top level parent is generally absolute positioned to be anchored either to the full screen as I previously mentioned

absolute with top, bottom, left, right as 0
or with some other anchoring to set it only to the bottom

tulip sundial
#

you'd still be looking for an equivalent of its HorizontalLayoutGroup

rough scarab
#

What do you mean? The equivalent is just baked in as flex

tulip sundial
#

Right

#

instead of absolute positioning

rough scarab
#

there is no need to look for anything, as layout comes by default

frail wigeon
#

Hi all
If i make a serializable class, is there a way in ui toolkit to just render all the fields?
Like how a default inspector would do? It even comes with a dropdown to expand/collapse the class content?

rough scarab
#

At runtime you would have to use runtime binding, which I've not used personally but it's got a large section in the docs

hexed heron
#

do UI toolkit elements auto-unregister events/callbacks when they are disposed?

lilac mortar
#

if e.g. a button owns a delegate, ofc when it's deleted the delegate (list of registered functions to call) also gets deleted

#

if it doesn't exist, it can't invoke an event

royal palm
#

When I Register a Callback to a Button and then Disable the GameObject with the UI Document and Enable it again the Callback does not work anymore. So does it automatically unregister all Callbacks and events ? And if so how would I Disable / Hide a lets say Menu without having to re Register all Callbacks every Time I open the menu ?

hexed heron
# lilac mortar what do you mean? they dont even register anything

I mean about registering callbacks to buttons/toggles/etc.
Then dispose of the UIDocument (assume no pooling).

Does it automatically unregister those callback/delegate references?
Especially if they aren't lambda/inner functions. I'm just curious if there is some sort of references keeping stuff in memory.

lilac mortar
# hexed heron I mean about registering callbacks to buttons/toggles/etc. Then dispose of the U...

think of a button keeping a list of functions to call on click. if the button gets destroyed it means the list gets destroyed. so it's gone.
only time you need to care, is when you have e.g. a class "Thing" and myThing registers its function "DoSomething" to a button click, but myThing gets destroyed. then the button will try to call myThing.DoSomething() even though it doesn't exist anymore.

#

so you need to UnregisterCallback(DoSomething) when myThing gets destroyed

#

when you register a callback, you basically just add a function reference to a list (which is what a delegate/event is)
and the button owns that list. so ofc when it gets deleted, then a) the list also gets deleted b) it can't even invoke the event anymore, because it doesn't even exist

hexed heron
hasty parcel
#

Is UI Toolkit good yet?
2 years ago we tried to port to it, but the toolset was too limited. We're running U6 now and curious if its developed enough yet. Our biggest issue was how hard it was to make UI elements seamlessly translate to in game objects. Think dragging and dropping objects into the world.
Also it was awful to render in-game objects ontop of UI Toolkit ui.

cerulean gyro
#

Hello !
I'm trying to create a UI that consist on recursive SplitView. I'm using AppUI package and I found an issue that looks common but I can't find any solution to fix it.
The issue is that the splitview orientation is controlled by a USS selector. If I have a horizontal Splitview that is child of a Vertical SplitView the selector inheritence result in a splitview that has both horizontal and vertical selector, which break the system.
Is there any way to prevent a selector to apply or to constraint the inheritence to prevent this situation ?
As you can see in the screenshot, the contentContainer match both vertical and horizontal selector

noble badge
#

just like this

sudden steeple
#

How can I make a Serialized reference with the UIToolkit

rough scarab
# noble badge

Style an element at the root so they take up the space you want them to

#

style it via code

lament gull
#

Do buttons have USS substyles for when they are being selected by a gamepad, similar to how the hover and active sub-styles?

leaden flame
#

Hey all, i wanted to ask whats the go to way to navigate between different menus and stuff? I have considered making each menu its own ui document and enabling/disabling them via scripts, but i dont know if there is another way

patent anvil
#

Is it possible to select/focus different visual elements at the same time using the default UI input action map and the UIInputSystemModule?

#

I would like my settings menu to be tabbed at the top, and for controller support I’d like to be able to navigate the tabs using the bumpers, and then navigate the page using the joystick or d-pad

lament gull
lament gull
lilac mortar
#

i set my cursor based on raycasts (if hitobject != lasthitobject -> set cursor) and check if the mouse is over the ui every frame
problem is, when mouse is over ui, i set my cursor back to default. if i immediately hover an ui element though, that has a cursor assigned, it'll override the cursor.
so e.g. a button with a hand cursor will be set back to default cursor.

#

not sure what would be a good solution for this

tulip sundial
#

sounds like you shouldn't set the cursor to default, but whatever the currently-hovered UI would want

lilac mortar
#

found a hacky solution. just giving ui elements a class name "cursor" and when i check if mouse hovers ui, i also pick the element at mousepos and check if they contain a classname "cursor".
and if so, i know the element has a cursor, so i dont set it back manually.

primal wyvern
#

can someone help me my ui toolkit is only showing ui document
and its frusturating

#

I mean it only shows ui toolkit and not the ui tab

#

like the ui tab is not therre

rough scarab
autumn chasm
#

Hello. Do you know how to build a tree list in the UI Toolkit?
I can't drag and drop anything into TreeView.

rocky root
autumn chasm
#

I did exactly that and then it's detached (it's outside the TreeView)

rocky root
#

oh you meant INSIDE tree view, yeah pretty sure its by design lol

#

you know what tree view is right?

autumn chasm
#

sure, this is what I want

#

I jsut can't put anything in TreeView so how can I work with it?

rocky root
#

did you open the inspector for it, you will see all the options

autumn chasm
#

yeah thanks

#

I will do it code

#

should be easier

rocky root
#

sure that works too.

autumn chasm
#

it's crazy that I need some unknown data source instead of adding labels and other things to the tree

rocky root
pseudo shard
#

Hi I am trying to use the TextMeshPro function isTextOverflowing but it keeps on giving me false when my text is obviously overflowing. Does anybody know why?

rough scarab
pseudo shard
#

oh mb will post it there

grizzled bluff
#

Greetings!

I have been trying to insert sprites into a label for the purposes of showing the player a corresponding input to press.
I have thus far:

  • Created a system that parses input system actions and correlates them into sprites
  • Created a ui manager that updates the ui document depending on the context of the game.
  • Create sprite assets for each corresponding sprite represending a button on the keyboard
  • Created a UITK Text Setting to set the paths of the sprites folder
  • Made sure that the label element has the rich text setting enabled

The problem that i am having is that the rich text tag is not working:

grizzled bluff
#

Bump

still quarry
#

I still can't figure it out

hasty parcel
#

Wait. Is there really not even an Image element yet (I know there's background image, but its severely limited)?
If I want to rotate an image but still have the element fit 100% width/height within the parent, the only solution right now is to rotate the element itself, but if it applies the width and height before the rotation because its on the parent, not the image..

hexed heron
#

How can I select the first element of a listView after binding?

protected override void Show()
{
    var interactions = ParentElement.userData as List<Interaction>;
    _listView.itemsSource = interactions;
    _listView.Rebuild();
    //simply changes the display from none to flex
    base.Show();
    ParentElement.RegisterCallback<GeometryChangedEvent>(FocusOnFirstChild);
}

private void FocusOnFirstChild(GeometryChangedEvent _)
{
    var contentContainer = _listView.Q(className:"unity-scroll-view__content-container");
    //the content container is created and has the children, but for some reason, Focus is not working
    contentContainer[1].Focus();
    ParentElement.UnregisterCallback<GeometryChangedEvent>(FocusOnFirstChild);
}

The menu shows without any element focused but if I move the arrows, they start getting focused (as seen in the second image).
How can I focus an element through code?

tame vessel
#

Is it possible to create a tooltip that holds data which follows the mouse as I hover around in a box?

odd tapir
#

sure

lusty dagger
#

hey! is there a way i can hyperlink some text in a label through code

tame vessel
#

Should I use one or multiple UI Documents?

lusty dagger
lusty dagger
rough scarab
#

what Unity version are you using?

lusty dagger
#

6000.29f1

#

ohh wait you have to do ctrl click

rough scarab
#

I don't have to on my end

lusty dagger
#

hm is it bcs i'm in editor?

rough scarab
#

I am in editor

#

I presume there's a setting somewhere

lusty dagger
#

gonna try setting it as selectable

hasty parcel
#

I see that there still isn't z position support. So if I have, say, a hand of cards and their order is dependent on hierarchy order, how would I render the :hover card over it's siblings without changing the order of the cards?

rough scarab
#

You would change the order of the cards

oblique oxide
#

whaaat there is no z-index?

#

oh well

tame vessel
#

Is it normal for the UI to stay when unloading an additive scene or did I do something wrong?

rough scarab
#

You either haven't unloaded the UI, or you've unloaded all rendering cameras

clever crest
#

Hey, I've been using this to get a system font for tmp and I was wondering if it's possible to do the same for the ui toolkit label for example.
If not, are there any plans to support stuff like this in the future?

#

Thanks in advance and please @ me when replying.

bitter adder
#

rich text not working in Label when using <a href="script path" line="11">Text</a> what could be wrong. link text is showing correctly but not opening the script at given path like console window does

broken dock
#

HI Folks, I'm trying to get UI toolkit to work in split screen. I've got 4 UI documents with separate panelSettings in each. Is there a way to restrict the NavigationMoveEvents to a particular panel / document? The navigation is moving between players' menus?

broken dock
#
NavigationMoveEvent navigationEvent = NavigationMoveEvent.GetPooled(TranslateDirection(direction));
uiDocument.rootVisualElement.SendEvent(navigationEvent);
#

I thought this would restrict it, but no luck

hasty parcel
#

I'm adding an element via code, then immediatly adding a class that should make it animate. I found that this doesn't work. It instantly adds the class without considering the base-css, so its instantly at the end of the animation. I tried adding the class in a scheduled delay of 1ms and that appears to work, but on faster computers, it fails every so often and looks choppy. I upped it to waiting for 5ms, but now this is screaming "bad solution". Am I doing something wrong here?

#

Is there some way to make "lock in" the base css so when I instantly add the animation class it will go through the animation?

tame vessel
#

Can UI toolkit handle multiple UI documents at the same time? I seem to have problems registering clicks on my elements, not sure if that is the cause

#

Even if I have only one element active it doesn't register my clicks anymore, this worked before... really odd

rough scarab
#

But it's unclear it'll be handled how you want it to

rough scarab
# clever crest bump

It's unclear to me what you want exactly, why wouldn't you just be able to do the same thing but with FontAsset? They're almost identical

clever crest
rough scarab
#

But I'm not at my computer to check, and would also prefer USS to style

tame vessel
#

I'm trying to make a simple debug cosole come down from the top when I hit a key, how would I animate this? So it slides down to half of the screen?

tame vessel
#

Also what is up with these docs. it claims you need className, but name: works in a query?

hybrid crystal
hybrid crystal
tame vessel
#

The docs say you need Q.(className: foo) when you can use name:

#

Like its some kind of disgusting React component we are working with

hybrid crystal
#

you use className when you have to apply specific styles to an element

tame vessel
#

I know, but the docs use it

#

I use name: foo

hybrid crystal
#

you can just ignore it completely if you don't need it

tame vessel
#

It's mandatory when you need to lookup name="foobar"

hybrid crystal
#

Can you give a little bit more of context

tame vessel
#

Yeah you are missing the point 😄

hybrid crystal
tame vessel
#

When you need to query for elements with name="foobar"

hybrid crystal
#

element.Q("name");

#

both parameters are optional

oblique oxide
#

hello, i have an interesting problem, on an android emulator, my UI sliders seem to be visually broken while in webgl and unity editor play mode the slider appears properly.

the funny thing is, the sliders still work correctly in the emulator, but I would like to know how to address this, but I honestly have no idea how to fix this

oblique oxide
#

ok it could be the problem with the emulator, I tried the same apk on a physical device and the sliders work perfectly

dark jewel
#

are there any good resources/tutorials on creating custom elements?

#

I've checked pins but nothing looks like it quite covers that topic thoroughly

dark blade
dark jewel
#

😦

dark jewel
# dark blade not really bro, at least for me...i need to make and check, sometime its hidden ...

while a lot of what it covers is brief, I found this https://www.youtube.com/watch?v=6DcwHPxCE54
video covers a lot of the basics pretty well and it's all shown in one example rather than the scattered guides I've found around

In this video, we'll look at some of the new features added to the UI Toolkit package in Unity 2023.2 and how it's now at a point where it's much easier to work with when building UI for runtime.

To demonstrate this, we'll look at how can build out a functional main menu, how to write and expose custom UI components in code and how we can bi...

▶ Play video
oblique oxide
broken dock
#

Split screen menus seem very difficult to get working with UI toolkit, hopefully Unity will add a simple way to limit events or input to a single Camera or UI Document or Panel

tame vessel
#

God the UI builder sucks. I add a USS style to the document and it instantly breaks

#

What even is this error? ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index

#

It should warn on what line in the USS is incorrect instead of completely dying

oblique oxide
#

I have found little success using the ui builder for anything beyond checking how element hierarchies react to different layouts, I think it's much more powerful and intuitive when you build it purely with code

rough scarab
#

I agree, it has a lot of potential but even without the bugs it's way easier to make an unmaintainable mess

#

There are a bunch of things that UXML does poorly but the UI Builder makes easy, but in those cases I prefer avoiding the UXML and going straight to C#. It's a bit of a learning curve figuring out what's best though!

dark jewel
# oblique oxide What kind of elements

Kind of all aspects? From basic to advanced. For example one of the more basic things I want to make is like a menu bar that I can specify what the items are(label + icon) and allow dividers. Something more advanced I want to do is a custom render visual element with 8 border colors instead of 4(two colors in each direction), which I believe would be using painter2d

oblique oxide
#

This screenshot is from the android emulator so the slider is bugged, but on a real device it looks fine

#

The second one I don't exactly understand

#

I would need a visual example

oblique oxide
#

I have very strong opinions on this 😄

#

My philosophy on avoiding the UI builder for actual UI building is that:

  1. it's a genuine hassle
  2. you essentially always make the UI anew between different "screens"
  3. you will still have to code but now you have to use these terrible find via string literal from the uxml methods and that in my opinion is a complete disaster of an approach
regal bramble
#

Hello 😄

I created a Toggle in a UIDocument, but nothing happens when I click on the checkbox. Did I miss something ? Ty ^^

thorny onyx
#

anyone ever have an issue with Dropdowns scrolling hyper fast by themselves until I open them and hit an arrow key?

#

it's like there's a rogue controller plugged in but I even put the project on a laptop with nothing connected and it still does it.

#

it's JUST dropdowns, no other application or anything else in unity does it

#

I click the dropdown and it'll scroll through the list super fast and sometimes close itself

tame vessel
#

How can I have multiple UI Documents, they are overlapping so I can't catch MouseEnterEvents on the elements. Can I resize a UI Document to only take a certain portion of the screen? I have "Match Game View" enabled on all of them, and if I disable it and change canvas size I see no option to tell my UI Document to be for example in the center and the bottom of the viewport

clever crest
#

Hey, I tried to add a UI Document to my scene and it works fine when in the editor, but if I try to load the scene, it just straight up crashes.
Am I doing something wrong?

#

By load the scene, I mean in the build, not the editor.

rough scarab
#

If it crashes then look at the log

clever crest
#

yeah, I have no clue what to think of this, windows build works fine too

rough scarab
#

Yeah no idea, some linux segfault

tame vessel
#

Can you achieve Heartstone animations and effects using UI Toolkit?

scenic brook
tame vessel
#

@scenic brookCan you lead me to the rabbit hole? Is it RenderTextures?

scenic brook
# tame vessel <@313011730525585415>Can you lead me to the rabbit hole? Is it RenderTextures?

Here is a video that briefly shows how to attach UI Toolkit assets to a world gameobjects:
https://www.youtube.com/watch?v=gXx_j-6z8jY
I haven't tested this feature, so I don't know what drawbacks it has. When I worked with regular GUI, I had mostly issues with materials, so it's probably worth checking out how they work here (e.g. if they interact with lighting).

In this video, we show how to use Unity's new UI Framework UI Toolkit in World Space.
This video assumes some knowledge of UI Toolkit. If this is your first encounter with UI Toolkit, check out what it is here:
https://youtu.be/yUXFHAOXhcA

If you want a deep dive check out our 20+ hours course on UI Toolkit:
https://youtu.be/JjIznsCcHMo

or dir...

▶ Play video
civic fiber
#

Generally speaking, is it more performant to use vector graphics or atlased sprites?

feral onyx
civic fiber
feral onyx
#

i.e. the mesh/vector drawing APIs?

#

or icons, styling and text you add to existing widgets?

civic fiber
#

I do intend to use the vector drawing API for some aspects at some point but for now I'm talking about for icons

feral onyx
#

i would expect that all vector icons will be converted into a SDF sprite sheet anyway, rasterizing curves or even complex poly-meshes is too expensive at runtime.

#

but maybe not, its a retained mode renderer after all, so it doesn't actually matter? maybe?

civic fiber
#

Time to whack it in the frame debugger and find out

unborn bluff
#

I was wondering if anyone could help me with this image problem I have been having in multiple projects of mine? where even though the image is way bigger than the canvas it still shows partially what the camera sees (The yellow)

rough scarab
dark jewel
#

if I am doing custom drawing in OnGenerateVisualContent in my custom element, is there a way to disable default paint methods like the border? I want to draw my own border in a specific way, but I also want to use properties from the uss like border width and colors so I didn't want to hide them via the style sheet. And since it looks like OnGenerateVisualContent is only effecting the content area(or it cannot draw over default borders) I'd need to somehow disable them

rough scarab
#

Iirc you can draw outside of the area just fine as long as overflow isn't set to hidden

tame vessel
#

When I press tab inside a TextField it loses focus, how can I prevent this? evt.StopPropagation seems to do nothing

#

Also tried to return, but doesn't stop it

thorny onyx
#

why does my main style sheet sometimes get stuck importing and delete itself? I've learned to make a backup now but my whole style sheet getting yeeted is kind of annoying. It didn't specify what was wrong with it, I just changed a value in the UI Toolkit inspector and saved and it broke both times.

brave nest
#

hi idk if this is the right category but i made a normal unity slider in a canvas but i can't slode it while in runtime (only thing that works Ais changing the value in properties)

Fixed: #🧰┃ui-toolkit message

ornate cliff
brave nest
#

i think that's it creating a new event system via create > UI > event system in hiearchy fixed it

tame vessel
#

I made a custom editor in Unity, why is my font pixelated? It's not sharp like the rest of the editor:

viscid ether
#

Is there a option to have the values inside my IntegerFields, UnasingedIntegerFields and FloatFields be separated by thousands? Or do i need to do it manually? Is doing it through a converter a good solution?

clever crest
#

Hi, is it possible to load uxml/uss from a system paths instead of having to have them included in the game build?
I found a few forum posts asking the same thing with disappointing answers, mostly due to the fact unity does some weird stuff where it links things with assets or something.
I don't need any of that tho, I literally just need to load uxml and uss from files and it'll mostly be used for text etc., not images and all the other stuff you'd find in the build.
This seems like a really dumb limitation, especially considering for how much modding it'd allow.
I've seen an answer suggesting asset bundles, but that just seems like such an unnecessary complication because not everyone has/can run unity.
I am making a music visualizer and just want people to be able to define the ui via text files that I load at runtime.

rough scarab
clever crest
#

Thanks for the answer, really wish this was a thing because I don't see a reason for it to be impossible butt sure.

dark jewel
dark blade
lone lark
#

Sorry if this is a dumb question, I'm trying to make a button's click area match the image.
I've seen a way using Image.alphaHitTestMinimumThreshold via a monobehavior on a normal unity UI button, but I'm not sure how to replicate that on a unity UIElement button.

weak fog
#

How can I reference a VisualTreeAsset from a custom BindableElement? Since it's for runtime UI it also needs to be included in build

vital totem
#

[field :SerializeField] public string Name { get; set; }
how to bind this property to label/textfield.value?

vital totem
#

do you how to bind gett set properties?

round tree
#

Is the UI-Toolkit an extern download ? Or where do I activate it ?

cold urchin
vital totem
rough scarab
#

I presume it's the same path you'd use for runtime

limpid grove
grim ferry
#

in ui tool kit how to define space between lables in a absolute visual element?

rough scarab
dark jewel
#

Does the Button element not support text overflow? I'm using Unity 6.000.0.31f and when I try to add a button the text label refuses to ellipse, while all the other text modifieres(like align, wrap, style etc...) work

bronze iron
#

Is there a real quick way of making dashed lines in UI toolkit? On the latest Unity 6

patent anvil
#

Anyone have any suggestions on how to play a sound on button hover and click?

tall owl
#

Hi friends, has anyone had success using sprite tags in UI Toolkit labels in Unity 6? Despite having the glyphs setup in a UITK settings and having that assigned to the config I am using, I am just seeing the text <sprite=1> instead of my sprite.

tall owl
#
using UnityEngine;
using UnityEngine.UIElements;

namespace UI
{
    public class ButtonSound : MonoBehaviour
    {
        public UIDocument uiDocument;
        public AudioClip hoverSound;
        public AudioClip clickSound;
        public AudioSource audioSource;
        
        public void Start()
        {
            if (uiDocument == null)
            {
                uiDocument = GetComponent<UIDocument>();
            }
            
            if (audioSource == null)
            {
                audioSource = FindFirstObjectByType<AudioSource>();
            }
            
            if (audioSource == null || uiDocument == null)
            {
                return;
            }
            
            var buttons = uiDocument.rootVisualElement.Query<Button>().ToList();
            foreach (var b in buttons)
            {
                b.RegisterCallback<MouseOverEvent>(_ =>
                {
                    audioSource.PlayOneShot(hoverSound);
                });
                
                b.RegisterCallback<ClickEvent>(_ =>
                {
                    audioSource.PlayOneShot(clickSound);
                });
            }
        }
    }
}```
#

I just attach this to my UI document GO

patent anvil
#

Thank you @tall owl !

#

I was thinking of doing it like this or maybe creating a custom element called AudibleButton that registers the callbacks

tall owl
#

Yeah, it's unfortunate having to write essentially a custom script to do this, but it's the only way I found.

tall owl
#

That's what I'm seein

#

OK I changed nothing and now it works. It's a christmas miracle

#

I don't understand it, but I ain't gonna complain about it

bronze iron
#

How do I share a uss variable between multiple stylesheets?

rough scarab
#

doesn't matter what sheet it was declared in

dark vault
#

I recently came to an understanding and i was wondering if anyone could correct me:

basically if i use ui toolkit for hp bar, ill have to handle position of those bars in respect to enemies

if i use gui, ill have to handle rotation
which sounds better & easier.

also if something isn't related to world-space like inventory, menu, static ui in game to display currency, my hp, stamina...etc => ui toolkit
other stuff like hp above enemies, mob name...etc => gui

rough scarab
#

I don't know what's difficult about looping over world positions and converting those to UI (panel) space personally

#

You would only care about world-space capabilities if you actually wanted rotations and stuff

dark vault
rough scarab
#

🤷 I use a form of ECS so it's just a system that loops over everything that wants to show a piece of anchored UI (i.e. has a relevant component)

#

So that just sounds like an organisational issue and not one about what's actually better for the job

hollow halo
#

How's UI Toolkit nowadays? Is it feature complete enough to use in a new project?
I'm also a web developer, and in my previous Unity project that had lots of UI, I did feel a bit of struggle with uGUI and wished I could just write everything in JSX/HTML -- which UI Toolkit would provide a similar experience.

Mainly I was wondering about:

  • Can we use raw image or alternative? This is used for things like rendering a camera to image so that we can display 3D objects inside the UI
  • Can we use particle system in the UI? In uGUI I use Particle Effect For UGUI
  • Are there still any other major limitations compared to uGUI?
GitHub

Render particle effect in UnityUI(uGUI). Maskable, sortable, and no extra Camera/RenderTexture/Canvas. - mob-sakai/ParticleEffectForUGUI

rough scarab
#

No particles, no shaders--you can use render textures just fine.

hollow halo
rough scarab
#

I have not looked into how it works

#

It could be anything from render textures to generating meshes similar to the above package

#

as they have listed limitations I imagine they're using a similar approach

cobalt nimbus
#

I use ListView to organize scrollable list of values. I don't need adding / removing by hand and any selection. Elements in that list have :hover styles and sometimes after hovering some of elements receive blue background from some style I guess.

Is it possible to shut down hovering of ListView or use something similar without any selection or maybe somehow create some .staticBackground class with unchangeble background-color: ... ! like important keyword in css ?

fast escarp
dark jewel
#

can you apply a selector to multiple pseudo classes without chaining them? For example I want my uss to apply to both hover and focus without needing seperate definitions for both of them

fast escarp
dark jewel
#

thanks that's exactly what I was looking for just wasn't sure of the syntax 🙂

fast escarp
#

I'm not sure if this counts as advertising (I'm not selling anything yet), but I've been developing a game using UI Toolkit for a long time. Along the way, I collected my solutions and turned them into an asset.

I've been using it in my game, but I'd love to get some feedback on it.

Here are its features: https://docs.cupkek.games/luna-ui/gallery

If anyone is interested, I'd be happy to share it and hear your thoughts

fast escarp
dark jewel
#

that's unfortunate 😦

#

having done my own file import and export functionality myself though I get it

ornate cliff
fast escarp
leaden light
urban schooner
#

Quick question:
How do I change the wrapping/content alignment of my "Inventory Slots" such that all children will render next to each other, instead of on top of each other?

urban schooner
#

okay, I found a way. This is not ideal yet, but it will work for now 🙂

fallow mortar
#

Is there no way to somehow bind UXML to a custom control so you can design the UI in the UI Builder? I'm racking my brain on this, but everything i'm seeing says you have to either create the visual elements in code, or in your gameobject behavior add the uxml files via querying.

rough scarab
fallow mortar
#

I'm trying to create a VERY minimal case to learn this, where I have a custom control made up of 2 labels, a name and value, and I want my custom control to have bindable properties of name and value which update the labels in the control accordingly

rough scarab
#

Not sure what you mean. Use queries to get the children

fallow mortar
#

i'm saying I don't know how to get my control attributes bindable, and how to transfer those bound values to my child element properties

#

for example, CustomControl.Name -> CustomControl._nameLabel.text

#

i've been going over the documentation so many times, but there's NOTHING that i can find about custom controls that aren't just extensions of built-in controls

rough scarab
#

By "binding" are you talking about runtime data binding, or something else?

fallow mortar
#

yeah

#

would this be wrong in any way?

[UxmlElement]
public partial class StatPanel : VisualElement
{
    [UxmlAttribute] public string StatName;
    [UxmlAttribute] public string StatValue;

    public StatPanel()
    {
        var uxml = Resources.Load<VisualTreeAsset>("StatPanel");
        uxml.CloneTree(this);

        this.Q<Label>("StatType").SetBinding(nameof(Label.text), new DataBinding
        {
            dataSource = this,
            dataSourcePath = new PropertyPath(nameof(StatName)),
            bindingMode = BindingMode.ToTarget,
        });

        this.Q<Label>("StatValue").SetBinding(nameof(Label.text), new DataBinding
        {
            dataSource = this,
            dataSourcePath = new PropertyPath(nameof(StatValue)),
            bindingMode = BindingMode.ToTarget,
        });
    }
}
rough scarab
#

maybe you're just using this an example, but I'm not sure why that'd require binding:

[UxmlElement]
public partial class StatPanel : VisualElement
{
    [UxmlAttribute]
    public string StatName
    {
        get => _statTypeLabel.text;
        set => _statTypeLabel.text = value;
    }
    
    [UxmlAttribute]
    public string StatValue;
    {
        get => _statValueLabel.text;
        set => _statValueLabel.text = value;
    }

    private readonly Label _statTypeLabel, _statValueLabel;

    public StatPanel()
    {
        var uxml = Resources.Load<VisualTreeAsset>("StatPanel");
        uxml.CloneTree(this);

        _statTypeLabel = this.Q<Label>("StatType");
        _statValueLabel = this.Q<Label>("StatValue");
    }
}```
fallow mortar
#

I had something similar to that, but that wasn't working for me at first, it only updated in the editor, not at runtime. I'll try it

#

yeah, just tried that, doesn't work at runtime

rough scarab
#

I don't use runtime binding so maybe I'm misunderstanding, but to me, your code above is binding the label and stat values to the properties on the element, so it's watching itself.
Surely if you wanted to use binding you would be defining all that in UXML and then you just call SetBinding on the StatPanel, which would bind the children elements using the data source path (defined via UXML).

#

UxmlAttribute just allows you to say <StatPanel StatName="Foo" StatValue="Foo">, and my code just allows you to define strings there or via code. Not via binding.

umbral sonnet
#

Hello, is it possible to create :active pseudostate to basic VisualElement? I'm trying to create a box for an item in the shop that contains a button. And I'd like the purchase to be called even if the player clicks on the button or somewhere else into this box. So I want to create :active state to "basic" visualelement of background.
Thank you! 🙂

rough scarab
#

and to use variables to handle the styling without too much duplication

fallow mortar
vernal gyro
#

Hello! I've started using the ui toolkit and the localization package together and I'm wondering about the update logic when binding LocalizedString.

As an example, if I bind a Label element through the UI builder to a simple field in a data source class. As such:

public LocalizedString Text;```

I've observed that setting the `LocalizeString` itself and setting the `LocalizationSettings.SelectedLocale` both trigger the binding. Now, i'm not sure if the binding mode `OnSourceChanged` is working just as intended or if the binding is checked every frame and that's why both of these scenarios work.

I've looked around on how I could debug this but I don't seem to have found any way to hook onto a binding trigger.
dark jewel
#

Can anyone help me figure out the best way to do pixel art/non-AA fonts in toolkit? Ideally one that supports different font sizes. Last time I messed with fonts with the UX system and I couldn't quite figure out a way to do this. I don't know if the ui toolkit introduces a different way to approach this

feral onyx
#

it’s generally a good idea to not use bitmap fonts if you can at all avoid it stylistically. They have too many conflicts with modern UI idioms and expectations. Also they aren’t great for readability above their native pixel size, which you will probably exceed on practically all modern devices.

dark jewel
#

unfortunately I am doing a pixelated operating system so it's important for the fonts to blend with the rest of the pixelated look 😦

feral onyx
cursive quail
#

Hello! I've started using the ui toolkit

dark blade
#

i applied this

* {
    margin: 0;
    padding: 0;
    border-radius: 0;
    border-width: 0;
    border-color: transparent;
}
``` on my Variables StyleSheets, and i make sure its added to editor window 

var root = rootVisualElement;
root.AddStyleSheets(SXResourcesUtils.VariablesUSS, SXResourcesUtils.DefaultControlUSS);

#

after checking into UI builder seems like my universal selector(*) are being override by unity

#

why?, any thought?

rough scarab
#

Ignoring the "type of style sheet" which I don't think is a thing that's differentiated with editor styles. It's unclear to me

dark blade
rough scarab
#

what do you mean by "from variables USS to Default USS"?

dark blade
#

currently trying to donwload unity 6.3, i'll be back later if problem persste

rough scarab
#

Ah, your two sheets?

#

How are you setting the default control one?

dark blade
#

variables stylesheet, and defaultStylesheet(my default style, in case later i have another layout design idea, i can make other style sheet for it), and yes 2 seperate stylesheets

rough scarab
#

If it's behaving inconsistently then yeah I agree it sounds like a bug

#

What's defined as a "user" style sheet imo is really irritating, and I've run against it a few times

dark blade
#

maybe personal preferences haha, i don't have any basic on web deveploment before, so maybe my "way" are little bit different

rough scarab
#

in webdev every style sheet has the same priority

#

except the styles built-in to the browser I suppose, but I don't believe you end up even thinking about that in the same way. I think theme style sheets act below style sheets, and so I never end up using them because precedence goes out the window.

dark blade
#

help me a bit here, so unity has default stylesheet(the default iterblabla) if i add stylesheet to editor window, in my imagination, my style sheet should have precedence over unity default, since its added last or its not?,

#

but then it's still a bug im pretty sure, since if i add classlist to an element, its should be always after the unity default one, ex: my button class, should be after the unity button class, but after inspecting into UI Debugger, somehow my button class are before the unity-with-icon classlist

rough scarab
#

It's slightly confusing but for each selector that's a match for an element, in order of importance:

  1. "user-defined style sheet" (which I think just means it's not a Theme Style Sheet .tss) selectors have precedence.
  2. The selector specificity (basically, complexity).
  3. The selector's style sheet that's closer in the hierarchy.
  4. The order the style sheet was added to the element (last is higher).
  5. The order the selector is in that sheet.
dark blade
#

thanks

queen flint
#

I had a client set the resolution of some Figma screens to a lower resolution than what the device is. I am using UI Toolkit and my panel settings has the cirrect resolution. Is there a scale factor I can set so that I can use the fiels authored in the Figma?

cerulean gale
#

Hey guys ^^
Someone know how to interact with a worldspace ui ?
I saw a video using a render texture to do so one year ago. Still haven't managed to do it on my project, but is there some new better way ?

cerulean gale
#

Ohh, I managed to see a button click with only a worldspace panel setting, but just not on the button.
I know it's experimental, but if someone know how to do it ^^

rough scarab
#

I use LocalizedString bindings and I have had a similar experience.
My localized label basically never unsets a binding once set, and then modifies the LocalizedString past that point. If the binding wants to be cleared I use the LocalizedString that resolves to an empty value.
There's probably something I'm missing, but I'm not really in the situation where I can wait on asking the Localization/UITK developers about what the deal is, so my workaround will do

umbral sonnet
#

Hello, is it possible to create custom or modify easing function or I can only use predefined functions? Thank you! 🙂

dark blade
#

i keep getting this error:```UxmlElement Registration Error: A UxmlElement of type 'SXToolkit.SXTextField' is already registered with 'UxmlSerializedData'. It cannot be registered again with 'UxmlSerializedData'.
UnityEditor.UIElements.UIElementsEditorInitialization:InitializeUIElementsEditorManaged ()

#

i'm using unity 6000.0.3f

cobalt nimbus
#

Need help! I have very simple hierarch of 3 elements with the same parent. Parent have 0.85 opacity and children have 1 opacity, so they overlap each other in opaque but I can still see through the whole UI element.
I want my #suggestions element to be on top of #input and overlap #logs so I make it position: absolute and give offset from bottom. But this way it rendered as not part of it's parent so it loses opacity. If I make it 0.85 opacity it now transparent relative to logs but I want it to overlap logs completely.
Is this a bug or am I doing something wrong?

urban schooner
#

Quick question:
Is there a way to get rid of the Label font-size selector here? It's overriding my NormalText style

#

ah found it, nvm

quiet light
#

how to add camera projection into image?

abstract sandal
#

So I have a UIToolkit float slider in an editor window with showinputfield = true
but if I click into the input field, and use the arrow keys to move the cursor around, it changes the value up/down
how do I stop this?

vital totem
#

how to create search window ?

lunar dove
#

Trying to get .unity-button:hover to work on UI button but unfortunately I'm unusre how do I add it onto the button.
https://youtu.be/6DcwHPxCE54?si=9sUPcjwarn-ev2PY&t=526

In this video, we'll look at some of the new features added to the UI Toolkit package in Unity 2023.2 and how it's now at a point where it's much easier to work with when building UI for runtime.

To demonstrate this, we'll look at how can build out a functional main menu, how to write and expose custom UI components in code and how we can bi...

▶ Play video
#

I think I need to assign .unity-button:hover but do I assign it right at the button itself?

#

Also has anyone used Ui-Toolkit for Mobile Gamedev?

rough scarab
lunar dove
rough scarab
#

By making sensible layout decisions and starting with a sensible Scale Mode setup on your panel settings

lunar dove
#

On UI Builder right?

rough scarab
#

wherever you're working

lunar dove
#

Let me try.

dark blade
#

that X is an image which i set from button.IconImage, what control that image color? i tried
.unity-button background color, wrong, tried its background image tint color wrong, tried target the image by

.unity-button .unity-button__image
``` also set the background color and background image tint color, also no effect, i'm even try to change the color from UI Builder, also not working...
im using unity 6000.0.3f
rough scarab
#

look at it in the UI Toolkit Debugger if you're unsure what's going on

dark blade
rough scarab
#

I've not experienced that before. I'd update Unity, you've got like 30 patch releases that there could be a fix in

dark blade
#

so it's a bug?, meh i moved from unity 2023 to unity 6.000.3 to avoid bug, just to encounter another one -_-

#

anyway here is my texture setting, it's should be fine right,

rough scarab
#

Sure

#

I'm not sure why you'd move to .3f unless you did it many many months ago!

abstract gyro
#

Hi;
Lets take the example from Unity:

using UnityEngine;
using UnityEngine.UIElements;

// Define the custom control type.
[UxmlElement]
public partial class CardElement : VisualElement
{

    private VisualElement portraitImage => this.Q("image");
    private Label attackBadge => this.Q<Label>("attack-badge");
    private Label healthBadge => this.Q<Label>("health-badge");

    // Use the Init() approach instead of a constructor because 
    // we don't have children yet.
    public void Init(Texture2D image, int health, int attack)
    {
        portraitImage.style.backgroundImage = image;
        attackBadge.text = health;
        healthBadge.text = attack;
    }

    // Custom controls need a default constructor. 
    public CardElement() {}
}

So lets say this is used along with a template in uxml. Is there a way to know once the object is ready to query its children using Q<>? I know I could use on AttachPanelEvent but I actually would prefer a way were it doesn't need to be attached to something first. Is there a callback? Can I may somehow hook into UxmlSerializedData-Codegenerator which helps me?

That whole UI-Toolkit-Thingy is starting to drive me crazy. At the moment I use addressables and sync-loading to get everything ready in the constructor. And choosing way is not like "this gives me benefits over that one" - no its more like: "this has less disadvantages than that one".

I know its still WIP - but why aren't there basic lifecycle-methods? I think with the old UxmlTraits-Thing I may could have achieved what I wanted - but thats obsolet now. I whish I could do something like: [UxmlElement(nameOf(Init))] but thats ofc also no option.

round tree
#

hey I am trying to change the Image of my Button and created an jpg image and would like to use that as my source Image but it doesnt work. Does the Image need an different format as jpg ?

weak fog
#

I can't seem to get the live-reload of USS files working for runtime UI. Anyone knows what could cause it to not reload?

pallid kindle
#

Question when working with creating UI
If I want to just create the player's UI (healthbar, ammo etc) is it better to keep everything together or create seperate UXMLs for different elements

#

Like if I have my health at the top left and ammo at the bottom right do I implement both of em in the same UXML?

weak fog
pallid kindle
haughty sapphire
cunning obsidian
#

is there a way to make an image overlay for a ui that doesnt block button raycasts

#

ok nvm found the raycast target option in the image component

rough scarab
weak fog
#

Wait really? I couldn't get it to work so I created a blank u6 project with a simple Label for UXML + USS. Added the UXML to UI Document. Changing the USS while game is running and nothing happens. If I change the USS with UI Builder open it updates as expected. Double checked that Live Reload is enabled as well

#

Actually since I'm home I'll try it on this PC, maybe I have some setting on work PC that disables it somehow 🤔

#

Hmm yes it seems to work as expected now... I'll bring this project to work tomorrow and give it another shot. I'm not sure why it wouldn't work

rough scarab
#

I don't use the UI Builder; so it definitely doesn't rely on it

weak fog
#

Ok good to know, I'm thinking it might be some import setting that's not correct

dark blade
#

anyway another question so

warning CS0618: 'UxmlFactory<SXEnumField, EnumField.UxmlTraits>' is obsolete: 'UxmlFactory<TCreatedType, TTraits> is deprecated and will be removed. Use UxmlElementAttribute instead.'
``` i got obsolete warning, and its suggest using [UxmlElement] instead, but using this to exposed our custom control to UI Builder will only give us default visual element attribute,
#

but unity already have [EnumField.UxmlTraits] which has the attribute that i need, how i can use that?

rough scarab
#

If you use UxmlElement it should inherit members from its parent

#

if you want to expose any additional properties you use [UxmlAttribute] on those properties

dark blade
#

ah so the parent of my custom control should be Enum Field if i want to have attribute from that...i guess i get it

rough scarab
slow ore
#

How do I update a list of objects? I've been able to add them all to a container but I can't figure out a way to add or remove them based on button presses

#

modifying the container doesn't do anything

#
public override VisualElement CreateInspectorGUI()
    {
        // Create a new VisualElement to be the root of our Inspector UI.
        VisualElement inspector = new VisualElement();
        
        // Add a simple label.
        inspector.Add(new PropertyField(serializedObject.FindProperty("animator")));
        inspector.Add(new PropertyField(serializedObject.FindProperty("body")));
        
        
        inspector.Add(new Label("States"));
        var stateListProperty = serializedObject.FindProperty("states");
        var addButton = new Button(() => {
            var stateMachine = target as StateMachine;
            stateMachine.states.Add(new State());
            //I tried adding another propertyfield here but it doesn't work

        });
        addButton.text = "Add State";
        inspector.Add(addButton);


        var stateList = new VisualElement();
        
        for(int i = 0; i < stateListProperty.arraySize;i++) {
            var listItem = new PropertyField(stateListProperty.GetArrayElementAtIndex(i));
            listItem.style.marginLeft = 10;
            stateList.Add(listItem);
        }
        
        inspector.Add(stateList);
        
    
        // Return the finished Inspector UI.
        return inspector;
    }
#

this is what I got rn

#

oh

#

I think my problem is very silly

#

I might've just forget to update the serialized object

#
var addButton = new Button(() => {
    var stateMachine = target as StateMachine;
    stateMachine.states.Add(new State());
    serializedObject.Update();
    stateListProperty = serializedObject.FindProperty("states");
    Debug.Log(stateListProperty.arraySize);
    stateList.Add(new PropertyField(stateListProperty.GetArrayElementAtIndex(stateListProperty.arraySize - 1)));
    stateList.Add(new Label("test"));
});

nope! this doesn't add the property field

#

it adds the label no problem and is clearly incrementing the array

#

as I can see with the debug and if I close and open

#

but it gives no complaints and just refuses to add the property

rough scarab
slow ore
#

oh my god you saved my life

#

that works ty

lunar dove
#

If I'm making a PlayerInteraction script that involves the Player directly touching the buttons on the screen and not through the Character the Player is playing, do I need to change anything? I'm new to UI scripting, never gotten it far untill now.

dark blade
#
    [UxmlElement]
    public abstract  partial class XUIInputField<TField, TValue> : VisualElement where TField : BaseField<TValue>
```so i make custom Control, and this class for all the field(integerField, FloatField, TextField,Vecto2Field etc) everything good as expected, until i make EnumField
```c
    [UxmlElement("EnumField")]
    public partial class XUIEnumField : XUIInputField<EnumField, Enum>
    //here the constructor
        
    public XUIEnumField() : base(new EnumField(DummyEnum.Dummy1))
    {
    }
``` i noticed the problem only occur if im trying to open this from UI Builder, as if i just ignore the error and simply open the editor window, everything working,
#

and after searching the problem is from this uxml attribute

        [UxmlAttribute("Value")]
        public TValue Value
        {
            get
            {
                return field.value;
            }
            set
            {
                field.value = value;
                clearButton.style.display = ValueEmpty() == true ? DisplayStyle.None : DisplayStyle.Flex;
            }
        }

```first i thought because the value  of enumField can't be null, but i did set using dummy in constructor, any help, thanks in advanced
balmy iris
#

Hey there, I'm new to UI Toolkit and I got my main menu working, however I can't get my loading screen to work because my script can't find the progressbar even though I'm sure I reference it correctly.

        public UIDocument loadingScreen;
        private ProgressBar progressBar;

        //Loading Screen
        var loadingContainer = loadingScreen.rootVisualElement.Q<VisualElement>("Container");
        progressBar = loadingContainer.Q<ProgressBar>("ProgressBar");

        if (progressBar == null)
        {
            Debug.LogError("ProgressBar not found in loading screen.");
        }
#

Isn't this correct? I did it this way for the settings buttons too and those work completely fine

cursive quail
#

Try loadingContainer.Q<ProgressBar>();

#

It doesnt look like your progress bar has a name

balmy iris
#

Ohh does it only have a name if I renamed it myself?

cursive quail
#

Yes. By default it will have no name

balmy iris
#

Ahhh I get it when it has # before the name it means I can reference it with the name but otherwise I can't

#

Thank you

forest inlet
#

So, in USS we have a universal selector, which is *, and it's working perfectly on its own. However, when I try to do #NameHere_*, it does not work. Is there any workaround for this, or am I missing something?

rough scarab
lunar dove
#

Has anyone connected Input System to the UI Toolkit in Unity? I seen videos on UI Toolkit and Input System but never saw one that connected the two together.

rough scarab
#

What do you mean by connected

#

You don't need to do anything special to use both together

lunar dove
rough scarab
#

what do you mean by connected or link?

lunar dove
#

Mainly an if statement that links the button to the Input

rough scarab
#

I don't know what that means.

lunar dove
#

Oh

#

How do I connect this:

        private void TouchPressed(InputAction.CallbackContext context)
        {
            Vector2 position = touchPositionAction.ReadValue<Vector2>();
        }```

To a button I've set in UI Toolkit?
#

Apologies, have just gotten to this part.

rough scarab
#

Which direction? Making the button call TouchPressed, or making TouchPressed activate the button?

lunar dove
#

Is there any difference between the two?

#

Though if I'm having the button open up another button down the line before accesing the main function(refiling somehting on an object), I'll try the latter.

rough scarab
# lunar dove Though if I'm having the button open up another button down the line before acce...

There's no built in way to link them together.
There's many ways to set up the connection though. In our project we have extended most controls and added UxmlAttribute to properties of a class that wraps a InputActionReference. It's assigned via a string using a UxmlAttributeConverter.
When assigned it creates a manipulator that registers the events, assigns classes, sends appropriate events to our elements, and adds binding tooltips.
Then there's also some specific ECS stuff that sets button state during gameplay.

#

There's probably 20 ways to go about it though

dark blade
#
   var dropdown = new EnumAdvancedDropdown(new AdvancedDropdownState());
        dropdown.Show(new Rect(pos, new Vector2(200, 300)));
``` im so lost at this, spend full 3 hour without any succes, i want to spawn this dropdown where my button click in editor window, i'm using UI Toolkit for Editor Window, but i'm aware that advanced dropdown are using IMGUI, so what should i pas as position?
umbral sonnet
#

Hello, I am developing mobile game with UI toolkit, But I am experiencing some problems with the Scroll view. I have level select screen based on vertical Scroll view which contains all game sets obtained in the game. Every set contain a classic level progress tree with buttons. So player is scrolling to wanted set and after that is opening level by clicking to corresponding button.

My problem is, that when is scroll view decelerating and I am clicking to button, it will only stops scrolling/decelerating and don´t trigger button. I know, that in high speed it is wanted behaviour, but it is happening too in very low speed. In some cases I am not seeing any movement and still click to button is not registered and probably only deceleration is stopped... so for registering button I need to click twice or wait some time... Is there any possibility to remove this very low speed deceleration on end (I want to keep deceleration but remove low speed deceleration on end, which is harder to detect by eye)?.. Or some another way to fix it? Thank you! ❤️

Because clicking twice or waiting longer is not pleasant for the player 😦

weak fog
plain basin
#

Yo quick question - is possible to remove this ? essentially make it transparent and we only see the password being written inside the field container?

hybrid oar
#

Assuming that's a TextField, you can simply apply a style at a scope that includes the control that targets the Textbox, which you can do using a selector

#

You can use the UI visual inspector to pick the control in your ui in order to see what the class name you'd target is

cunning obsidian
#

is there a function in unity which sends a ui element to the front/back in c#?

brittle furnace
#

I am having trouble getting my .clicked event to fire. I'm not sure what is wrong? The string name references are correct and my other controller, the MainMenuController has similar code but works just fine.

using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UIElements;

namespace FW
{
    public class PauseMenuController : UIController
    {
        public GameSceneEventChannelSO _GameSceneEventChannelSO;

        public Button m_resumeButton;
        public Button m_restartButton;
        public Button m_exitButton;

        private void OnEnable()
        {
            Time.timeScale = 0;

            m_resumeButton = m_ui.Q<Button>("btnResume");
            m_resumeButton.clicked += OnResumeButtonClicked;

            m_restartButton = m_ui.Q<Button>("btnRestart");
            m_restartButton.clicked += OnRestartButtonClicked;

            m_exitButton = m_ui.Q<Button>("btnExit");
            m_exitButton.clicked += OnExitButtonClicked;
        }

        private void OnDisable()
        {
            Time.timeScale = 1;
        }

        private void OnResumeButtonClicked()
        {
            gameObject.SetActive(false);
        }

        private void OnRestartButtonClicked()
        {
            _GameSceneEventChannelSO.RaiseEventSceneChange(SceneManager.GetActiveScene().name, true);
            gameObject.SetActive(false);
        }

        private void OnExitButtonClicked()
        {
            _GameSceneEventChannelSO.RaiseEventSceneChange("Main", true);
            gameObject.SetActive(false);
        }
    }
}
slow ore
#

how would I display items hoziontally like in this example? like how I have the [X] button over on the side on the same line as the text?

#

flexDirection = FlexDirection.Row seems to be it

slow ore
#

ok so I'm having some trouble, I have this dropdown that I want to be able to pick a list of options from somewhere else in the object, but I need the list to be able to refresh. If I add a state I want it to reflect in the dropdown

#

which is a problem

#

basically I just want the choices to update when you click it

#

its not really a situation where its easy to have every single StateSelector subscribe to every single thing that can change what states exist

#

ok I did it on pointedown it was that easy

patent anvil
#

Is it better to separate out views into separate uxml files and load them at runtime, or should I build the UI in ui builder and package all of the uxml templates together into one uxml file? Is loading at runtime less performant?

limpid grove
brittle furnace
#

I am completing my first Unity project ever as a portfolio item for university applications and the deadline is coming soon. I hope to be able to have at least a function pause menu haha

#

Thanks in advance

brittle furnace
#

Hi all, thanks to anyone who looked and tried. It turns out setting the gameobject to enabled or disabled causes the issue. Setting the display style to none and flex is the correct way to enable and disable UI documents.

lunar dove
#

Is there a way to access the C# code within a .uxml file? I'm trying to call a button within the .UXML file in Unity's UI Toolkit but sofar I'm unable to even after its interaction.

mellow mountain
lunar dove
# mellow mountain I am struggling with my UI I am coding with ui toolkit , my dialogue text pushes...

How did you code buttons? Trying to make mine work but I'm unsure if I understood how it works:

    public class refillFeedButton : MonoBehaviour
    {
        private Button restockFeedButton;
        // Start is called before the first frame update
        private void Start()
        {
            var root = GetComponent<UIDocument>().rootVisualElement;

            restockFeedButton = root.Q<Button>("RestockFeedButton");
            restockFeedButton.clicked += RestockFeedButtonPressed;
        }
        private void RestockFeedButtonPressed()
        {
            Debug.Log("Hello!");
            //If button pressed.
            //Feeder is refilled to full.
            //Else Feeder stays in its current ammount.
        }
    }```
mellow mountain
#

You have to add them to an element first. menuContainer = interactionMenu.Q < VisualElement > ("MenuContainer");
I add them first menuContainer.Add(button);

lunar dove
#

Do I put it at Start()?

mellow mountain
#

OnEnable

lunar dove
#

Do I need OnAwake as well?

#

Cus I don't have a menuContainer myself. Just the RestockFeedButton button.

mellow mountain
#

I dont know im pretty new to all this myself

lunar dove
#

Same

lunar dove
#

Now it works.

brittle furnace
#

Hi everyone, how would you code a circular healthbar in UI Toolkit? Something that fills up like so

hybrid oar
#

Id probably use a render texture to do the actual filling, with a circular mask to hide the underlying texture

fickle perch
#

is there a canonical way to do runtime MenuItem style menus in UITK yet? with support for nested items

fickle perch
slow ore
#

anybody know how I could make a dropdown with categories like this?

pallid kindle
#

Hey I want to overlay a visual element ontop of another one, how would I go about doing that

#

Wait I figured absolute

bitter adder
#

How to use link text to open script at line numbet using UI text/label richtext. I can make the rich text clickable with the a tag but it does not open the script

#

Is there any callback to handle the click event and open it mannualy

bitter adder
#

Yeah like unity console

#

I found out from the editor dll that it uses rich text and link click callback to handle it. But the callback only works for IMGUI

#

No such callbacks i know for ui toolkit

#

Thats why having trouble

queen flint
#

ahh. Not sure about that one

bitter adder
queen flint
bitter adder
#

there are events for it but is in the experimental namespace. check out pointeroutlinktag event and there are more such as hover, up etc

#

instead of a tag its used with "link" tag

pallid kindle
#

Hey struggling a bit here
Anyone know why this might be happening?

#

for some reason its only generating the left part of hte pause icon

bitter adder
#

check slicing settinngs

vital totem
dark blade
slow ore
#

oh sweet

#

ty

dark blade
oblique oxide
#

perhaps a silly question, but how would yall do visual changes to element on tap/click?

:hover seems like an extremely unreliable workaround, and there seems to be very limited guidance regarding this in docs (maybe i am missing something)

rough pilot
#

I have a weird issue with Unities Ui toolkit, specifically when i try to change a "Labels" text, it weirdly overrides the original text. it doesnt create a new "VisualElement" which it shouldnt but somehow the weirdly "overriden" text does not follow the parent anymore. anyone have an idea what might be causing this?

rough scarab
rough pilot
#

i dont thats the thing

#

wait ill send a screenshot

#

this is the original set up

#

and instead of changing the labels text, this happens

#

and when i change again this happens

rough scarab
#

Are you sure you don't just have two instances in the scene?

rough pilot
#

yes i checked

#

i checked all the visualelements that are on the rootvisualelement

#

and its always the same

rough scarab
#

What's it look like if you hide the element with the UIToolkit Debugger?

rough pilot
#

wait

rough scarab
#

It really just looks like a duplicated UI

rough pilot
#

sorry i ahvent used the debugger yet and the internet tells me to click preview but i cant find sucha button...

rough scarab
rough pilot
#

i think i see what migth be wrong

#

but i dont see why this would happen...

#

can i only have 1 ui document per scene, is that it?

rough scarab
#

I don't personally, but I think you can have many, if you use the same panel settings they are placed in the same final panel

rough pilot
#

this is for one of the "declines" the text

#

and this for the other... so i think this is the problem

#

but how come this happened?

rough scarab
#

I don't know, it's your project lol

#

Presumably you've got all of it in the scene/instanced it, and not hidden anything appropriately

rough pilot
rough scarab
#

Different UXML documents

rough pilot
#

i only made one tho...

rough scarab
#

It looks like you're using Yarn, which has probably instanced it for the different views

rough pilot
#

that might be it...