#🧰┃ui-toolkit
1 messages · Page 20 of 1
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());
Also - two typos in this error; is there more details anywhere on how to avoid the instantiation workflow/issues?
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 🎉
has any one made visual elements that can follow objects in the scene or is that not really possible with ui toolkit elements?
Not sure if it's not possible at all, but their documentation does not recommend using it for that.
why click on clickable change pseudo state to active, but not with click event?
Sure, just reposition them constantly. Make sure to set the UsageFlags appropriately so the performance isn't garbage
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
sounds like ui toolkit isn't really built well for that compared to the older system
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?
https://docs.unity3d.com/Manual/UIE-best-practices-for-managing-elements.html
Different approaches to hiding an element
You will have to check that disabling the UI document is equivalent to VisualElement.RemoveFromHierarchy()
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
Thanks for the heads up @rough scarab
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>
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>
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();
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
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?
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
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
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
interestingly this only happens in editor, but it's fine in builds
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)
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)
Might add that I copy pasted some elements from another UXML and that could probably be the cause
Any reason that UI is upside down in device simulator? 🫠
Try rotating it twice.
It being flipped only on the simulator, I’d guess the screen scale might make the scale negative
In the game view it looks good. There is only problem in simulator
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
In the end I used this solution https://docs.unity3d.com/Manual/UIE-HowTo-CreateRuntimeUI.html
seems like my thinking about how it should work was wrong
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.
You can allways subscribe to events and do it in script. But I think it is doable in uss like enabling objecs on click/hover with uss class
https://docs.unity3d.com/6000.0/Documentation/Manual/UIE-bind-to-list-without-listview.html
Why there is INotifyValueChanged<Object> instead of INotifyValueChanged<Texture2D>?
Why when I'm using INotifyValueChanged<myEnum> is seems not be working?
Why TextElement impements INotifyValueChanged<string> and it's working, but it's used in very bizzare way? 🫠
Any one make upto date or know of videos for this toolkit for unity 6 they can recommend?
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
sorry
why in the world is unity not recognizing that my listview not respect having reorderable disabled? is there a known bug for that?
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.
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
ok I think I worked around it with my own capture thingy c:
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
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
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.
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)
Anyone here familiar with this particular part of UI Toolkit: Parallel tessellation ? Or could someone mention an example of a use case?
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 ^^'
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?
yes, you can't give space between the selector and the pseudo class
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.
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.
I guess, as far as visual studio is concerned, we're just relying solely on the UI Builder for now.
for the uss, you can threat the file as vanilla css, and its solved....the problem are with UXML file, that not as simple as uss, and working with UI Builder is really bad, i hate that a lot, many bug, slow, and unintuitive
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
Hi, how do I change the vertical scroll speed of the scroll view for keyboard/gamepad input?
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 );
}```
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&guid=caac3f53eded4a99a1894ed47608c26f&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?
Thanks
So it's more of a trick than a real solution..
I haven't used the UI Builder much yet, so it should be fun.
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.
Hey. Anyone know how to restrict focus inside specific window(visual element)?
hey everyone
i just got unity 6 installed but i can't open it unless i use administration
can someone explain why?
Did you install it into non-system folder?
Also #💻┃unity-talk
yes i made my own folder
i rebooted my pc
now i don't need administration
i finally downloaded unity 6 after 2 days lol
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.
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:
What do you mean? Drawing the UI is unassocated with the camera
put it wherever you want, it doesn't care about either
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
I can only presume that either your UI is empty or the panel settings has something incorrect going on
Screenshot your panel settings, and use the UI Toolkit Debugger to validate where your elements are in the final setup
Gonna share it in here just incase.
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
Ok
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
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
👍
you should probably be anchoring it correctly so it cannot be off-screen
Instead of using absolute positioning you can use alignment
On the Align tab?
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
Noted, here's my Hierachy tab, with Player_Character_Main_UI to be the Root Element for my UI
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.
I feel stupid 
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
Are you putting your styles in a theme style sheet or a normal one?
a normal one I think!
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
hmm, my theme file looks like this
@import url("GeoUSS.uss");```
not sure if it should
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
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
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
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
Well if it's got nothing to do with UIToolkit then you shouldn't be asking here. #🔎┃find-a-channel
hm yeah I've already done that
yeah that adds a <Style src=" at the top
i want room for eror in unity
I would try removing the import from the theme and see if that does anything
buddy
i can't make preject in unity
Ask in a relevant channel buddy
idk any room like that
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
i read
i want room no location
if you want help with an error message then #💻┃code-beginner is probably a good start
#💻┃unity-talk and ask an actual question
if you meant remove my uss, then, made no difference
I believe you shouldn't be fighting for precedence with this setup
You just get it if a selector matches at all
nvm maybe unity bad
yeah that's why I'm feeling a very strong "I have to be doing something wrong" energy
it's also really annoying that the default theme isn't (easily?) readable
Very annoying
like if I could read that then I could at least debug and see what selectors I should use
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)
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"
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
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
" and im like yeah I know but given what selector and from what variable?
The .unity-button selector may just hard code it. I'm on my phone-does it usually show vars in that area?
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
https://www.foundations.unity.com/components/button
If they use the same ones as the editor then it'll be
--unity-colors-button-background
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 
Your styles will be set at the TemplateContainer to be clear, not at the PanelRootElement
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 
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
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
;-;
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
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?
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)
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
hm, using what specifically?
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
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
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 😦
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?
Is there a way to set up hotspots for cursors? Otherwise the functionality for cursors is completely useless, since the cursors are all offset...
Yes https://docs.unity3d.com/Manual/UIE-USS-SupportedProperties.html
It's the two integers listed in the syntax, you can see some examples in the linked MDN docs (though note there's some differences, the hotspot ints are the same)
so it exists if you write it in uss, but just not in the ui builder interface?
seems to work
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.
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?
Put "Input System UI Input Module" on your GameObject with the UI Document. And also use "PlayerInput" for handling inputs.
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
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]
I think you don't receive the event without the variable being directly declared on the element, so you might want to make another variable declared on your element that references that one, and then resolve that variable.
The whole problem is I wanted to avoid a style sheet here because it's just some debugging ui
I just want to use appui variable sizes for width/height
Then I think you'll have to subscribe on the root element
@rain wind did that end up working?
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;
}```
should i use controls like enumfield at runtime? it seems to work but it feels so janky, also dunno how to style it
better not, since the popup for enum field choose enum, are hidden from our, we can't do ||shit|| to it
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.
does anyone know how to make buttons switch pictures????
Has anyone done a round progress bar in uitoolkit? Like going around clockwise
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.
Hello,
transition-animation on position doesnt seem to do anything? Is there any reason why this won't work in Unity 6 anymore?
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?
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
you can make a new class inherited from UIElement.Image and add [UxmlElement] attribut into it, that will exposed it to UI Builder, working directly witth unity Uxml file is confusing, no help from intelisense at all
It depends what namespace has been used at the top of the file.
no help from intelisense at all
Reasons to useRider lol
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.
Is it expected the KeyDownEvent is not triggered for TextField element in runtime even though InputEvent and KeyUpEvent events are?
The prefix ui: or engine: is an alias to the full namespace of the c# type. You'll see it declared on top of your uxml file as xmlns:engine="UnityEngine.UIElements"
makes sense
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
Is there carousel slider component available for UI toolkit? (free)
how do i change the ui:DropdownField background color (or any properties for the background)
not sure if this is the correct channel
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
seems like you need a bit of a hacky workaround, since they didn't bother implementing it well
https://medium.com/medialesson/how-to-style-dropdown-selectors-in-unity-ui-toolkit-229900de0330
ah yes thanks
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?
Is there a way to disable rather than hide perhaps?
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 😉
Sort of... You can dissable the GO but it's not recomended from what I read... The issue is it's not clear what the reccomended method of doing this is. At least, not to me
Sorry, I'm just starting with UI toolkit, I just thought it'd be similar to javascript / css
Is there a reason why a ListView that is not marked as resortable allow for clicking and dragging of items in that list view?
Hi! What's the difference between binding property "Text" (red arrow) and Binding collapsable view at the top of the Inspector (yellow arrow)?
I'm on my phone, but you should look at the output UXML to find the difference
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;
}
}
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?
Anybody knows a way to make scrolling over an UI element block the scroll event to reach game input? (which would be zooming)
I generally use this block of code _eventSystem != null && _eventSystem.IsPointerOverGameObject() which results to true if the mouse is over a ui element
Does anyone know why when I have a ListView with Reorderable unchecked, I can still click and drag to reorder the items?
yeah thats what i ended up doing
There is a bug for this: https://issuetracker.unity3d.com/issues/the-list-remains-orderable-when-nonreorderableattribute-is-used
Reproduction steps: 1. Open the attached “BugNonReorderableAttribute.zip” project 2. Open the ”SampleScene” 3. Select “GameObject” f...
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??
Got it!!
I need layout element!
Hi Folks, has anyone managed to get UI Toolkit to work with local multiplayer?
(i.e. splitscreen)
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?
What happens? I didn't know they cared about cameras
Ah, does it care about the clipping rect?
It just renders across both viewports
That's exactly what I would expect
I'd like it to care about the camera 😂
Well, that's not how it works, so you'll have to divide the screen manually
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
Yes you can do that. I'm not sure what the best way to go would be, you could probably have one setup and have 4 UiDocuments sharing the same panel settings, and offset their roots differently
Ah cool, I tried multiple but I couldn't offset them, I'll try again when I'm back at my machine
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?
@fickle perch : That might help: https://docs.unity3d.com/Manual/UIE-ViewData.html
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
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 😛
I just forgot how to iterate over the correct fields lol
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 
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?
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
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?
seems this was a reported bug
oh yeah lol
ur the one who reported it was reported my bad lol
i got around this for now
made events NavigationSubmitEvent and BlurEvent set a flag to be processed in the next Update() call, so that order of events doesnt matter
that way if random BlurEvent calls that i dont want are run when you hit enter, the submit event still gets processed
in my brain it feels icky and i hope theres a better way
I would like to report that i did try upgrading to 6.000.1.0a6 and that im still able to drag around elements in a list-view even when reordable is toggled off
how can I add a game object reference or a variable reference to this?
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)
How to set binding in column and cell?For above list?
ObjectField
It's just a standard editor control, nothing to do with graph view
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?
Only info I found is this: https://docs.unity3d.com/2022.3/Documentation/Manual/UIE-Runtime-Event-System.html. I am using new Input System so from my understanding is that I don't need to do extra steps to use it.
Have a look at your Event System object -- it should have an "Input System UI Input Module" component on it
e.g.
It references an input action asset.
It should already be working, though -- you're just looking for WASD/arrow navigation, right?
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!
please @ me if you are able to help
does it compile scripts in between? if not you might want to run
CompilationPipeline.RequestScriptCompilation() or so
@clever crest
Hey, it does compile the scripts but after it tries to create the SO instance.
Let me try that and I'll let you know if it worked, thanks!
Didn't work sadly, here's a video of it happening in case it helps:
https://www.youtube.com/watch?v=RIao3JgtVMw
My Website:
https://nnra6864.github.io/nnra/
My GitHub:
https://github.com/nnra6864
My main channel: @_Enenra
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!
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
You can open the uxml file with your IDE
I did, and it got me compiler errors
And copy past the inline style to the ucss file
saying something about attributes missing tags
You need to add the component reference at the top of the uxml file too
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
Yeah there is still a lot missing, like adding css variables
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
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?
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?
Yeah it shouldn't redraw every frame for no reason, it's supposed to be optimised 😅
I don't no if any Unity UItoolkit developers are watching this discord
I'll have to investigate a little more! it could also just be my fault c:
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
it also doesn't help that I'm doing something kinda wonky on top of that
I never digged the editor components creation side of UIToolkit but I look forward of what you are doing with it
Ah my bad, don't hesitate to @ me if you have more questions then
So it's a runtime editor so to speak 😅
I know you always work on tools, that where the confusion comes from
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
It's probably late but I hope you are using a recent version of Unity and the runtime binding feature. It avoids a lot of manual referencing and bindings
https://docs.unity3d.com/2023.2/Documentation/Manual/UIE-get-started-runtime-binding.html (the doc isn't perfect and don't show that you can also configure your binds inside the UIBuilder)
Also Unity introduced a Reducer like state manager in their App UI package that pretty much work like web redux
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
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
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
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
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!
Ah yes I see what you mean, in the case where the list changes a lot it might be less performant yes, I only had the case where the list only needed the data to be prepared once and never changed after that or not very often
I feel the complete opposite hahahaa
UI Builder produces really ugly UXML so I do understand why it feels like that though
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
Reproduction steps: 1. Create a new project 2. Hover any item that has a tooltip 3. Press ALT + F2, and enter ‘lg’ to open the Looki...
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.
there is two way
var wnd = GetWindow<NisualizerSceneCreator>();
wnd.titleContent = new("Nisualizer Scene Creator");
or
var wnd = GetWindow<NisualizerSceneCreator>("Nisualizer Scene Creator");
``` afaik both working fine, and if not, then its a bug
Pinged the wrong person
ehh sorry
@clever crest
thanks!
Yes, and submit with enter/space. I had setup like you describe but might be something different. Will be working on it today will post update if I get anywhere.
@tulip sundial Ok I was monkey, thanks for help
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.
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
No. You probably should just add your own classes to the elements
or can you just remove the :m_Script from it, even it auto generated, but you control whatever generated right?, so exclude that part wont be hard i guess
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
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?
is there a way to force a refresh as a band aid fix?
this workaround doesnt seem to work
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(?)
but why are u moving visual element?
just to see if that forces a layout update (which it does)
oh
is there a version of GenericDropdownMenu that supports nesting? like, multiple levels deep of menu items
(in builds, not editor)
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)
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.
where can I read more about these properties?
Why do you need to?
It's how the UXML is serialised after it's imported, and it's irrelevant to using it
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
https://docs.unity3d.com/Manual/UIE-UXML.html
It's just the imported UXML, serialised in UnityEngine.Object form so it can reference assets
It's intended for the UIDocument and Unity's internal code, and no-one else
Does UI Toolkit support particle effects and shaders yet?
how do i align that to the bottom, been touching all the settings and it doesnt movee
The root object isn't very useful. If you're building something like a HUD or menu, generally it's best to make a full-size element at the root that's anchored absolute with top, bottom, left, right as 0. And then use that to control the position of the children.
ooh ok
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
how can i move freely the items? im new to this, there getting stuck to a specific alignment
If you want to ignore layout entirely you use absolute positioning
o htrue, but im back to the same issue, i want a hud at the bottom, just a line of items, but for taht i need a container no?
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
yeaah i was triying to follow some tutorials buut midiatly got lost, some of the gui is different and im getting lost on all the options
and it loooooks easy to manage, like a css and html buut im getting lost on all the menus and options
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
actually, even if you're going based on UGUI
you'd still be looking for an equivalent of its HorizontalLayoutGroup
What do you mean? The equivalent is just baked in as flex
there is no need to look for anything, as layout comes by default
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?
In the editor? That's just a PropertyField.
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
do UI toolkit elements auto-unregister events/callbacks when they are disposed?
what do you mean? they dont even register anything
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
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 ?
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.
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
I see. Thanks for the detailed explanation 😄
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.
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
How can I make a Serialized reference with the UIToolkit
Style an element at the root so they take up the space you want them to
style it via code
Do buttons have USS substyles for when they are being selected by a gamepad, similar to how the hover and active sub-styles?
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
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
Yeah. You can hook up the same event system as the previous UI system for basic navigation. I don't know about element styling though.
Found it. It is the Focus Qsuedo-Class
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
sounds like you shouldn't set the cursor to default, but whatever the currently-hovered UI would want
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.
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
This version of Unity is old, no? The searchable context menus were removed, have they been brought back?
Also, I don't know what UI menu has to do with UITookit (this channel). If you don't see the menu for UGUI's objects then presumably UGUI is not installed
Hello. Do you know how to build a tree list in the UI Toolkit?
I can't drag and drop anything into TreeView.
you have to drag it underneath until blue line shows or drag it directly on canvas
I did exactly that and then it's detached (it's outside the TreeView)
oh you meant INSIDE tree view, yeah pretty sure its by design lol
you know what tree view is right?
sure, this is what I want
I jsut can't put anything in TreeView so how can I work with it?
you have to Bind data to it
did you open the inspector for it, you will see all the options
sure that works too.
it's crazy that I need some unknown data source instead of adding labels and other things to the tree
afaik its just a list you can link to
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?
This is a question for #📲┃ui-ux
Text Mesh Pro is UGUI not #🧰┃ui-toolkit
oh mb will post it there
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:
Bump
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..
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?
Is it possible to create a tooltip that holds data which follows the mouse as I hover around in a box?
sure
hey! is there a way i can hyperlink some text in a label through code
Should I use one or multiple UI Documents?
thanks! so do these tags go within the text when i set like label.text?
hm do you maybe have an example? i tried infoLabel.text = "<a href=\"https://www.unity.com\">Visit Unity!</a>"; where infoLabel is a Label. that didn't seem to work
what Unity version are you using?
I don't have to on my end
hm is it bcs i'm in editor?
gonna try setting it as selectable
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?
You would change the order of the cards
Is it normal for the UI to stay when unloading an additive scene or did I do something wrong?
You either haven't unloaded the UI, or you've unloaded all rendering cameras
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.
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
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?
NavigationMoveEvent navigationEvent = NavigationMoveEvent.GetPooled(TranslateDirection(direction));
uiDocument.rootVisualElement.SendEvent(navigationEvent);
I thought this would restrict it, but no luck
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?
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
SendEvent is just a wrapper for sending the event to the panel.
You can set the target of the event before you send it so it actually trickles down to a relevant target
But it's unclear it'll be handled how you want it to
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
Ah, I see, I ran into that when I was trying to access random properties of the label but wasn't sure if it was the correct thing.
I don't have much experience w ui toolkit so I just wanna make sure that this is the correct way to set the font:
_label.style.unityFontDefinition.value.fontAsset = //The font asset;
Thanks in advance!
I imagine it will have an implicit cast that makes the value.fontAsset redundant
But I'm not at my computer to check, and would also prefer USS to style
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?
Also what is up with these docs. it claims you need className, but name: works in a query?
you could try using the transform property of the console element
what do you mean you need a className?
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
you don't need a className
you use className when you have to apply specific styles to an element
the docs use it becasue it's useful not because it's mandatory
you can just ignore it completely if you don't need it
It's mandatory when you need to lookup name="foobar"
I'm sorry I'm not understanding you right now
Can you give a little bit more of context
Yeah you are missing the point 😄
in what context is it mandatory??
When you need to query for elements with name="foobar"
i mean you could just query by element name, no?
element.Q("name");
both parameters are optional
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
ok it could be the problem with the emulator, I tried the same apk on a physical device and the sliders work perfectly
are there any good resources/tutorials on creating custom elements?
I've checked pins but nothing looks like it quite covers that topic thoroughly
not really bro, at least for me...i need to make and check, sometime its hidden somewhere on someone project on github where they use UI Toolkit
😦
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...
What kind of elements
Thanks for the tip. I've decided to make the split screen menus a bit more simple and use the old UI system. I've started making the "normal" menus from UI toolkit and I really gel with it, mostly because I have a lot of HTML/CSS/JS experience and it's very similar
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
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
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
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!
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
The first one if I understand correctly is very simple to do
This was one of the first things I made helper methods for generating
Currently it looks very basic but it is the exact concept you mentioned: the field label and whatever field value entry (slider, text, selector buttons, etc) are divided, I could add another visual element between them to make a bar to act as a visual divider
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
Code only is the way for maintainability
I have very strong opinions on this 😄
My philosophy on avoiding the UI builder for actual UI building is that:
- it's a genuine hassle
- you essentially always make the UI anew between different "screens"
- 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
Hello 😄
I created a Toggle in a UIDocument, but nothing happens when I click on the checkbox. Did I miss something ? Ty ^^
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
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
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.
If it crashes then look at the log
yeah, I have no clue what to think of this, windows build works fine too
Yeah no idea, some linux segfault
Can you achieve Heartstone animations and effects using UI Toolkit?
Hearthstone cards are 3D objects. There are ways of displaying UI made with UI Toolkits in 3D world, so I guess the answer is yes.
@scenic brookCan 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...
Generally speaking, is it more performant to use vector graphics or atlased sprites?
all vector graphics have to be converted to some form of a sprite(sheet), polygon mesh, or both, before they can be rendered efficiently. So generically speaking, vector shapes are worse. But there may be other concerns that override this situation or make it irrelevant.
Such as wanting to primarily target high dpi devices where the manufacturer of said devices prices storage like it's 1974? 🍎
are you talking about making ui toolkit widgets/graphics yourself?
i.e. the mesh/vector drawing APIs?
or icons, styling and text you add to existing widgets?
I do intend to use the vector drawing API for some aspects at some point but for now I'm talking about for icons
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?
Time to whack it in the frame debugger and find out
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)
#📲┃ui-ux this channel is for a different UI system
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
No, you'll have to use your own properties
Iirc you can draw outside of the area just fine as long as overflow isn't set to hidden
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
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.
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
#📲┃ui-ux not toolkit. And make sure you have EventSystem enabled.
thanks, i'll go there for further issues with this
i think that's it creating a new event system via create > UI > event system in hiearchy fixed it
I made a custom editor in Unity, why is my font pixelated? It's not sharp like the rest of the editor:
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?
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.
No. Both assets are imported. You could try to pull apart the importer logic to support a greatly cut down version though
Thanks for the answer, really wish this was a thing because I don't see a reason for it to be impossible butt sure.
alright thanks that's somewhat useful at the very least!
i guess the easier way is get the value from the input field, then do your magic, for adding the , or . then use SetValueWithoutNotify for that, but i'm not sure that numeric field allow to add comma or dot in it, so textfield is your friend
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.
How can I reference a VisualTreeAsset from a custom BindableElement? Since it's for runtime UI it also needs to be included in build
[field :SerializeField] public string Name { get; set; }
how to bind this property to label/textfield.value?
do you how to bind gett set properties?
Is the UI-Toolkit an extern download ? Or where do I activate it ?
brother that was a year and a half ago
Yah ,know
https://unity.huh.how/serialization/serializing-a-field-1#properties
The field will be serialized as
<Name>k__BackingField
I presume it's the same path you'd use for runtime
It's build in. In newest unity versions it wasn't even in package manager. Earlier version had it in package manager.
in ui tool kit how to define space between lables in a absolute visual element?
Inside of an absolute element is just a flex container. So... Flex settings through justify-content, padding, margins, more absolute positioning. However you want. There's even more ways than those!
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
Is there a real quick way of making dashed lines in UI toolkit? On the latest Unity 6
Anyone have any suggestions on how to play a sound on button hover and click?
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.
This is how I achieve this:
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
Thank you @tall owl !
I was thinking of doing it like this or maybe creating a custom element called AudibleButton that registers the callbacks
Yeah, it's unfortunate having to write essentially a custom script to do this, but it's the only way I found.
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
How do I share a uss variable between multiple stylesheets?
If a selector creates a variable then it's inherited through the hierarchy
doesn't matter what sheet it was declared in
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
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
i don't think that's easy tho
for rotation u can create 1 component, and slap it on any canvas u want to rotate towards camera
for position, ill have to keep track of everything in my screen
🤷 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
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?
The comparison between the two has barely changed, and is pinned to this channel.
No particles, no shaders--you can use render textures just fine.
For UI toolkit particles, the only thing I find are paid assets on the asset store (https://assetstore.unity.com/packages/tools/gui/ui-toolkit-particles-particle-image-for-ui-elements-252260). How would these work given the particle limitation in UI toolkit, does it just render particles from the world onto a texture image in the UI?
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
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 ?
yea you can override the default styles but its a bit annoying to find them. Run the game, open ui debugger, hover the element, alt tab or win key so game pauses in hovered state, click on ui debugger, find the element and the style giving blue bg, override it in your uss
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
I dont think so but you can do it like this:
asdas:hover,
asdas:focus,
{
}
so you dont have to write same styling twice
thanks that's exactly what I was looking for just wasn't sure of the syntax 🙂
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
just a note: if you save an uxml that uses this uss in ui builder, they will be separated again
that's unfortunate 😦
having done my own file import and export functionality myself though I get it
Please create a thread in #1179447338188673034 , ask for feedback there.
sorry, didnt know about that. Thanks!
This looks super interesting. I'd love to check it out if it's available.
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?
okay, I found a way. This is not ideal yet, but it will work for now 🙂
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.
You can load the UXML in the constructor and clone it into that element via any normal means. Addressables, resources, etc
I think i've got that working now, not sure if this is the correct way:
public StatPanel()
{
VisualTreeAsset uxml = Resources.Load<VisualTreeAsset>("StatPanel");
uxml.CloneTree(this);
}
Problem now, is that I don't know how to allow my custom control's attributes to be bound and update my UXML's child element properties with those values
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
Not sure what you mean. Use queries to get the children
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
By "binding" are you talking about runtime data binding, or something else?
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,
});
}
}
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");
}
}```
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
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.
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! 🙂
you have no control over psuedo styles or states sadly, it's all internal. You're best option (beyond exposing the internals) is to just manage your own utility styles
and to use variables to handle the styling without too much duplication
I'm trying to make it so the consumer of stat panel doesn't care that there are labels. It just knows of StatName and StatValue, which StatName will be a static property on the instance, and StatValue will be bound to a data source.
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.
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
You can look for any solution for how to do it via textmesh pro. You will likely be locked to sizes that render pixel perfect (multiples of the base size), all other sizes may be blurry or crooked depending on how you go about it.
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.
unfortunately I am doing a pixelated operating system so it's important for the fonts to blend with the rest of the pixelated look 😦
Well the issue is that ui toolkit fundamentally is resolution independent and tries very hard to do the opposite of what you need. Not much you can do about that besides ‘hacking’ the tmp asset to ‘degrade’ the rendering
Hello! I've started using the ui toolkit
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?
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
im more believe this is a bug, so i tried move the universal selector from variables USS, to Default USS, its worked, then after re open window its not working again, then i tried add the uss from UXML, its working, then after a while its didnt work again(im not even reopen the editor window) im using unity 2023.2f
what do you mean by "from variables USS to Default USS"?
currently trying to donwload unity 6.3, i'll be back later if problem persste
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
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
maybe personal preferences haha, i don't have any basic on web deveploment before, so maybe my "way" are little bit different
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.
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
It's slightly confusing but for each selector that's a match for an element, in order of importance:
- "user-defined style sheet" (which I think just means it's not a Theme Style Sheet
.tss) selectors have precedence. - The selector specificity (basically, complexity).
- The selector's style sheet that's closer in the hierarchy.
- The order the style sheet was added to the element (last is higher).
- The order the selector is in that sheet.
thanks
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?
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 ?
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 ^^
bump
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
Hello, is it possible to create custom or modify easing function or I can only use predefined functions? Thank you! 🙂
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
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?
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
how to add camera projection into image?
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?
how to create search window ?
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...
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?
You don't. The class unity-button is already assigned, the :hover state is a psuedo style that's applied dynamically based on the hover state
Noted. How do fit it into mobile (Samsung phone) resolution then?
By making sensible layout decisions and starting with a sensible Scale Mode setup on your panel settings
On UI Builder right?
wherever you're working
Let me try.
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
https://docs.unity3d.com/Manual/UIE-USS-SupportedProperties.html
-unity-background-image-tint-color:
look at it in the UI Toolkit Debugger if you're unsure what's going on
.sx-inputfield #sx-clear-button > .unity-button__image {
-unity-background-image-tint-color: red;
}``` i did that, and its applied as we can see from UI Debugger, yet on actual icon image color, still white
I've not experienced that before. I'd update Unity, you've got like 30 patch releases that there could be a fix in
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,
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.
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 ?
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?
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?
It seems live reload doesn't work for runtime UI which is a shame 😦
Still trying to find an answer to this if possible
Im a bit confused on if I should create an empty with multiple UIDocuments or just work everything into one
Depends on how you want to handle it. If you want to reuse it you can make them separately, if not you can slap them all together in one thing. You can also look at the dragon crasher sample (learning from it myself RN)
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
It definitely does.
For me in Unity 6, style sheets live reload without having to turn anything on. UXML requires live reload to be enabled on that window
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
I don't use the UI Builder; so it definitely doesn't rely on it
Ok good to know, I'm thinking it might be some import setting that's not correct
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?
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
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
Yeah, or you declare that setup yourself and mark the relevant properties with UxmlAttribute if you want to completely rework the setup
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
A property field needs to be bound to create its children. The editor calls Bind on the root object after you return it so the work is batched together.
You'll have to call Bind manually if you create property fields at other times
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.
[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
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
Try loadingContainer.Q<ProgressBar>();
It doesnt look like your progress bar has a name
Ohh does it only have a name if I renamed it myself?
Yes. By default it will have no name
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
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?
just target by className,
That's not how it works, it doesn't act as a wildcard
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.
What do you mean by connected
You don't need to do anything special to use both together
Really? Thought you have to add somehting to link the button to the Input System?
what do you mean by connected or link?
Mainly an if statement that links the button to the Input
I don't know what that means.
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.
Which direction? Making the button call TouchPressed, or making TouchPressed activate the button?
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.
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
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?
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 😦
Solved it! The issue was that I had Auto Refresh (Preferences > Asset Pipeline) set to Enabled Outside Playmode 😅
Yo quick question - is possible to remove this ? essentially make it transparent and we only see the password being written inside the field container?
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
is there a function in unity which sends a ui element to the front/back in c#?
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);
}
}
}
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
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
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?
I usually do what Unity did in their examples. One uxml with multiple uxmls working as screens. Turning them on/off do the trick. Afaik Unity needs to build it every time you call for it, so it's easier to have them build on start and just keep them.
My apologies for repeating this but is anyone able to inform me on what I might have gone wrong or how I can provide more info on the issue
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
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.
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.
I am struggling with my UI I am coding with ui toolkit , my dialogue text pushes into the dialogue options below: https://pastebin.com/80wEC6gc .
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
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.
}
}```
You have to add them to an element first. menuContainer = interactionMenu.Q < VisualElement > ("MenuContainer");
I add them first menuContainer.Add(button);
Do I put it at Start()?
OnEnable
Do I need OnAwake as well?
Cus I don't have a menuContainer myself. Just the RestockFeedButton button.
I dont know im pretty new to all this myself
Same
Now it works.
Hi everyone, how would you code a circular healthbar in UI Toolkit? Something that fills up like so
Id probably use a render texture to do the actual filling, with a circular mask to hide the underlying texture
is there a canonical way to do runtime MenuItem style menus in UITK yet? with support for nested items
it seems like GenericDropdownMenu doesn't support nesting while the legacy GenericMenu doesn't support UITK? :c
ok managed to work around it with this https://github.com/fabSchneider/fab.uitk-runtime-dropdown
anybody know how I could make a dropdown with categories like this?
Hey I want to overlay a visual element ontop of another one, how would I go about doing that
Wait I figured absolute
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
To open script?
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
ahh. Not sure about that one
found solution
What was it
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
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
check slicing settinngs
why only 9 item are being show?
isn't that just a generic menu?, other option you can use is Advanced Dropdown, better style and has Search Field
generic menu? wdym
https://docs.unity3d.com/6000.0/Documentation/ScriptReference/IMGUI.Controls.AdvancedDropdown.html i'm more prefer this thought, compare too generic menu,
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)
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?
It's unclear what you mean, why would it create a new element when you change the text of a Label?
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
Are you sure you don't just have two instances in the scene?
yes i checked
i checked all the visualelements that are on the rootvisualelement
and its always the same
What's it look like if you hide the element with the UIToolkit Debugger?
wait
It really just looks like a duplicated UI
sorry i ahvent used the debugger yet and the internet tells me to click preview but i cant find sucha button...
Learn the UI Toolkit debuggers, and how to resolve performance issues.
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?
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
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?
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
obv. but do you know why there wcould be so many different template containers?
Different UXML documents
i only made one tho...
It looks like you're using Yarn, which has probably instanced it for the different views
that might be it...
Rider lol