#🧰┃ui-toolkit
1 messages · Page 4 of 1
Why does this button clicked event not work? Its 100% finding the button.
And the button's icons and pseudo-classes are being set correctly.
But this one function isn't getting called.
And the event is showing up in the debugger.
Figured it out. Nevermind.
Apparently if you disable the frame and re-enable it, the registered events are removed.
hi how do you convert from screen to panel in 2021.1 before RuntimePanelUtil ?
Hey, guys! Can you, please, tell me how to style default tooltip (that appears at runtime for all built-in controls)? Is there any resources with all internal selectors (and their properties) for predefined controls?
does anyone have any clue about this?
it doesn't get key down events either
https://forum.unity.com/threads/change-styles-for-dropdownfield.1307496/
this nice thread kinda answered my question
how can I create a crosshair with the ui toolkit should I use a symbol(text) or an image and how do I center it correctly
?
ok im getting closer. I've figured out that if I put one document I have inside of another, neither of them can receive events. This didn't happen before; what gives?
I'm getting a NullReferenceException whilst I'm opening/closing my inventory UI, or sometimes when I drag and drop items.
The exception isn't frequent at all, and will be perfectly fine for a while, and then out of nowhere it'll just throw a hiccup.
Errors:
https://hatebin.com/khbaiepzos
https://hatebin.com/bnlyeluvyq
this error means literally nothing without context, so I suggest you to just learn what's it about
and figure where it happens at least
So, is there an option to easily disable the possibility to click a singular button via code for UI toolkit?
.SetEnabled(bool)
Hello I've got a question is UI Toolkit oficially 'production ready'? Because It was kinda laggy for me and I don't know if it's because I've use *-preview version or it just works like that
I mean, sometimes it would freeze entire PC (I'm using linux), it's a common problem or just me?
it is released as current gen
or maybe even LTS in 2021
oh yeah, 2021 is LTS now
and it has UITK built into engine
generally it's good to go now
ok, thanks for info
Because sometimes it would freeze entire OS, thus loosing unsaved changes made in UI Editor....
Never experienced or heard of it
anyone have any ideas what could be wrong here?
is there not an easy way to set all the borders color at once?
I have to change the top and left and right and bottom border color in code?
renderTexture.style.backgroundImage = new StyleBackground(hero.renderTexture);
can you not set renderTexture in code?
this doesn't work
you can set it in UI builder
or through UXML
I'm needing to switch it during runtime
You can actually you just need to create a new Background object and set the renderTexture property if memory serves
But the border thing is a pita - I should just create an extension method thinking about it
new Background() { renderTexture=hero.renderTexture }
Try that maybe? Not in front of pc atm
lifesaver ❤️
didn't even know Background was a thing
I found StyleBackground...but it didn't have anything renderTexture wise
Yea it’s definitely a bit jank but historically it was done through the Image type which was never exposed publicly so… it’s better than it was but still not great
is there anyway to make the listview go horizontally instead of vertically?
have also tried changing it in code but didnt work
doesnt look like its possible :(
@thin bane no clue Listview vs Scrollview
But scrollview can just go horizontally
Or just vertically
Or maybe both at once...not sure if thats possibly tho
Any solutions for UI toolkit lagging when you type? (Very large/complex doc)
Any Unity staff here able to advise what the plan is for XR UI and UI Toolkit because MS just laid of their entire XR team?
Lots of devs were using MRTK which had a nice spatial UI system (with flex/algiment/etc.. similar to UI Toolkit and flexbox).. https://www.itworldcanada.com/post/entire-microsoft-vr-team-among-laid-off-10000-staff#:~:text=Microsoft's 10%2C000-person layoff may,virtual reality products being axed
Microsoft’s 10,000-person layoff may put a halt to the company’s HoloLens and headset-based projects, with entire teams working on mixed reality and virtual reality products being axed.
I'm just doing
document = GetComponent<UIDocument>();
document.rootVisualElement...
but it keeps telling me that rootVisualComponent is null? What could cause this? my UI document is fine, and isn't null.
Z-index when? 🥹
I just want a simple dropdown
while having the parent element docked relatively
WindowContent overlaps the dropdown...
even the built-in dropdown is a fake popup
what da heeeaaallll
I always do this in one line
VisualElement root = GetComponent<UIDocument>().rootVisualElement;
assuming the script is on the object with UI Document and the UI doc isn't blank
I imagine it should work
Anyone know why UI will work in the Editor, but when I try in a build clicks do not work on my buttons?
I have the Event System in the scene.
If it makes any difference, im using BOTH input systems and the UI is made from the Toolkit.
I've ran into issues where another UI doc was blocking inputs
or I have like a joystick stealing inputs also
Well the Hover color change works for the mouse on the buttons, so it has to be something weird
Im going to try and set the Sort Order to 1 and see if it help. I doubt it
I feel like something is missing.
2022.2?
.1.4f1
not sure then
It was broken in 2022.2 until 1f I believe
oh shit. well damn
I thought maybe it was because I didn't have a Player Input on any GO in the scene
but even then it still doesn't work
you just need to have event system
as long as it's here - inputs are passed to UIDocuments
check log
for errors
I'm pretty sure
it'll reveal what's up
I forgot how to pull up the Debug console on a dev build
Appdata/LocalLow/YourOrganization/YourApp
log file is here
on windows
It's just strange how the Mouse Hover works, but not the Click event.
_playButton = _root.Q<Button>("playbtn");
_playButton.clicked += PlayButton;
I can even click and drag on the input field. So it must be the .clicked not working correctly.,
I updated to 22.2.3f1 and it still doesnt work...
Try pure test in empty project
Still nothing
And I have both of those. Man this is frustrating
I made a custom style for :focus and that goes to show you that clicking works.
Now why the hell won't the actual function run???
GOT IT. FINALLYYYYYYYY
I took the subscriptions out of the Awake function and threw them into start.
yeah, thats what i thought, but it doesnt work
does changing our your small script for what I put change it at all?
you should always put any ui toolkit related code in OnEnable as that's when it is fully initialized
OnEnable comes before start right
nope.
yeah, but every css change you make will disable and reenable the object
so if you want your code state to persist after tweaking uss values, you should put it in onenable
Good look. Just fixed a lot of stuff from that.
my structure is this. why is rootVisualElement null?...
probably show inspector SC + script here also
inpector + NewInventoryControl
you have root declared above as a VisualElement?
yeah
If you store element on ui document - keep in mind that it flushes whole hierarchy on disable
Each time you enable object hierarchu is instantiated
okay. One minute, my scripts can't find the root element of the UI Document, but input events work on the UI document. I restart Unity, and now most of the scripts find the root element fine, but input events break. I feel like im going insane
Anyone got theme style sheets working? I'm trying to style all buttons but cant get it to work.
My .tss file:
/* TODO: why not applied? */
.unity-button {
margin-left: 0px;
margin-right: 0px;
margin-top: 0px;
margin-bottom: 0px;
}```
🤦♂️ apparently there is a dropdown where you have to select your theme in the UI builder
yep, different UIDocuments can have different panel settings
I don't quite understand. Do tooltips work in Play mode?
or build?
so far they only work for me in UI Builder
literally everything else doesn't
They are only for editor it seems. https://forum.unity.com/threads/tooltips-in-ui-toolkit.912896/
this is thread from 2020
almost 3 years passed 😅
yeah, but probably nothing happened
Yup editor only but at least the tooltip field is still available and useful at runtime so pretty easy to make your own
some cool stuff is at works
All code required to make this UI:
public partial class TestViewModel : ViewModel
{
[RelayCommand]
private void Increment() => Counter++;
[ObservableProperty, NotifyPropertyChangedFor(nameof(FontSize))]
private int _counter;
public StyleLength FontSize => Counter;
}
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements"
xsi="http://www.w3.org/2001/XMLSchema-instance" engine="UnityEngine.UIElements" editor="UnityEditor.UIElements"
noNamespaceSchemaLocation="../../../../UIElementsSchema/UIElements.xsd"
schemaLocation="UnityEngine.UIElements file:/F:/UnityProjects/Packages/ECSMVVMToolkit/UIElementsSchema/UnityEngine.UIElements.xsd"
editor-extension-mode="False">
<ui:VisualElement style="flex-grow: 1; font-size: 70px;">
<ui:Label text="#Text"/>
<ui:Label text="Tooltips don't work in runtime :(" tooltip="#Tooltip"
style="background-color: rgb(255, 255, 255);"/>
<ui:Button text="Counter" view-data-key="{@IncrementCommand}"/>
<ui:Label text="$Counter={Counter}"/>
<ui:IntegerField label="Counter" view-data-key="{%Counter}"/>
<ui:Label text="This text font size is bound to Counter" view-data-key="{^style.fontSize=FontSize}"/>
</ui:VisualElement>
</ui:UXML>
how do I make it so an entire background you can click and do something, but if you click on any element not-background it doesn't do the background button event?
Any way to correct the difference between whats show in the ui builder and ingame? It looks awful in game.
Hi guys I need help to make a coin for my game the coin name is "DIRHAM" and it's grey I don't know how to design it
Make sure to set the UI builder theme to be the same as ingame
UI builder defaults to the editor theme
What about the style causes the transparency to be out of whack? I'd like to correct that.
This kind of looks like bloom? Not sure how bloom can affect overlays
There is currently no preprocessing for UI, I believe.
Maybe its due to blending with the background?
You can see a little bit of overlap with the background and its still different on both.
Try setting the background in the builder the same as ingame, assuming the theme is also the same
Tested that, it still looks fine with unity default runtime theme.
Also, disabling all post processing makes no difference.
Is there something I can put in a them style sheet to fix this?
wtf, this button doesn't work at all
tryBackButton = root.Q<Button>("tryBackButton");
if (tryBackButton == null)
{
Debug.Log("backbutton null");
}
tryBackButton.clicked += GoBack;```
void GoBack()
{
//MainMenu.instance.CloseMe(root);
root.pickingMode = PickingMode.Ignore;
root.style.display = DisplayStyle.None;
Debug.Log("backclicked");
}```
its not null
and not clicking
Test it with logs. Whats the picking mode on it set to initially?
Oh. I see you have. I types that before you updated your message.
Perhaps another element is ontop of it.
yerp that was it apparently
Is there a way to make an event such as PointerUpEvent to prevent the same event from triggering on something underneath the triggering element?
Evt.StooPropagation
Ty
How do you make animation for the whole asset (like fade-in/out)? Do you have root VisualElement that gets animated or you can somehow animate asset?
So I've got some drag and drop functionality using this to identify droppable slots:
private bool OverlapsTarget(VisualElement slot)
{
return movableDisplay.worldBound.Overlaps(slot.worldBound);
}
How might I improve this to prevent it from observing a slot if the slot is entirely hidden behind some other third panel? I have a popup inventory panel and I don't want it to be possible to slot into "hidden" slots.
Hello,
I'm a beginner on unity and toolkit and I'm looking to know if it's possible to control the toolkit interface with a joystick. If so, how can I do that?
I need help with UI toolkit TextInput.
In the UI builder page the sizes look different comapred to the simulator window.
Also while in play mode the text entered inside the text input is not visible
Here is the comparison.
Text looks small in the toolkit window compared to simulator and the input section is also very different in size
did you set proper theme in ui builder?
I have only one option in that
This one right?
well, you are meant to create your own, but for testing this works
also
check whether window size matches
Ohhh I had no idea we were supposed to create one also.
Some tutorials i followed did not mention that
It is on match game view
this works too
How do i access it?
Sorry a bit too clueless here
it's in the manual
first pinned link
Great
Will check it
Hopefully it gets resolved
How can I repeat a background texture?
It's repeated by default
To modify uv there's a style property
It wasn't for me
Odd
I had to add background-size: contain and background-repeat: repeat-x
For some reason those properties aren't visible in the UI builder
Ui builder is meh in general
Just s preview tool
it also misses tons of ui elememts
Like multi column list or tree
and etc
Those are just for editor usage though right?
No
They are part if runtime engine
I have a pretty long scroll view and no matter what I set the size to, nothing changes how fast the scroll is (incredibly slow). Any advice on making it scroll faster?
oh yeah, I'm struggling with same problem
I suppose bug report should help
there's also annoying bug with scroll color
which gets different in runtime compared to ui builder
man, this problem is driving me up the wall. Sometimes, when I start the unity editor, I don't get any input on my runtime UI, but other times, I do. Last time I got it to work, it was after I had deleted the library. I wonder if that could be part of the issue? Should I file a bug report? I'm not sure how to reproduce it, though...
create new project and reproduce
if it reproduced - file a bug report
Is there a list of all pre-built visual elements somewhere?
I never know which ones are runtime and which ones are editor only...
I'm guessing it's this one https://docs.unity3d.com/2022.2/Documentation/Manual/UIE-ElementRef.html
manual
yes
Although it doesn't seem to tell you if it's runtime compatible
My screen was cutting of the namespace field 😅
Any ideas why I can't drag an existing UXML asset into the UI builder to instantiate it as a template?
that just doesn't work for me
you can
you drag it from UI Builder panel
It's faster but is still missing features
and the authoring is completely different
I'd recommend just experimenting with it a bit and seeing yourself. If you do frontend work you'll at least find the markup language and styling parts familiar
Yes, VisualElement has a RegisterCallback<T> method, where T is the event type, e.g. ClickEvent
If you want inspector support for binding you'll need to add that part yourself somehow, since the visual elements aren't part of the hierarchy
trying to get sliders to display correctly, but they always seem to want to scrunch up and not show the slider bar thingy...
Hey everyone, does anyone know if it's possible to detect mouseover events on buttons built using the UI Toolkit? I'm trying to trigger a sound effect on mouse over
Nvm, I figured it out:
buttonStart.RegisterCallback<MouseEnterEvent>(TriggerSound); and then create a custom method that receives a MouseEnterEvent as an argument for future reference.
UXML is a one way format. You can consider it for authoring only. When it's instanced it's just managed objects, no UXML.
You can instance other UXML (VisualTreeAsset) into the hierarchy from what you parsed from JSON or you construct it all via C#.
Okay?
My point is that UXML is not the runtime format. You can modify the hierarchy at runtime as much as you want via C#.
You are misspeaking. UXML is the authoring format, and the UI document is not represented by UXML, nor can be entirely converted to UXML at runtime
The UI document is often created by UXML, but it's a one way conversion
I've got some drag and drop functionality. Is there a nice way to bring something "to the front"(what would be z-index in css)? It doesn't look like z-index is an option currently.
Reordering in hierarchy doesn't work for me because it messes with some Events and it needs to have 100% width/height in its style due to it's dynamically sized parent so it is massive when I move it.
Is it perhaps possible to make a custom rendering call in LateUpdate to make it draw ontop of everything else?
VisualElement.BringToFront
That only brings it to the front within its own local hierarchy. So if you have an inventory system where you want to drag items around, it doesn't quite work for all slots after the starting slot
You can have everything as one hierarchy
It is all one hierarchy, but if the thing I'm moving is nested within slot 4, it will be above 1,2,3 but under 5+
Alternative - move your element to separate ui document and modify it's sort order
That's what I have now and it feels janky. Thanks! Just thought I'd see if there's a better way of doing this.
This is pretty much having element in root
So if you want onw hierarchy - that's the way
hmmm i have no idea why i am getting this error...
any ideas?
here's the ui builder and a link to the code in pastebin
pic 2
https://pastebin.com/xfriTZS0
pic 1
https://pastebin.com/Zb7k00hq
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.
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.
nvm figured it out was looking at the wrong "template" and gave it the wrong binding
hi, so I have a tile-based map, which is being parsed into a grid-like system. My current problem is, how do I go about scaling this according to the map size? And is it possible to keep the grid cell size, while resizing the UI?
UITK with world space is pain
I suggest to just use uGUI
the map parsing has not been a problem, the only issue I have now is that objects added on runtime don't conform to the flex align settings
the square in the top middle part is the "template" object I am recreating via code
yeah, it's not suitable for that basically
most style attributes only exist in UXML
and are resolved only once on Instantiation
in runtime they will behave a bit differently
then in what cases would you ever want to use the ui toolkit then?
only for static menu screens and UI?
I might be misinterpeting what you're saying, but this issue above isn't related to world space
the most valuable things that are missing in UITK rn:
- proper text rendering (there are some limitations rn)
- world space
- materials/shaders
it's when I try to add new VisualElements to a container
🤔
What are you even trying to do?
Is that TileMap on your screenshot or everything is UI?
it's all UI
oh
for (int i = 0; i < size.x * size.y; i++)
{
VisualElement newTile = new VisualElement();
newTile.style.width = tileSize;
newTile.style.height = tileSize;
newTile.AddToClassList("slotIcon");
m_SlotContainer.Add(newTile);
}```
this is essentially what im doing
yeah, that part might be tricky, especially when you start testing different screen dimensions
are you relying on pixels or %?
pixels
if you want to force tiles to a fixed size you can try adding max-width/max-height
thats not the issue
the issue is that its not aligning properly within a container
if i copy paste the elements, they align like this, which is what I want
you might want to go with % then
but when I do the same thing through code, this happens
that's the only way to keep it dynamic during screen resize
that's a fair point, but still not the origin of my issue
it kind of looks like you're not adding them to the right container?
the ui debugger is your best friend there
compare the styles on both the container and the tiles with the copy-pasted method and see what is different
yeah looks like I was just being dumb lol
was adding it to the root instead of the container
thanks
and also thanks for the feedback on this, will definitely be looking into doing that
I'm trying to make animation logic when switching between menus (for example from main to settings). Is it better to use tweener or try to add uss classes at runtime?
I have developed a MVVM data binding for UI Toolkit with full Localization support
https://github.com/bustedbunny/com.bustedbunny.mvvmtoolkit
great job!
is it possible to change the USS from a C# script
Is there any event that tracks adding to hierarchy?
I am trying to make custom radio group
and I need a way to obtain all children that will be added after construction
yes, background style supports it
create a circle visual element with infinite border radius
and then register it to all pointer up/down events
this will make your VE a perfect circle
no matter what size it has
otherwise you are fine just setting a very huge number
judging by description it's a custom field for us to use however we want
are you talking about my package
?
Has anyone else experienced a huge increase in build size after adding and using UI Toolkit? web build.data is 167.97 MB and it's a single scene with minimal UI elements. The prev file size (before adding and using UI Toolkit) was 26MB.
it's possible to have inline images using rich text in the UI Toolkit?
don't believe you can. Besides, even if it was possible - image path would be like 50 symbols long. Not very good for inlining
After searching a little, I figure out how to do this, it's basically the same thing as we normally do with text mesh pro. Just need to create SpriteAsset, and put it in a UITK text settings
thanks!
Hi there, does anyone know if the Unity UI Toolkit can completely replace UGUI? I've missed some things, especially a tool for making interface animations. In these aspects, can the UI Toolkit already replace UGUI?
no
world space UI is uGUI
and I don't believe there's any better solution
and how about ui animation?
Hi, I'm using the UI Builder to create UI for my new project and was wondering if it is possible to add components to Visual Elements, so when I clear and add sub elements, they can handle their own interface logic. Or more like VisualTreeAsset's, hence uxml objects you open to edit in the UI Builder.
UI builder is just UI for modifying .uxml file
as for components - you can add manipulators
well I'm trying to create a whole menu system with the UI Builder, including settings and etc. So each button needs logic. My thought so far was to use VisualTreeAseets and add/remove them based on button clicks.
but so far I only have a main MenuControler script attached to the UIDocument Root.
it would be nice if I can somehow just add the Visual Element "sections" replacing certain parts of the UI with ´Clear() and Add(...CloneTree()).
and each "template" have their own monobehavior logic
or am I going about this wrong?
I'm not sure what exactly you are trying to do
Like I said, create a complete Mainmenu with basics like settings and etc
but obviously certain elements need to change to go through setting menus
but if you want some good addition to UI toolkit:
https://github.com/bustedbunny/com.bustedbunny.mvvmtoolkit
this way you'll have easy way to bind logic through uxml
yeah thats kinda what I mean.
natively UI toolkit does not support binding in any way in runtime
everything requires code from behind
but I guess basically I just want the templates, like a VisualTreeAsset to be paired with a component
ahh
that makes sense then
damn... so when ever I replace a sub-interface element with a certain uxml asset.. I need to manually give it a component o.o
I think you should go over UI toolkit manual first
I feel like you are misinterpreting how it works
2022.2 version of manual is reaaally good
ok
Sorry, but I'm starting to get confused. I have watched multiple vids on how people are using the UI Toolkit and read through most of the docs, but everyone is doing something else. Is there no simple "meant-to-be" way to change the state of the UI and give it logic with the Toolkit? Like when pressing the settings button in a menu menu, the existing MainMenu is removed and adds the settings UI with according components/logic to handle the sliders/buttons?
Hey there guys. I have an inventory and I want to drag items out of it. Each slot has a visual element and the problem with the code I have is that if i move the mouse too fast I will lose the Icon. Basically it stops updating the dragged Icon position(it stops).
draggedIcon.RegisterCallback<PointerMoveEvent>(OnPointerMove);
private void OnPointerMove(PointerMoveEvent evt)
{
if (!draggedIcon)
{
return;
}
draggedIcon.style.top = evt.position.y - draggedIcon.layout.height / 2;
draggedIcon.style.left = evt.position.x - draggedIcon.layout.width / 2;
}
And the class is a Scriptable Object. Tought a Coroutine could solve this, but I cant use that. Does anyone know another solution to update its position when it moves too fast?
no meant to be.
But since UI toolkit is very similiar to XAML, HTML and CSS. It can be worked through existing GUI patterns
Model-View-Presentation, Model-View-ViewModel and etc
my framework brings the best out of MVVM
I'm trying to make a style for my slider, so the Label only takes on 100px and then leave the rest for the slider itself. In flexbox (HTML) that is easily achieved by setting flex: 0 0 100px - i can't seem to change anything though - i can change grow/shrink/auto but nothing happens?
I can change the color and font size though - but the width of the label i can't change?
my selector is .unity-slider Label and like i said i can change lots of things, just not the size or flex properties
found it:
.unity-base-field__label {
min-width: 100px;
}
It seems it had a min-width set to something more 🙂
is there is any hacky way to make UI_Toolkit world space?
btw solved it
problem was with the draggedIcon.RegisterCallback<PointerMoveEvent>(OnPointerMove);
m_root.RegisterCallback<PointerMoveEvent>(OnPointerMove);
will solve
m_root being the main uxml covering the all canvas
there is a workaround by displaying the ui as render texture
@lean horizon
guys noob question
how do I change value of visualElement width in c#
wanted to do something like _visualElement.style.width.value = something
i cant
Is it possible to render a UIDocument on a plane or something?
PanelSettings has option for Target RenderTexture
but having so many RenderTextures and panels will certainly be no good for perfomance if it's world space you after
You do like you would in the properties window, so if it works to change the width value in the properties window, then yes, that is how you do it with code as well. Often though, you want to use the Flex layout instead - depending if you want specific width or just want it to fill out some space
If the value does not change when you do it in code, then try if it works in the properties window - chances are, it doesn't work there - then find what properties work first, then do the same in code. Often the width of an element is controlled by the parent if in a flex layout
Sorry just respond now. Apreacciate so much you answering. Thanks a lot. If i change the width in the window it works. This is for a mana bar. I want to change the inside Visual Element according to my ManaManager. If I play a card it wastes like 10 mana, lets say 10% of the width. But i want to update it after with time, increase it. And thats why it needs to be in code
Btw i solved it
It was working. I was just querying the visualElement for the _manaBar before it was in the main VisualAssetTree
so it couldnt find it
Is there a way to tint BackgroundImages in a VisualElement in a color?
{
value = new Background
{
sprite = img,
},
keyword = StyleKeyword.Undefined
};
backGround.style.color = new StyleColor
{
value = Color.green
};```
this sytle.color wont have any effect. the background sprite stays white
do i need to create all color variations as extra sprites now?
imageTint I believe
or smth like that, take a look at UI builder, it has it exposed
right below texture selection
ah its style.unityBackgroundImageTintColor in C#. thanks!
got another basic question. how do i make a visualelement not grow with its children?
it depends on height/width.auto
you can define it in % or px
or with initial
so it's fixed with initial size
Allthough I'm not sure on later
never used it
@hallow fjord btw, have you seen my UI package?
I developed runtime binding for UITK with full localization support and many other features
https://github.com/bustedbunny/com.bustedbunny.mvvmtoolkit
yes youve shown me. but i need it for editor
the green pills are a scrollview
i want the scrollview to not scale up the parent container with more items
so that there would actually be scrolling
That should work that way by default
you define scroll view size
and it never changes
thats how i wanted it to look. but to make that screenshot i had to set the width of the VisualElement containing the scrollview to a hardcoded value.
are you setting it up in uxml or pure c#?
hmm
Check whether you add to scroll view correctly
btw, now that I thought about it, my package should work in editor
you'll just have to manually create instance of binding through code and that's about it
scrollView.mode = ScrollViewMode.Horizontal;
scrollView.horizontalScrollerVisibility = ScrollerVisibility.Hidden;
scrollView.contentContainer.style.flexDirection = FlexDirection.Row;
scrollView.contentContainer.style.flexWrap = Wrap.NoWrap;```
thats my scrollview and i just add to it with scrollView.Add(someElement)
but the scrollview should not be the problem here. the visualelement containing that scrollview is. how do i avoid scaling it based on children but scale it based on parents?
make it's size fixed
100% width
for example
and what happens instead?
nothing
then waht's the problem?
my scrollview still scales the parent visual element and with it the whole node
set all the child to 100%
visualElement.style.width = new StyleLength(new Length(100, LengthUnit.Percent));
// do the same to the height if you prefer to
then (optionally) set the parent to a fixed size in % too
parentVisualElement.style.width = new StyleLength(new Length(50, LengthUnit.Percent));
so 50% here will only apply to the parent but it will be 100% to the children
How can I make an image behind the button and make it as child of this button?
Thanks for trying to help me. sry for late answer.
The first node where no scroll view is added is how i want it to be scaled.
The second node with scrollview (where parentcontainer is set to 50% as you said) is still scaled as if all scrollview elements are visible... im so confused. (the green items are the elements in the scrollview)
are you sure you're styling the correct VisualElement?
there are not many involved.
The hierarchy : Node-ContentContainer-QueryContainer-ScrollView
i set the QueryContainer to 50 %
the scrollview somehow still scales the Node
Im a UI noob so tell me if im wrong here but scrollview should be contained within QueryContainer right?
whats the setting that allows a childelement to increase the parents size?
i mean what causes the node to scale when for example one of the PortLabels in the inputcontainer would overflow
when i set position to absolute it looks like this:
scaling would be correct like that but position is obviously wrong
seems like i need : style="max-width:fit-content;" how do i do it in USS?
Hello! anyone know if there is a video element, or if there is a way to add video in UI Builder?
RenderTexture
is supported by styles
and you can render video to it
thanks I'll look into it
Wow. Who decided it would be a good idea to have backspace delete unsaved UI Builder VisualElements without warning 😄
missclicking into a textfield and hitting backspace just deleted all my test setup again :S
just use uxml instead
supreme editor
im pretty sure scrollview is bugged. at least the horizontal version
here is my repro in UI builder :
paste uxml instead
Both "nodes" (blue and green) have the same settings. the only difference is the green one has a visual element as the child in CantScaleNodeContainer and the blue one has a scrollview
CantScaleNodeContainer is set to 100% width. so it should keep the size of the parent. (the node)
but in the blue node the Node is actually scaled as if CantScaleNodeContainer was set to auto width
you have way too many styles attached
to scroll view at very least
align-self: flex-start;
this one might not do what you want
and you might want to control it's position through parent instead
yes i just tested if anything made a difference. for my scaling issue it doesnt matter what is set there
so what's the problem? ScrollView is bigger than you want?
yes scrollview is scaling up its parents even though it should be contained within their parents.
and its different behaviour than a simple visual element
yes. and it may not drive the size of the parent.
it doesn't do that
which is usually achieved with setting the container to 100%
it does. else it would only be 200px in the sample
which is the width of the node
it would have the width of the green node
it is scaling the node. even though its supposed to have 100% of the parents width...
you don't show how it looks 😅
huh? what do you want to see?
question about the proper way to handle switching menu's like in a main menu to the settings area. following a class for the UI Toolkit for Runtime: he uses a custom "panel manager.cs" with a root "UI" GO, and then depending on buttons pressed , the panel manager will enable/disable the according children game objects that have UI Documents on them. Is this in 2023 how I should do this?
kinda hard to see but scrollview is slightly bluish
I can see it
so I don't see how anything wrong with it
seems like it's saying in bounds
of it's parent
yes its in bounds but it did scale the parent
parent is set to 100% too
in debugger as well
didnt i show that the bug is there with my repro?
if not can you explain to me why the blue node is bigger than the green one
when none of the child elements are supposed to scale the node
because scroll view does not rely on children
that's the whole point of scroll view
its exactly what i want to achieve. i want it to ignore the children so i can actually scroll through. but its not working. the children do somehow scale the container
when i delete the scrollview from the blue node :
both same size
sec i encountered another strange thing -.-
I CANT DEAL WITH THIS omg
just by dragging the scrollview over the hierarchy this happens
the green node has no settings changed but now it ignores its set minSize of 200px
okay bug nr 2 aside :
scrollview added again. nothing changed all good
adding elements to scrollview and setting it to horizontal
its supposed to be as big as the green one still
idk what you are doing
I just tested
my scrollview matches exactly size of container
with only style
flex grow 1
same for horizontal
I use % to control size
pixels don't work
that's the only thing I noticed
that is unusual
have you given the elements inside the scrollview a minsize so they overflow the scrollview?
else you wont need to scroll
yes
but thats where my issues start
children of scroll view are 500x bigger than it is
can you create a container that has size 200x200 and inside of it create a scrollview that stays 200x200 but the elements overflow?
I don't use pixels for sizes
they don't scale with screen
only text pixels scale
yes but for arguments sake. containing the scrollview inside the outer container without scaling it
thats the whole point
no, pixels didn't work for me
Let me re-ask with the current Info I have gathered about the UI Toolkit, I see two options currently about navigating through a menu:
- Create a root UI Panel Manager that registers to certain buttons and enables/disables certain game objects that contain a UIDocument and script for handling the logic of that template.
- Create a root UIDocument for that scene and dynamically clear and clone templates based on buttons pressed and also having to add script/logic components for the loaded in UI.
These are are 2 variants I have seen people doing on Youtube, but these are from over a year ago and many components they use dont exist currently.
So what in 2023 I currently the "proper" way to navigate through UI and dynamically change its content with the logic it needs.
- first approach disposes and recreates hierarchy every enable/disable of uidoc. Less memory usage, super slow instantiation
I use approach of pre-creating whole hierarchy and just enabling/disabling it through display style
as for navigation - no right or wrong approach
even in non-gamedev GUIs every framework uses it's own implementation of navigation
so it all depends on how you want to do it
well the way I understand it, the new UI Toolkit is meant to work like html/js, and when I designed websites, I would use JS to replace certain sections of the HTML, which would make me think I should replace sections of the VisualTree'S
I am currently developping a framework for UI toolkit to use best practices from GUI development
https://github.com/bustedbunny/com.bustedbunny.mvvmtoolkit
this is MVVM, so potentially oyu worked with it
already
for me it does not work as soon as the elements in scrollview have a fixed size and overflow.
no matter how the outer container is setup. can be in % too
try to remove all styles in your scrollview and leave only flex grow
yeah, but I have a uncertain feeling using your toolkit to base my new project on. If Unity made a whole new UI system, there should be a logical complete thought behind it
well, they still didn't make runtime binding (only for editor)
and no one really answered about proper pattern to use
but if you use naked UITK
I belive that would be MVP
with pretty much everything having code behind
the only thing they mentioned about proper pattern - styling
they use BEM
and recommend to use one as well
@gusty estuary , what do you think your future support will be and do you think the UDevs will implement your work, or something based on it in the future?
hehe yeah
ok, thank you for your work, I will read your docs and see if I can implement it
how might one get :hover to work on elements if there's another element between it and the mouse? is there a way for hover to work without setting the picking mode to ignore for the topmost element?
@gusty estuary oof took me nearly a full day to get this working inside nodes now.
here is the solution that worked for me if you are interested: https://forum.unity.com/threads/scrollview-scaling-issues.1395742/#post-8782246
And now i dont like the look of it anyways 😄
take a look at uitk manual
styling section
it has explanation on child selectors
I want to show a few dots when text doesn't fit into a line, I've tried setting overflow to hidden, Text overflow to ellipsis and Wrap to no wrap. This seams to somewhat do the job but it hides the line below aswell, what am I doing wrong?
I think it's a bug
if you could check if it's reproducable in new project - bug report would be appreciated
Sure, thanks for clarifying it's a bug!
that's not 100%
but it certainly sounds like very edge case someone didn't think of
hello, I'm new to the whole UI Toolkit system, I'm trying to make a hud and menu manager for my game.
I'm trying to move some of the Update HUD stuff over to the UI, and let the monobehaviours ask for it, but I'm not sure if thats good practice.
Could I get some tips? 😅
have you worked with UI before?
are you familiar with mvvm?
Sorta yes. I usually do more mvc
https://pastebin.pl/view/f89ffecf -- Code I have at the moment
Pastebin.pl is a website where you can store code/text online for a set period of time and share to anybody on earth
I am developping mvvm toolkit for UITK if you are interested. So far I already have support of data binding and localization.
https://github.com/bustedbunny/com.bustedbunny.mvvmtoolkit
other than that - there are no patterns Unity defined to build UI with UITK, so... mostly people just do their own thing
and it always involves a lot of code behind
since built in binding doesn't work outside of editor
I assume this can compile to WebGL? 
oh yes, I am developping a webGL project while doing it 😅
so I ensure it's fully supported
@gusty estuary think I can reuse my existing uxml? Its a bit nested.
I assume all I'd need to do is set up the text bindings on the UI Builder(?)
My framework assumes you split logic between different .uxml difles for each screen or it's part
but technically
you can still nest everything at the same file
it's just not going to be very perfomant
how so?
It uses INotifyPropertyChanged attribute
allthough...
binding happens to nested object instead...
yeah nvm
perfomance will be same
Bindings are set up in .uxml
you can use Builder yes
but generally I suggest to use simply text editor alongside, since UI builder is really underdeveloped (many built in elements are not even present in it)
How does one install?
my lad, have you considered openupm?
can I add package from git url instead? (Im participating in the game jam)
I did, but I haven't released a stable version yet
ah
as I constantly push new features
You can try, but I never tested
is there a way to write my own visual elements such that if i bind a Scriptable object to the upper most visual element each child element binds the correct properties?
essentially what do i need to do to cascade that binding
focusing a TextField from code using .Focus() is not selecting the text, neither using .SelectAll()
could someone help me to achieve it?
See if setting myTextField.delegatesFocus = true; helps
the elements are getting focused properly, the problem is that it doesn't open the text editor engine again (no caret, no selection, no keyboard input...)
I've already tried with .delegatesFocus = true, .visible = true, .SelectAll(), .Blur() and .Focus()
Which version of Unity are you using?
2021.3.16f1
Ok - I think Focus() is working for us fwiw. I'd suggest double checking it still doesn't work in a new scene and make the simplest repro you can - if it's still broken, submit bug with repro to Unity. If it works, my guess would be there could be another listener (eg FocusInEvent or something) causing eg a change in a listview or some indirect change of selection. I'd also suggest making sure the textfield.isDelayed is set to true for testing it too.
im using a custom text field with placeholder that inherits from TextField using RegisterValueChangedCallback, RegisterCallback<FocusInEvent> and RegisterCallback<FocusOutEvent> but im not modifying its focus on them
If the problem is only with your own custom inherited version I can't offer much advice except do be sure that you're correctly calling the base constructor with whatever parameters are expected.
i.e.
{
public MyTextField():base()
{}
}```
No not necessary when there's only one constructor in the base class without args - I'm not sure about TextField but it's caught me out before when there have been args and were being instantiated from uxml
it is not working either with a standard TextField
but it works fine if I toggle the enabled property before focusing on it like this
textField.SetEnabled(false);
await UniTask.Yield(PlayerLoopTiming.LastPostLateUpdate); // Wait a frame
textField.SetEnabled(true);
textField.Focus();
If I have a selection of possibly overlapping visual elements and I want to determine which one is "on top" how could I determine their position in the hierarchy? I don't see a method or documentation on this.
And I mean relative to the root. child.parent.indexOf(child) won't work.
Z-Index would be really nice to have :/ even if it was just a readonly computed field.
I'm hoping that calling .Last() on a querybuilder will work.
That did appear to work.
Is there a way to force a ui element to resolve its size immediately? Let's say I have a tooltip and dynamically resize it based on the text inside that tooltip, the text will change immediately but sometimes the size remains at its previous size for a frame
there is a method that notifies that hierarchy is dirty
you can notify root element
Found it, thanks!
When using a FontAsset In Label, no color is applied.
Is this supposed to be like this?
rich text does not work with custom fonts it seems
And using Font, sometimes works fine, but sometimes it throw the exception, MissingReferenceException: The variable m_AtlasTextures of FontAsset doesn't exist anymore.
should I not use rich text in ui-toolkit?
so with toolkit, for images, how do I use the sprite atlas? It doesn't seem to be an option.
tried many different ways, all are pretty inconvenient, best way is using a PNG sprite sheet
I wouldn't say so
world space is under consideration for UITK so
potentially it would be meant to use both
for different purposes
Happy to announce: I made a lot of commits into my package since last time I mentioned it:
- Now it supports nested localized strings
- Now there's burst-compatible wrapper for Messenger
For those who don't know about it: I developed MVVM runtime data binding for UITK with full Localization support.
https://forum.unity.com/threads/ui-toolkit-mvvm-data-binding-with-full-localization-support.1397308/
https://github.com/bustedbunny/com.bustedbunny.mvvmtoolkit
The manual mentions to do it this way so it should be fine. I would expect the "none" display styles internally to be moved to some other list so it doesn't get processed. I'm not aware of an alternative other than unloading the document or using several gameobjects, one for each panel/screen.
In general: don't assume, measure! 😉
In the meantime trust what Unity is saying you should be doing ...
style.display makes VE ignored when building or propagating events.
As alternative - you can literally cut it away from hierarchy and re add on demand.
VisualElement without attached panel will only take up memory afaik
Maybe a bit complicated problem, For custom control visual element, How to add a list trait, for example, a scriptable object list.
UxmlListAttributeDescription is not available
When I newed a custom control, using another script change that list, it seems not binding. that list I set to public static
Hence, I am thinking using trait
Like a popwindow,show the filtered list, the list is keep update by another script
Tried three days, always said the object reference problem
Can this custom control be made by UI Toolkit?
I found another way, visit the custom control visual element, then add a list to it. This seems the easy way to do it, and more flexible
when I newed the custom control in other script, just visit the new one , then add the list
This way errors should also be less
How can I make a Text Field always focused?
I don't think that's intended at all. What is your actual goal?
I want to keep a Text Field selected while scrolling and clicking through a List and a Treeview
what is actual goal behind it?
Technical implementation you ask for will remove any gamepad/keyboard support for navigation
Its a editor pop up window to generate files
You should be able to edit the name while selecting a Category and Template
What's the intended way to update UI toolkit elements if I need to do something each frame? I can't find an update event or anything, is there something better than just externally calling the function each frame from somewhere?
The only real native thing I can think of is doing something like schedule.Execute(...).Every(0), although I'm not sure how that interacts with the update loop
Also, are schedulers automatically cleaned up if the element leaves the hierarchy? I haven't used them much
well, the intended - you attach monoB to Document and query your elements and then do your thing in Update
but I'm curious what exactly do you have, that you need update?
e.g. updating values on a progress bar
generally UI should never have update, but instead be fully event based
ooh
I solved it by using async methods
Since it's a dots project I feel like just setting the value is easier than implementing events for everything
my progress bar view model provides IProgress<float> object
after I get reference to it, I just report current progress to it in async method before yielding
most Unity async operations have a property to provide current progress
well, considering it's ui - far easier way is just having task that does it
How so? The visual element can just read the value from the entity
And I checked earlier, the scheduler updates each frame, and automatically de-registers if the element is removed from the hierarchy
because if it's just task - then it's as easy as slapping async to method
and doing it all just inside of it
let me show some example I guess
Yeah I get that, but how is that easier than a method that is just called once per frame
(This is without events)
public static AsyncOperationHandle<T>
WithProgress<T>(this AsyncOperationHandle<T> operation, IProgress<float> progress)
{
TrackProgress().Forget();
async UniTask TrackProgress()
{
while (!operation.IsDone)
{
progress.Report(operation.PercentComplete);
await UniTask.Yield(PlayerLoopTiming.FixedUpdate);
}
}
return operation;
}
since UI doesn't have one, you'll need either monoB or system
system is overkill
it does? Is it exposed?
ooh
that's what you meant
I see
didn't know about it
It also seems to automatically be disposed if it leaves the hierarchy
I don't have a lot of UI so I don't want to over engineer it
interesting
you could use Until
progress >= 1.0f
or something like this
The progress bar is health, so it's not a thing that is done at some point
It just needs to update to the current value (and animate a little)
ah
then I guess you can go on with system here
which retrieves proper instance in OnStartRunning
and then just updates value with change filter
this way you can even use SystemAPI
I'm not sure if I should have a single system to update all bars, or keep the update code in a custom visual element
well, if you have a lot of them
Since if bars can be created / removed during runtime the system would need to re-query the UI document (which wouldn't be a huge deal)
a system will be perfect
what kind of health bars do you have?
It's just generic HUD stuff, health, mana, etc
if it's singleton - then system is best
no, events are managed separately from style, with exception of display which will simply disable element alltogether
This is bad. It is a standard on css
Yes, this is the default.. the disposing happens once detached/removed from the panel
Hello !
Is there a recommended way to modify the default styling of a builtin VisualElement ? As exemple, I would like a Radio Button to display a Button instead of a toggle with the associated name next to it (similar to the EnumButtonGroup of OdinInspector) . Do you have any recommandation to achieve something like this without reinventing the wheel ? Thanks !
Manual has guide on styling which suggests a BEM approach, which Unity follows
generally you use TSS Themes
with your own style overrides to default Unity theme
Thanks for the answer ! I will look into it. I did'n found this documentation this morning.
if I want to show a particle effect
do I need to make a RenderTexture?
or is there a better way to do this?
Where can i learn uitoolkit responsiveness
Basically I have a VisualElement Inventory that has a background Image
and i want to have this inventory responsive to every screen but the image doesnt keep its aspect-ratio
How would you guys handle this:
hovering over "TargetQuery" expands the grey box with the ALL ANY and NONE Lists
that VisualElement obviously needs to get in front of everything else.
Its supposed to be some kind of ContextMenu
I want that Menu to be a Child of that TargetQuery VisualElement so that i can use absolute position based on it.
So what i would need to do now is to move the TitleContainer of the Node above the contentContainer. But if I do this i get that result:
the menu is in the front now but the order of the flex parents changed with it
So TLDR : How do i render VisualElements on Top without having them on Top of the Hierarchy?
you could put your VE at root
yes thats how unity does its dropdowns etc. Seems like Z-ordering is on roadmap but has low priority
for me its a little bit more complicated. i need to add the VisualElement to the Node, else the Zoom function does not work with it
guess i need to calculate the absolute position relative to the node coordinate space instead of the graphview
can i get the absolute position of one element based on another?
e.g the absolute position of the TargetQuery Element based on the Node?
{
VisualElement element = (VisualElement)evt.target;
var absoluteWorldPos = element.LocalToWorld(element.transform.position);
var node = GetFirstAncestorOfType<Node>();
var absolutePosInNode = node.titleContainer.WorldToLocal(absoluteWorldPos);
}```
why?
seems like very complex solution
can't you just make dropdown a child of element you clicked?
i cant add it as a child because then it does not render on top anymore
which was the original problem
i need to add it to the node (so content scaling works) but at the absolute position where the child is.
child always renders on top of parent
Yes I know. as I wrote unity has z ordering on roadmap. It's just a missing feature I need to get around.
How to track if style "Display" is changed on visualElement with callbacks?
I have a map editor for my game with buttons for a user to select what kind of items they want to edit onto the map. im looking to show the 3d objects on these selection buttons so the user can visually identify what they are selecting. It is a grid of buttons which means a lot of these 3d objects need to be shown at once. Is there a good way to go about this? I thought about potentially using a secondary camera and rendering the 3d model somewhere away from the main gameobjects and stuff but that wont work when i need to display a bunch of models for a bunch of buttons. not sure what to do.
Should I just setup a scene with a camera to take images of the models somehow?
or is there a better way?
I am using the new UI builder with USS.
I just ended up setting up a camera to take image captures.
anyways i have a new question.. does the IMGUIContainer visual element have an actual image property i can apply an image to? or just the background image property?
and also, i cannot programmatically change the background image of my IMGUIContainer element, here is what i am attempting
tileInfoImage.style.backgroundImage = Resources.Load<Texture2D>("D:/Strategy Game/Assets/Screenshots/Sea.png");
this doesnt throw an error or anything but it does show nothing on the background image, its just blank / empty space.
.label-style {
-unity-font: url('project://database/Assets/Block%20Square/Scripts/Editor/Fonts/COASBL__.TTF?fileID=12800000&guid=a598abb22c2113948b4bc28a6cb9e536&type=3#COASBL__');
-unity-font-definition: url('project://database/Assets/Block%20Square/Scripts/Editor/Fonts/COASBL__%20SDF.asset?fileID=11400000&guid=bc0163fd39f3dd048b3889989c489ca7&type=2#COASBL__ SDF');
``` how i can get the path like that??, using copy path by right clicking in editor wont give that path, thanks in advanced
edit: anyway im using UI Builder and assign the Font from there to get that path, but what if i dont want to use UI Builder just to get the "correct path"
then you have a problem. So far Unity was focused on UI Builder instead of text editor intellisense, so...
We are kind of stuck with combination of both
it's way easier to manage USS styles with UI builder compared to text editor as well
damn, for an easy editor script, sometimes i dont want to use UI Builder, but this url stuff drive me crazy, because even without ui builder i still need to open that just to know the correct path
okay thanks, hope they improve more, on next uodate
@dark blade btw, you might be interested in my mvvm binding package
https://github.com/bustedbunny/com.bustedbunny.mvvmtoolkit
btw if you only include the path, the next time UI Builder processes the file it will add the fileid & guids. So you can manually type eg:
-unity-font: url('project://database/Assets/Block Square/Scripts/Editor/Fonts/COASBL__.TTF');
-unity-font-definition: url('project://database/Assets/Block Square/Scripts/Editor/Fonts/COASBL__ SDF.asset');
}```
at least, that's been my experience and the technique I use
How do you animate transitions between screens (from main to settings for example)? Using Tweening library or using styles with transitions?
you can any way you want tbh, since there are no strict rules around navigation even in non-gamedev GUI application
but UITK indeed supports transition animations for this
allthough, their implementation could be tricky
for the moment feels like adding and removing styles with transition can make a headache
Check if there's transition trigger for display style
cause usually you enable/disable screens using this style
i know
if it does support it
there most simple animation that comes to my mind - using root screen's transform and just move it to side when none and from side to center with flex
the main issue is to how manage this animations. Create 1 style with complex animations; Create multiple animation styles and combine them with code and registrer callback on end to disable particular screen
Here comes the question with reusability
With tween library like Dotween i can make DoTween.To value like opacity but i need to create some sort of framework and thats quite time-consuming to be able create atom-based animations like opacityAnimation and reuse the functionality by tweaking some values while with uss i need to create opacity style for each animation
yea
I personally would rather avoid using code behind
and do it with styles
meanwhile nothing also stops me to adding some inlined animation options for all root screens
yea but my thought about tween library came after i could not understand how to add "pre-animated" state.
For example:
When switching Main to Setting I want:
Scale-out main screen;
Scale-in setting screen
Setting screen has to be in special scale, after add scale-in style and transition will come automatically
UITK animations are transitions
so you would want to define your pre state in a style
scale-in-prepare which will have scale 0.7 0.7
scale-in with transition scale 1.0 1.0
for example ```css
.disabledScreen { display = "None";
Transform.x = -1;
}
and when transition started remove style scale-in-prepare?
it would work but i don't know why but it feels odd. Need to try out styles on maximum and after consider should I shift to tweener
your defined animation will happen until previous style values meet new style values
idk, UITK is first UI framework I worked with, so... feels ok to me 😅
(well, after IMGUI)
Heh
I get that this system realizes to reusable UI document files but is there a way to create customized UI components that can be reusued across not only UI document but many? For example if you want to have multiple UI documents for multiple different scenes but they all have access to a customized button component.
yea - either through shared uxml's or through your own custom VisualElements
You can only load a single uxml file to a UIdocument/scene though right?
Sounds like the custom visual element might be what I'm looking for
you can reference any uxml as a VisualTreeAsset and then invoke CloneTree() on it and add it to whatever hierarchy you like.
Sounds overcomplicated for the solution, I think I'll go with the custom visual element route.
Thanks for the tip
Also do you happen to know if the IMGGui element has an actual image property or just the background image property?
Cus I can't find a bonafide image property. Makes me question the point of the IMGGui element its basically just a normal Visual Element with a different name.
🤔 sorry - not too sure I understand. The IMGGui element is mostly there to support the old editor UI - you can draw what you want in there but I wouldn't recommend using them unless you absolutely have to.
Basically just looking for a component to display an image.
just a basic VisualElement can display an image by setting the background property
I ended up using that IMGGui element because it sounded right
I'd suggest it's probably not what you want
Yeah sounds about right. Usually a background image property means that the container won't respect the image size so it could cut off the image. That was the concern
Speaking in terms of how web development stuff works.
I'd suggest experimenting in UI Builder to find what you need rather than doing everything from code - you usually need to set the background mode to what you want (eg scale & fit) and you often need to nest visual elements for more controlled alignment & sizing.
I have been doing that for the most part but that specific use case i needed to set things programmatically as i have a heads up display thingy that changes the text and image depending on what piece of terrain the user is looking at
but everything else is static and will be set in the UI builder
You can reuse uxml with template instance
but if you talk about specific VisualElement instances shared across multiple views - then no
also you can use as many UI Documents as you want
there is a way to use them in hierarchy, but I find this approach not very useful, due to the fact, that enabling of UIDocument fully recreates view from scratch, which is slow.
Is there a way to set a button index? I have a bunch of buttons in a single UI element panel laid out like so
pressing the D keys (using WASD navigation) goes in the order above
ideally it should work more intuitively than that, such that if you are on the top row of buttons it goes from "Terrain" to "Buildings" to "Units" to "X" (close) and if you are on the row below that then it would go "Plains" and then "Sea"
but it doesnt really work that way
I've tried googling this but there isnt any relevant answers as far as i can tell
I've also tried the "Tab Index" options and set them to
0,1,2,3
4,5
but that doesnt work either
A basic problem. I want to make a popUp custom control, when I make the window flex , it will share its width with other visual Element, which make it in the hierarchy, not hover , how to fix it?
I think may be store the buttons in a list<Button> , may this way can solve your problem. Button[0] : terrain, Button[1] : Buildings, Etc
I don't get how that would make the button selection work in a certain order
Then VisualElement.Add(Button[0]), should use for (i=0; i< buttonList.Count,i++)
Hmmm
I think first make a condition how you order the list, then do the circle add the buttons by index
cycle
This way all button children are arrange by its index
.
Make position absolute
And size manual
Thank you so much! it works
Is there a way to get all elements un a UIDoc that have Text available on them?
_rootVisualElement.Query<T>().ForEach
where T is TextElement
oh I see, everything that has text will be inheriting from TextElement
like Label, Button etc
kind of
some custom elements might implement text as well
but that would be on them
I am only using the unity ones, and the ones I made myself.
So if I know that I can make sure its correct
unless unity makes changes to that structure I will be fine
and that seems unlikely
I made runtime tooltips with full binding support
How do i add selectables for the drop down button?
Add all the options
Right now its just blank
this simply cant be the solution. there has to be a better way.
am i really to understand the ui toolkit is just so broken and incomplete that you can't simply configure the focus order on ui elements?
the more i work with unity the more i question my choice in using it.
Doesn't sound like my experience at all
just so frustrating to get the dumbest things working.
well i mean there is a difference. you CAN configure the focus order on things
but it doesnt affect the WASD/arrow key focus order
🤔
those will just be messed up no matter what.
are you sure your elements are sorted correctly?
im not entirely sure what you mean
open debugger
do you mean with the focus index property?
is there a specific debugger for ui toolkit stuff?
and if so where do i find that please?
i will check
ah okay i think i found it
on top right of game view
what am i looking for in here specifically please?
hover over elements in debugger
they will be highlighted
ensure everything is fine here
they appear to be in the right order, meaning that they are in order on the debugger
you want me to copy paste the uxml or a screenshot?
i just tried to paste it as text but it wont let me
so ill do a screenshot
thank you by the way for taking the time to help me
jeez, I hate UI builder, it brings so much garbage into code
i was thinking maybe learning to create uxml without the builder
but i figured since its a feature they have it should be fine to use it
guess not?
yeah, learning uxml is good. But you'll still have to rely on UI Builder for styles
is the name property being the same on multiple buttons perhaps messing wit hit?
im not sure if the name property is similar to the id property in html
neither Rider or VS recognize USS yet fully
i actually have been doing all the .uss stuff by hand
it's all in manual
since i understand css and its similar enough
still though looking at the above do you see anything obvious causing this specific issue?
well, from what I see - your buttons aren't just in a single list, they are parts of different containers, which messes with the way navigation works
also I'm not familiar with how tabIndex value works with it
well the idea was to go for a tab system
it's been fine for me simply without it
so a row of buttons for tabs that controls what tab content shows
but I never used buttons the way you did
my buttons always were just in single container
gotcha
thanks for taking a look. if nothing else that last comment there may give me some ideas.
maybe i can make all buttons in a single container but style them and control them differently how i need
is an extra pain in the ass but might be doable.
can anyone recommend a data-binding library for ui toolkit that's kind of in the spirit of WPF? looking for an ObservableCollection sort of thing that would work in unity. https://stackoverflow.com/a/73599517/9731532
I literally use CommunityToolkit.Mvvm, so it should be very familiar
cool, thank you
as of now though it's in heavy development stage though
currently trying to implement Localized asset table support
which is very tricky
yes
heavy development stage might though.
Be aware, I might push a lot of breaking changes until first stable version.
Hopefully though, all of those will only touch backend.
@gusty estuary in the section where code generation for the observable property is introduced, I think it would be useful to see what's actually gonna be generated. I'm gonna guess it's an event and a property, or a property that calls into INotifyPropertyChanged with the property name
just inspect other part of your partial class
it's native IDE feature
should be just ctrl + left click on type declaration
yeah I'm just reading the doc
I've run into a strange issue that I can't figure out.
I have a crosshair that I instantiate from a VisualTreeAsset, then add to the UIDocument root. Then I grab an element in the asset, set the position to absolute and move it (it's a crosshair). For some reason it's offset exactly one screen height from the top, and I don't understand why
From debugging the screen space and panel space values that are set for top and left seem to be correct
What's the UI Elements Debugger show?
It can be used for runtime UI?
Yes
Well that would have saved me a lot of time
I'm really confused. This is what I'm setting the bottom and left style to: (339.64, 112.00), yet the debugger shows this
values are slightly differently since I'm centering the element
But it seems to just invert the Y coordinate for some reason
That's where the log message is
What values are set to bottom and left in the debugger?
The stranges thing is this worked, and then I upgraded to entities .44, and now it broke somehow. I didn't touch anything UI related
There's also nothing UI related in my git changes, and this is one commit after it worked
I meant the UIElements debugger; I'm presuming they are what you expect and that maybe there's some border, padding, or margin that is messing with your expectations