#π§°βui-toolkit
1 messages Β· Page 26 of 1
so they don't even support rendering the UI on RT?
well.. that kinda sucks for any VR use then π
I have no idea if you can manage to get it onto a RT currently, I haven't heard of anyone doing it, but I also haven't looked
I'm not personally planning on jumping into the "this is not a feature" territory of UIToolkit, it's burned me before π
I just really dislike doing UI design work in actual scene, it's why I never wanted to use UGUI in the first place π
but yeah probably not the best idea to jump into "not yet supported" territory still π
Oh I totally agree that UIToolkit will be great and UIBuilder is a much better place. I'm just only transitioning for things where I know I am almost completely covered by UITK's offerings
UGUI is hell 
We do it. Works pretty flawlessly tbh - not sure why it isn't more well used & known. There's even an example for it with the bundle.
The main issue with using it in WorldSpace is the events - you used to have to hack a solution together especially if you're doing VR. Not sure on the current best practice though. Depends which input system you're using too I think.
is there a way for me to satisfy this error when creating PanelSettings from code?
guess I could just create a UIDocument prefab with the PanelSettings already saved
Is using the Resources folder for uxml/uss acceptable?
Oh it looks like there is no support for StreamingAssets loading raw uxml at runtime, so you have to use AssetBundle or Resources
And since UI assets are generally lightweight Resources is probably acceptable
acceptable? That is debatable. Some people consider not using resources folder at all is the only acceptable route, someone say barely use it, some say who cares use it as much as you want. I personally don't use it at all. If you are wanting to use "resources" in editor, there is also Editor Default Resources folder special name that EditorUtility.Load goes directly to first
As I haven't actually released anything yet though, unfortunately my knowledge fully on the resource and streamingassets folders are limited
https://learn.unity.com/tutorial/assets-resources-and-assetbundles?uv=2017.3 this has some really good info
but yea they say... "dont use it" under the resources section π
I have been working pretty hard on basically creating everything from code as much as possible, even my textures and stuff. So, I don't have a lot of things included to take advantage of things like the streamingasset folder
although under the "proper uses" section uxml does kind of fall into all of those categories
its ubiquitous, not memory intensive since its just ascii, doesnt vary that much across platforms
I don't know the best way for UI stuff either, speaking of loading, it was kinda something I was just looking up, but, in my effort to not use resources folder, I ended up doing 2 things. I've made a ScriptableObject which I'll show in a second cause I actually have questions on it, that has RuntimeInitializeOnLoadMethod attribute, for basically UI, and a base prefab that contains a UIDocument
the prefab was mostly to stop the above Theme Style error
but realized I could probably just use 1 prefab object and manipulate it a lot for my needs
So does this mean you have very little uxml? Are you mostly creating your element tree in c#?
yeah, I'm in the process right now of actually stop doing it in editor and actually try and make and implement it into a build. My project name is called something stupid just "CreaterWorld", but, my idea behind it all has always been to somehow shift my Unity development all into an actual build somehow, just because I think that is fun
I suppose you get true live reload that way? heh
but all my UI is base visual elements, with different pieces atm that depending on the complexities of what they need are custom built from visual elements, or, something like dropdown (eventually hope to have them all custom, but, being a solo programmer, it's a get to thing). Then some of them have UXMLFactory and traits so they can also be used in UIBuilder if so desired, or to print out the code in that way
do you see a preview of component in UI builder if there is no uxml?
No, at least not natively. I think they actually can? But UIBuilders auto detection requires them?
so last night I refactored most of my ui to use templates in uxml, but now im considering another refactor to custom elements and UXMLFactory
i dont really like the <AttributeOverrides ... stuff in uxml
feels clunky
yeah, I didn't like how it was setup also. Not that it is bad persea, just that it doesn't flow naturally with all the different things Unity teaches
the uxmlfactory stuff seems really nice though, and the integration with the uibuilder is sweet
so now you've kind of convinced me that i should do that lol
I actually had no idea about custom elements at first, but after copy/pasting a bunch of times to update multiple instances I was like okay there has to be a way to componentize this stuff
basically you setup all your stuff like normal through c# then use the UXML factory to initiate through that rather than... itself?(Idk if that is the right word)
And unfortunately I didn't stumble on uxmlfactory until after I had refactored to use templates, since that seems to be the primary docs they have around reusability
Imo Resources is ok - just not great at scale or if making an asset across multiple projects. Think the most common way (and method I usually use for runtime stuff) is to just have a monobehaviour in a scene reference them.
what is tooltip
in ui toolkit?
i want to change a selector/group of buttons in a ui
via script
I haven't used it yet, but, it's suppose to be a popup tooptip if your text were to overflow
like, if a button from this group is clicked, something happens
no, more like lets say you have a section of UI with text that fills up [abcdefghijk]lmnopqrstuvwxyz where the brackets are the space. Tooltip makes it so the lmnopqrstuvwxyz would be visible when you hover over it. Maybe even more letters because I think with tooltip enabled it ends with ...
check out RadioButton
Hello
also, clickable.activators is how you edit the button after created
i see toggle, but not radio buttons
what version are you on?
oh, I haven't checked the actual builder for a while, but https://docs.unity3d.com/2021.2/Documentation/ScriptReference/UIElements.RadioButton.html
https://docs.unity3d.com/2021.2/Documentation/ScriptReference/UIElements.RadioButtonGroup.html
also, if you don't have it, shouldn't be too hard to track with a ChangeEvent<bool>
is it not supposed to show up in the builder then?
how do you use it
are you writing xml and uss
I'm not sure on the priority of adding to the default builder since if they can create you can add it to the builder yourself
let me look at my builder rq
yeah you must be on an older version
2021.2 uibuilder has radio and radio button group in default
what the
ill update it here then
but i downloaded it like
2 days ago
how do i update it?
mine is this version i thinkl
no idea on the packages, in 2021.2 this is default built in, so don't have those even installed to check, but try doing a com.unity.ui to make sure everything is up to date?
in your github link in package manager
that has happened to me sometimes. I just restart Unity
anyone knows if there's a public timeline for when the UI Toolkit will be compatible with Unity's "new" Input System? The only place I found any reference to it is https://docs.unity3d.com/Manual/UI-system-compare.html which says "planned" =/
I mean, the input system's been around for 3 years now, and we still can't use the UI Toolkit with it (at least as far as I know)
There is no public timeline afaik. Also, while the new input system may have been around for a while, it wasn't until 2021.2(?) that UITK runtime became stable/'production ready'.
π been a few since I've talked to you! Just saying hi!
2022.1.0a15
UI Toolkit: BoundsField, BoundsIntField, DoubleField, FloatField, Hash128Field, IntegerField, LongField, RectField, RectIntField, Vector2Field, Vector3Field, Vector4Field, Vector2IntField and Vector3IntField are now usable in Runtime
haha, after I made all my own π¦
Oh no, I finished creating them just recently.. π₯²
do I need to do more than just .Remove to get rid of a UIElement?
Nope, it's just plain old C#, so it'll get garbage collected when you release the references
can I get your guys opinion. I'm not sure how I should handle the text overflow, if I should wrap, or just tooltip, or what would be the best route
Tooltip is probably adequate, wrapping would end up looking clunky i think
I just finished refactoring my templates to custom elements and I am much happier with it now. I also made some really low level wrappers around button/text that basically just override text property to hook into localization, so much happier with that too.
What version are you on? Ellipsis is a good option.
2021.2.2f1
Oh then the Label has a ellipsis bool that will also automatically add a tooltip showing the full name too (can be toggled off)
How do we modify the Clipping of an element? I have a foldout that I want to shrink so only the arrow is clickable, but it's clipping the children out. Can I fix that?
oh sweet! I'll check that out, thanks!
try messing with the .style.margins and .style.padding
Wow, somehow this madness sort of works.. I'm going to assume this is a bug.
Is there a way to stop elements from Inheriting style data? I'm manually indenting some elements and the content wrapper element is adding additional indentation at each child level.
everything has a default layout it is layed out in. From my understanding, you need to set it yourself. The repetitiveness of this though can be solved from many fronts. One way as an extension method that has the styles you want to "override". Another way is a just a container of sorts like a new class called StyleSettings or something. The other is your own custom visual element. You can also do all this through your own stylesheet if your want
I'm doing everything inline with the class constructor right now
I don't see a StyleSettings for the element, just style and resolvedStyle, which is unclear what it is.
yeah, in this way then I would probably recommend doing a custom class visual element, and add on extension methods for ease of changing specific things that might be outside of your normal defaults. For example,
public static IStyle ResetPadding(this IStyle style)
{
style.paddingBottom = 0;
style.paddingLeft = 0;
style.paddingRight = 0;
style.paddingTop = 0;
return style;
}
Hmm, well I can reset the margin to 0 and it won't keep increasing when nested, but the uncontrollable clipping returns again....
I haven't messed with it yet, but, can try toying with IStyle.unityOverflowClipBox. I know I had an issue the other day with weird clipping happening on a foldout added to a scrollview, I ended up just having to make my own from visual element to solve it
Yeah I tried setting that to the parent element ScrollView but it didn't seem to do anything for the clipping. Seems like the inheritance on element style is not stable or something.
Ended up digging through the elements with Q<> to manually fix the margin down the chain. Still not sure about the clipping though. Margin seems like the only fix, but it's not even related.
Eh, just yolo'd the button width until it was clipped by the parent panel. Looks fine. I think this could also be something with the way the Foldout manages the sizes and indentations too, causing some weird results when you're trying to add things with absolute positions and stuff...
I would highly suggest not using inline styles and trying out stylesheets instead. The inspector is nice for tweaking stuff to see what you want your final values to be, but I would roll those changes back into a stylesheet somewhere.
UI toolkit takes direct inspiration from html/css, and people in the web world stay away from inline styling as much as possible.
And you may be tempted to use # selectors to target names but I would instead add a class and use that as a selector. I try to use # for scripting query lookups only.
you can create stylesheets in c#. A class that builds itself in a constructer is essentially the same thing
I personally prefer names, then I can leave classes for precisely what they are
Half of the reason for me using uss is that I get my ide tooling and syntax highlighting etc.
And classes arenβt just for if you need to apply the styling to multiple elements. Itβs perfectly acceptable to have a class selector that is only applied to a single element.
is there a way to create a rootvisualelement without UIDocument? I understand that the UI system relies on a root visual element, but, I'm not entirely sure what that root visual element is doing to draw? I've checked out GL and Graphics classes, but, that was getting into some entirely new things I'm not ready to learn just yet
Just random tip if anyone else was curious, margin is outside the element, padding is inside the element
Also, I know Unity has said this multiple times, but, https://yogalayout.com/playground is amazing
have any of you messed with changing the cursor style? I'm not quite sure how to do it
am I handling callbacks correctly?
bool isOut;
bool isDown;
void OnPointerOverEvent(PointerOverEvent e)
{
isOut = false;
RegisterCallback<PointerOutEvent>(OnPointerOutEvent);
RegisterCallback<PointerDownEvent>(OnPointerDownEvent);
}
void OnPointerOutEvent(PointerOutEvent e)
{
isOut = true;
if (!isDown)
{
UnregisterCallback<PointerOutEvent>(OnPointerOutEvent);
UnregisterCallback<PointerDownEvent>(OnPointerDownEvent);
}
}
void OnPointerDownEvent(PointerDownEvent e)
{
isDown = true;
RegisterCallback<PointerMoveEvent>(OnPointerMoveEvent);
}
void OnPointerUpEvent(PointerUpEvent e)
{
isDown = false;
UnregisterCallback<PointerMoveEvent>(OnPointerMoveEvent);
if (isOut)
{
UnregisterCallback<PointerOutEvent>(OnPointerOutEvent);
UnregisterCallback<PointerDownEvent>(OnPointerDownEvent);
}
}
void OnPointerMoveEvent(PointerMoveEvent e)
{
}
No, a VisualElement cannot get events unless focused or the pointer is over it. So registering/unregister when the pointer enters/leaves only hurts performance and code readability.
okay, thanks! That is exactly what I wondering, what about leaving a callback on an element? Is it ever better to not worry about unregistering?
Only unregister if you specifically don't want them their. If you are going to add them again and having them their would not cause undesired behaviour then leave them.
If I need to toggle behavior of some type I use bools fields in the class instead of registering/unregistering events. This also seems to be the approach Unity takes with all of their internal systems/implementations.
okay, in this case would it be good to still use the the onenter and onleave callbacks? Also, if it helps, I'm trying to to create callbacks for size changing with the borders
for example
I don't see a need for the PointerOver and PointerOut events if that is what you are referring to. What do you mean "for size changing"?
I have 4 visual elements for each border, and doing the callbacks I track the delta position and geometry change the main container
Idk if I get it, but okay!
I'm trying to setup changing UIs size from dragging the borders
so I'm getting it to work pretty well, just need to figure out how to better deal with the events if dragging while it leaves element
oh maybe I need to use capturemouse while mouse is down
then MouseCaptureController.ReleaseMouse() on mouseup
oh yeah, that mouse capturing is game changer
if I'm to drag a window to expand left or up is there an easier way than what I'm currently doing to change the height and width? When dragging down or right I easily just change the width or height. For up and left I've had to make it so it is changing the position of the UI and increase/decreasing the height/width
basically, is there a way for me to change the pivot
well let me checkout this domeasure
So I'm trying to figure out a better way to approach adjusting the top and left size of a UI window. The way I listed above causes some jittering
I found somewhat of a way by adjust the padding, however, I didn't know if I should keep this route just because of having to add an extra variable in calculating width/height
basically doing something like
parent.style.marginTop = parent.style.marginTop.value.value + e.deltaPosition.y;
parent.style.height = parent.style.height.value.value - e.deltaPosition.y;
in all the respective borders, but as you can see I still have a little jittering. Not sure if anyone has any thoughts on that?
maybe I should calculate any changes before doing the changes and then use Mathf.Approximately?
Take a look at the source for the UI Builder and see how it does it maybe
I'm actually breaking down my thing atm into more containers to control things. Hoping that helps
Adding a default 9pane container for example into my base containers, with a size container override. Then I think I can abuse absolute position while maintaining relative for auto layout
how do I better keep track of the layout phase, is that the IMGUI layout phase?
Not toolkit related, sorry
ok sorry thx
can anyone better help me understand how to register changed events? I thought I had it down, but, apparently not. I'm trying to register value changes for height and width of a main container to adjust the border containers accordingly. The way I have it setup right now i something like
protected override void ExecuteDefaultAction(EventBase evt)
{
base.ExecuteDefaultAction(evt);
if (evt.eventTypeId == GeometryChangedEvent.TypeId())
{
if (evt.target == this)
{
UpdateBorders();
}
}
}
public void UpdateBorders()
{
UpdateBottom();
UpdateLeft();
UpdateRight();
UpdateTop();
}
It works, but, I was thinking that I didn't need to run through all of these every time a size change happens and instead specifically target the exact thing based off value changes
What...? Wouldn't doing RegisterCallback<GeometryChangedEvent(OnGeoChanged) be what you want?
can I add a UIDocument to a MonoBehaviour without showing it? I want to do this so that I can use its CloneTree method and add its elements to the main game frame. Am I doing this the wrong way?
Ummm I guess yeah I could just do on geometry change, if newRect height != oldRect height?
Unless I am mistaken, what you are doing in that snippet is effectively the same as just registering to the geo change event...
And yeah, you would do new !=old. But I think the event may have a enum for the type.
Oh, I was reading through some of the most recent UIToolkit Manual and it said if you can do things in overriding default action. It says that it is less performance than registering a new callback
however, it comes after registering callbacks, so you can use a callback if specifically needed and cancel default action
like, I started doing
protected override void ExecuteDefaultAction(EventBase evt)
{
base.ExecuteDefaultAction(evt);
if (evt.eventTypeId == PointerDownEvent.TypeId())
{
RegisterCallback<PointerMoveEvent>(OnPointerMoveEvent);
this.CapturePointer(PointerId.mousePointerId);
}
if (evt.eventTypeId == PointerUpEvent.TypeId())
{
UnregisterCallback<PointerMoveEvent>(OnPointerMoveEvent);
this.ReleasePointer(PointerId.mousePointerId);
}
}
void OnPointerMoveEvent(PointerMoveEvent e)
{
parent.parent.style.marginLeft = parent.parent.style.marginLeft.value.value + e.deltaPosition.x;
parent.parent.style.width = parent.parent.style.width.value.value - e.deltaPosition.x;
}
instead
also
I didn't know how to really use PointerMoveEvent inside the default action.
What are you doing...?
This does not look what you should be doing, but maybe you have a good reason...?
just trying to perfect this
I would really look at how the UIBuilder does it's canvas because I feel like could improve yours by learning from it.
From the bits of the code you have shown make me think that it is rather messy and not exactly how you are meant to be doing things.
I tried, but, ended up a little confused because I'm trying to build everything through strictly c# hehe
Look at Packages/com.unity.ui.builder/Editor/Builder/Viewport/BuilderCanvas.cs
It does exactly what you are doing from what I understand.
I think I'm doing it how they intended. The UIToolkit seems to be built on this idea that everything is a "container" for things you want to do. So, in this screenshot for example, everything you see is it's own visual element, with minimal code inside of it, then it's all in essentially an overlay container on top of a content container
I mean more of how you are handling events.
cool let me check that out
oh okay, definitely, yeah, I need to get those down better
You are using elements as intended though yes. Each side being an element and such.
part of my problem is IDK which element should be the element that essentially handles events?
Like, if I want to change a child elements size, is it better to handle that in the parent, or the element itself
It depends(tm)
Also, do you know how to use public UIElements.StyleCursor cursor;? Some of these styles I'm confused how to edit. I ended up using a button with a unicode code in the text because idk how to edit the istyle cursor lol
Idk, look at the class I suggested and its styling because it edits the cursor π
yeah haha, editing these styles made me realize how much of a noob I still am. Like, when I first started messing with translate I just kept entering in new Something till something worked
I guess mostly, what I'm struggling with is how I generate a texture from a unicode text
Aha, I get it now
public static UnityEngine.UIElements.Cursor TestCursor()
{
UnityEngine.UIElements.Cursor cursor = new UnityEngine.UIElements.Cursor();
cursor.hotspot = Vector2.zero;
Texture2D cursorTexture = new Texture2D(20, 20, TextureFormat.RGBA32, false);
cursorTexture.alphaIsTransparency = false;
for (int x = 0; x <= cursorTexture.width; x++)
{
for (int y = 0; y <= cursorTexture.height; y++)
{
cursorTexture.SetPixel(x, y, new Color(Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f)));
}
}
cursorTexture.Apply();
cursor.texture = cursorTexture;
return cursor;
}
Hey there, Unity keeps giving me this error namespace or class "UIDocument" can not be found.
this is the line of code giving me this error
but as you can see, UIDocument exists
it's identified inside of vscode
actually, I can always fix the problem when I edit the code (without changing anything), but this error always show up when I open the editor
what's causing this? how do I fix it?
It's when your DLLs load. It's isn't that the UIDocument is missing, it's that it hasn't been loaded yet
I haven't messed around really with those yet as every time I do I seem to use them wrong, so, that is unfortunately the extent of my knowledge
Is there a native way to cancel mouse events in general if using pointer events?
Or, I guess. Is there a way for me to lock the cursor icon while pointer capturing?
an example of what I'm trying to do. You can see the icon change if it goes out of the visual element, however, it is still captured, so thought it would stay
Another more common approach might be to match the border position with the cursor position.
hmm good idea. Going off of delta position is probably why it isn't fully following. I was trying to understand propagation better and was assuming the icon change was happening because of out events, but, I couldn't seem to successfully figure out how to stop events yet even using evt.StopImmediatePropagation(); and evt.StopPropagation();
I'm actually confused by how e.originalMousePosition even works. The top is the position it gives me, the bottom is an example of what `Input.mousePosition gives me.
e.position just seems to return originalMousePosition as a vector3, so does no help. e.localPosition returns the distance of the cursor from the element doing the event, which is probably what I'm looking for, however, still leads me the confused on the previous 2
probably why delta position isn't moving with my cursor. It's probably being calculated on wrong positions
for example of another check
@tulip sparrow Just thought I would say thanks for mentioning element.CaptureMouse() the other day, I needed to implement a version of what you are doing today and because I saw you mention it it was at the top of my mind. Saved me a lot of time haha.
original could be relative to the panel maybe?
heck yeah man! It's way good! Though I've been wondering if I should be using CaptureMouse() instead of pointers in scenarios where I know there is a mouse. I've bene instead using CapturePointer() as like a catch all including for mouse
doing some testing with Style.Translate I believe the the other positions might be px related, however, that still confuses me because I thought px would be a larger number
They should all be in pixels...
I should have finished my thought, because what I said doesn't make sense. Hold on
okay, I think I notice the problem. It might not be the same in an actual build, but, I think the input.mousePosition was giving me coordinates based on my actual screen resolution, and not just the game view?
IDK how to test it, but, is referencing 2 parents up in UIElements like parent.parent.style.translate = new Translate(parent.parent.style.translate.value.x.value + offset.x, parent.parent.style.translate.value.y.value + offset.y, parent.parent.style.translate.value.z); better than doing .Q()?
btw, I changed the move event to
void OnPointerMoveEvent(PointerMoveEvent e)
{
Vector2 offset = e.originalMousePosition - position;
position = e.originalMousePosition;
if (offset.x < 0 && offset.y > 0) style.cursor = UICursors.ExpandArrowDiagonalForwardLeft();
if (offset.x > 0 && offset.y < 0) style.cursor = UICursors.ExpandArrowDiagonalForwardRight();
parent.parent.style.translate = new Translate(parent.parent.style.translate.value.x.value + offset.x, parent.parent.style.translate.value.y.value, parent.parent.style.translate.value.z);
parent.parent.style.height = parent.parent.style.height.value.value + offset.y;
parent.parent.style.width = parent.parent.style.width.value.value - offset.x;
}
and works really well now. The cursor is never not on the element while moving now
need to just update it on all my border visual element now
hi i am using ui builder and i created an UI document but i dont have this event system component, anyone knows why?
have you downloaded the input package? I'm not sure if it is necessary depending on what version of Unity you are though. At least since I upgraded off the LTS I haven't needed the input component
no the guy from the tutorial just installed ui builder and toolkit, im using unity 2020 LTS too, which input package i need?
iirc in the package manager, type in com.unity.ui in the github, it should give you everything up to date ui package
I'm on 2021.2.2f1
ehm, is it okay if I ask here about UI Builder messing with me pretty bad, or is this strictly for design advice?
anything UIToolkit related
alrighty then...
so, every time I re-open my project, the script in UIDocument stops working, tells me to check for compile errors, which there are not any
and I have to delete the script, create an identical one, attach it to the UI Document again
and it works... until I close unity again
rinse repeat over and over
its super confusing
as everything is working fine, until I close unity
this is what it looks like after re-opening unity
you need to check out assembly definitions. It's because on recompile, you have scripts trying to access the assembly the UI Document is in before the assembly is loaded
Unfortunately, I don't understand much outside of that yet, I just know it's the issue because I had that issue on earlier versions
from the very little I found basically you use them to tell the order of assemblies you want loaded, but, I'm confused on if you use one, does that mean you need to start including all assemblies? Last I checked, the default unity was using like 162 assemblies? I think, so, IDK lol
Oh thanks for the effort
I decided to go to bed angrily
It is an issue for tommorow's me
ok in case anybody cared/needed it, I fixed it
in the folder where the script handling the UI is located, I created an assembly definition
the name of the assembly definition is the same as the name of the folder it is in
after that it still was not working, so in the assembly definition menu in the inspector, I clicked on add reference
and there I added all the assemblies containing 'ui'
probably not the best solution
but its working Β―_(γ)_/Β―
Hello! Is there any guides that provide like starting experience for code-only UI Toolkit usage? I've found only the ones that use UI Builder, but i'm actually kinda experienced in web development and HTML + CSS, find them pretty comfortable so i want to grasp the code-only way. Just have no idea where to start.
I think that is exactly what you had to do. So, it is the best solution! I'll hopefully remember that so if someone else has the same problem haha
https://docs.unity3d.com/2021.2/Documentation/Manual/UIElements.html is a place to start. However, note that it is 2021.2. So, if you aren't on that version, it may not be as accurate.
and https://docs.unity3d.com/Packages/com.unity.ui.builder@1.0/manual/index.html for the builder
I know personally https://yogalayout.com helped me out immensely, so, check that out also
I'm actually in the process of trying to create a webGL unity UI playground. I don't feel comfortable sharing it yet, and wondering if I ever will lol, but maybe you gave me extra excitement to do so
Yeah, getting started part is just what i needed
does it even worth using UI Toolkit with 2020.3.22f1 version tho?
I'm not sure.
I don't really know what is included from updating the UIToolkit package, vs built in
I am using it with that version
so far its ok.... except for the issue I explained above but I have no clue if the same is going to happen to you
isn't
public static bool operator ==(StyleLength lhs, StyleLength rhs);
public static bool operator !=(StyleLength lhs, StyleLength rhs);
suppose to let me validate if one of these style structs is null or not?
I can use Debug.Log(parent.style.width.keyword == StyleKeyword.Null); as an example, but, thought I could just do without with operators
I also haven't been using StyleKeyword like anywhere, so, IDK if it's only values by default are StyleKeyword.Null and StyleKeyword.Undefined on values that aren't null. Basically, if it is a valid thing to check against only if I specifically set it
all these errors while trying to install ui toolkit on unity 2020.1.9f1
whats this? i already tried other version i always have errors when trying to install this
I hate how I keep starting out with like 10 visual elements to learn how I want to build something, then condense it to like 1-3 visual elements once I figure out what I want lol
between the direction textures read, and differences between absolute/relatives starting points and direction, etc... position is so annoying sometimes. No wonder they recommend auto layout lol
can anyone tell me if in the most recent unity they make dealing with IStyle properties less obnoxious before I make a bunch of extension methods?
What are you doing right now?
I just got frustrated with typing out all of StyleTranslate stuff when resolvedStyle isn't good enough. So just did
public static StyleTranslate @Translate(this StyleTranslate styleTranslate, Vector2 value)
{
float x = styleTranslate.value.x.value + value.x;
float y = styleTranslate.value.y.value + value.y;
float z = styleTranslate.value.z;
styleTranslate = new Translate(x, y, z);
return styleTranslate;
}
to save me some time
I created a container I call my "Interaction Container". To leave it as generic as possible I created a new delegate to notify a listening of when that element is clicked, however, I wanted to check if there was an event that already happens that I should use instead? To clarify also, I do use PointerDownEvent. I'm trying not to use that specifically though for this case because I'm trying not to directly make a visual element rely on another. Oh, and I have picking mode off on the overlay I want to bug about this.
I was going to use SendEvent, but, I wasn't quite understanding it yet it seems
better yet, is it better to just cancel default actions on visual elements and use your own delegates for any reason?
for example, I just did
public delegate void OnInteract(EventBase evt);
public OnInteract interactMethod;
with
if (evt.eventTypeId == PointerDownEvent.TypeId())
{
pointerPosition = evt.originalMousePosition;
this.CapturePointer(PointerId.mousePointerId);
if (interactMethod != null) interactMethod(evt);
}
do I need to care about BubbleUp and TrickleDown at all?
this issue
sucks
i just fixed this problem, my team almost gave up on using uitoolkit because of that
in fact, it's so inconsistent to the point that sometimes it would work, for some people it would work
while for others this problem popping up
in fact, you didn't even need to delete and recreate the thingy, if you just edited some script (like added a comment or something that makes no difference at all), saved, and then went back to unity and waited for recompilation, it would suddenly work
the solution you found is how to deal with it really
assembly definitions
yep it sure does suck
was stuck on it for a while
its the type of thing thats so demorilising that it makes you lose all the drive you had to work on your project
for me that is, at least
Controlling assembly loading is a necessity long term. It sucks when something happens outside of the normal scope that would cause huge headaches if you aren't at that level you. There is a reason
UI Toolkit is built into Unity as a core part of the Editor. It is also available in this package, com.unity.ui, which is currently in preview. The built-in version for each major Unity release is based on a specific version of this package, but the two are not completely identical.
is on the UI Toolkit page.
Unity compiles scripts in 4 separate phases. You can actually cause this issue yourself as your project gets larger if you start taking advantage of assembly definitions in an effort to condense load while still having access to everything you want.
if you guys haven't found it yet https://docs.unity3d.com/Manual/cus-asmdef.html has an example file if you choose that route
https://docs.unity3d.com/Manual/cus-layout.html for the package layout
Also, IDK what version you guys are on, but, when I jumped off the LTS, all my UIToolkit problems went away XD
There's also a migration guide pinned to this channel for going from earlier preview versions to later ones, or to 2021.1
yeah, I forget to mention the pins
Is it possible to serialize UI Toolkit Image class for runtime so i can add icons for my interface with drag & drop?
I want to add icon field for my MonoBehaviour items on scene,that would then display in player's inventory.
Image already exists for runtime. Even if it didn't, you can change a visual elements Style.backgroundImage
ATM You have to use UIDocument to display visual elements since they require having a "root" to display in. Unfortunately, I haven't gone further into figuring out more than that since it is pretty simple. Just make sure a UIDocument Game Object exists when you game starts and make it the size of your screen. I personally haven't had a situation yet where you would need more than 1 UIDocument. In fact, I wish Unity just removed the GameObject all together, made it always the size of the screen, and made it just built into builds
Then make rootVisualElement just some base in the UnityEngine library
That doesn't answer my question
I've asked how could i set Image typed field of a class in the inspector, ATM it doesn't seem to serialize it
and what could i use instead then
sorry, you mentioned runtime, so assumed you meant not in the editor. Check out the property field for editor
also, make sure you are serializing it π
I've mentioned runtime cause i'm not building UI for the editor itself, i just want to set the value of an Image typed field in the class that is attached to a game object
i am, tried both serializeField modifier and making it public
it doesn't seem to show up in the inspector any way
did you do System.Serializable above the class?
nope, only SerializeField modifier
but i'll try this one, one second
ScriptableObjects and MonoBehaviours are default Serializable, so, you shouldn't need to include it on those, but on other stuff you do
Nope, it doesn't seem to work either
statics aren't serializable either. Personally, I just stop messing with serialized or not and just make accessors that editor can get values from and display it regardless
try SerializeReference. Serializing doesn't play nice with nesting, and if you have something nested deep not serialized, it will cause issues
also, try posting a SS of your code if you get a second
I've tried the SerializeReference too
seeing that code will make it a lot easier to diagnose
that's all i'm trying to do basically
just expecting the icon field to show up in the editor
so i could put the image to it, and then use this icon in the UI
same thing did work with basic unity UI, but doesn't with UIElements
oh, in this case, you are using the wrong field. Try Texture2D field
You can't drag and drop UIElements in this way natively
but would i be able to use the Texture2D as background image for the UI element then?
Yes. So, based off what you are doing. Use the Texture2D for the field. Then, you make the image the texture, or backgroundimage, or whatever
Well, thanks!
if you want to get fancy, you can delve into making that field visible in the inspector, but, for simplicity, you should be able to natively drag and drop into a Serialized Texture field
Do you have the text element in the front of siblings?
do you have an overlay with position.aboslute over it?
no
also, can you click on the text field? value needs to be set for text to show
a change event has to be registered to
yeah, but, you can type things into a text field in editor without it saving
Changing text by itself doesn't save it
you need to go through the normals steps to save the value, or, automate it registering to ChangeEvent
Yes. Go to wherever you initialize the element in game, add whatever.value = "login" for example, and whatever.value = "******"
but that doesn't make sense, i made 3-4 other ui and never had that issue
for example, with the button,
Changing this value will implicitly invoke the INotifyValueChanged{T}.value setter, which will raise a ChangeEvent_1 of type string
so you can automate saving it through this by default
or initialize the UI with the text you want
if you are making things with UIElements, you either have the default value set somewhere, or initialized with text, or automating a process to save the text
if you are using PropertyField to change things, that is a different story. I'm not fully aware if it replicates SerializedObject and SerializedProperty in their entirety, but, says, A SerializedProperty wrapper VisualElement that, on Bind(), will generate the correct field elements with the correct bindingPaths which may be automagically doing setdirty type things for you
oh okay, so you are using UIBuilder, let me check if the saving things are still the same havent opened it in a while
did you file save after changes correct?
take a loot at this and make sure you are editing the correct field
text != value
hey
i did this
i think i figured the source of the problem
yesterday i was having a massive issue, which was such a pain
type or namespace "UiDocument" could not be found
so I followed a tutorial and created an assembly definition
and this assembly definition
had this setting
in order to work
now I feel like fonts are not showing up or there's no font on the runtime
no text show up, at all
that could be the reason, but the solution, no idea
can someone help me better understand how to deal with events with trickledown and bubbleup? Most the time it feels like dealing with them is far less efficient than directly telling the element to grow up and be a big boy
Just as a premise, I'm working more on my ability to expand a UIElement any direction regardless of it's parents settings. Doing so is making have to wait on GeometryChangedEvent and AttachToPanelEvent for example, to guarantee certain steps have happened first and not skipped over. Easy enough to not use the default UIElement event system, but, I feel like that undermines the purpose and I just don't get how to use it yet fully
I don't quite understand what you are asking for tbh.
I'm just trying to understand UIToolkit over a little more. Like, better handling of not only events, but, when it is more profitable to just directly tell an element to do something rather than waiting for it from the trickledown/bubbleup
and I feel like I concluded it is almost always better to just ignore the trickledown/bubbleup, but, I also don't use any xml and do all of my UIToolkit in C#
so idk if that is something that is beneficial there or?
what does
Style sheets also have features that arenβt possible to use with inline styles, like:
Pseudo states like :hover, which will apply some style properties to an element when you hover over it with the mouse.
Styling of elements inside a read-only hierarchy inside a Template Instance (instance of another UI Document (UXML)) or custom C# element that creates an internal hierarchy. You can style elements with style sheets using hierarchical USS Selectors, like the following
even mean? I literally am doing these things right now
It means that in C# using styles, you cannot set a specific style for when an element is hovered.
It doesn't mean that you cannot do it "in code", it just means that inline styles themselves do not have any support for those things
ohh gotcha, okay, cause was like, all elements, even with picking mode on false, receive in and out events, which is a literal trigger for hover events
You can set it set style for hover using events, but that is not the same as setting a style for a pseudo state.
An example is the :selected pseudo state.
all elements have defaultaction for in and out unless coded not to
as far as I can tell, without picking mode set to false, all elements have the in/out/enter/leave/up/down/click default actions, and with picking mode true, just enter/leave
Yes that is correct.
rather, not false and true, but position and ignore
ignore means that it cannot be 'picked'/'clicked' by the mouse/pointer
It'll be cool if/when they add the more complex selectors that CSS has and is continually getting
I hate how CSS works for layout and has a lot of incompatible nonsense, but the selectors are really nice
IDK if it will be of any use, and if I'll ever even finish it, but, I'm trying to make something like the yoga playground atm with UIToolkit
my goal is people will be able to download C# file for UIToolkit they can use in their projects
we will see though
Hi all, I want to make a L shape button. But I only can make rectangle touch zone of it. Anyone have idea to make it? Is UI Toolkit have some thing like alphaHitTestMinimumThreshold ? Thank you π
should be easy enough with RadioButton
if you aren't on a version that has a RadioButton, just use 2 buttons and connect them
Thank you Eliseus, so UI Toolkit not support alphaHitTest now? Because in future we also need many shape of button (diamond, circle, Z...) I don't think your solution can help us π¦
Do we have plan to support alphaHitTest in future?
Unfortunately I don't know, and IDK what alphaHitTest is, however, I know you can use https://docs.unity3d.com/2021.2/Documentation/ScriptReference/UIElements.VisualElement.ContainsPoint.html for more custom interaction
Ah, sorry, before, we use this feature for custom shape buttons https://docs.unity3d.com/2018.1/Documentation/ScriptReference/UI.Image-alphaHitTestMinimumThreshold.html. If use touch on a alpha part of rectangle image, we consider it is not a hit. https://forum.unity.com/threads/none-rectangle-shaped-button.263684/
btw, thank you for your support π
Anyone else notice that the Inspector's updating of values is a huge drain on Editor performance in Play mode?
Are there any gotchas with creating custom elements that using uxml files as templates.
I'm not sure if I understand how it supposed to be working.
Like I can create an element like this:
public class CustomElement : VisualElement
{
public CustomElement()
{
var template = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>("Assets/element.uxml");
template.CloneTree(this);
}
public new class UxmlFactory : UxmlFactory<CustomElement, UxmlTraits> { }
}
and the uxml is very simple:
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" editor-extension-mode="True">
<ui:VisualElement />
</ui:UXML>
it basically just single VisualElement. but when I'm trying use it in builder it spawning exceptions as soon as I'm selecting the element.
something about attributes overrides. it looks like if I'm using uxml asset in custom element constructor it still trying to use as a template instance if that makes sense.
it works as expected if I create the whole layout by hand in c# but I was just wondering if I can use builder for custom elements
Further to this, every single update to a serialised or public variable in the Inspector seems to be creating garbage, which has to be collected, causing a huge stutter when it's done.
Not really much to go on. I don't notice these "huge drains", but, I don't know everything you are trying to do
Consider yourself lucky. When you experience it, you'll know exactly what I mean, and that there's no possible remedy, other than getting Unity to take a look at how to build "strings" to present in the UI without creating garbage.
Are you using a custom inspector or anything because by default the editor is IMGUI, not UITk. Also, have you tried profiling?
2020.LTS, profiling reveals the garbage, and the hiccups on cleanups of the garbage. Hide the inspector, two things happen: much faster rendering of everything, much less garbage.
Even merely deselecting everything does the above, too.
No custom inspectors. Custom components with serialised fields showing changing values every frame.
This is most significant with a small array of float4's showing their updates.
You're missing the fonts needed. Be nice if Unity told you the name of the fonts missing.
Does anyone remember the link to what the default style settings are for all the built in elements? Also, all of the default inherited styles?
I don't think there ever was something like that...
Oh, I swear I skimmed past something the other day haha and didn't care at the time, ugh, okay
does anyone know if there a base field we can access yet that isn't abstract that I might be overlooking? Something like how TextElement is for text
better yet I guess, does anyone know how to manipulate a visual element to create a field?
How do i make non-interactable sliders in UI Toolkit? Like for the health bar.
I've didn't found any guides about the slider element in UI Toolkit actually
found this element, but not sure how to use it
when i try to declare it in .uxml like that
it doesn't seem to work
nvm, I've found out the ProgressBar element is probably not for the runtime
what could i use then, besides making a simple container, and overlaying it with something?
2 visual elements, 1 as the main container, and the other as the bar that expands and shrinks
yeah i get it
just thought there would be generic element for that
it's kinda easy to implement tho, so doesn't matter anyway
if you dont use progressbar the only more simple thing, which is actually not as simple as just using 2 visual elements, is just use 1 visual element, change the background, and have it expand and shrink
what patterns do you guys usually use to access data in classes tied to UIdocument gameobjects?
i'm pretty new to unity, and didn't found anything better than that
How do you make UIElements PropertyField work with nested editors? We have EditorA that has PropertyFields, end EditorB that contains EditorA instances and shows them inline. For this we use CreateEditor to get EditorA's editor and add it to EditorB VisualElement, however the PropertyFields no longer display (while they work fine when we look at EditorA in the inspector). My guess is that when EditorA is displayed nested in another Editor, the PropertyField binding is borked and binds to the other Editor (so the properties are not found and nothing shows), but how do we fix this/avoid this without having to stop using PropertyFields and start using type-specific fields with manual binding ?
I actually have a GameManager Scene Object. There is plenty of other things you can do, even just do a static class that has a runtime attribute to initialize a UIDocument, but, I just like having a GameManager Object, but anyways, the GameManager script attached to it has a "UserInterface" class that holds a prefab for my UIGameObject
so do you actually instantiate a prefab with UIDocument and all the code that works with it in runtime?
not sure how else could class hold a prefab
is it like found by tag and cached then?
yeah, originally I was just doing it dynamically, but figured I could just save a prefab and save time
for example
ooooh
this way
that looks just what i need, but does the editor actually hook up the UI
and show it before the game is started?
I've added up visual elements at runtime previously, and there was no other way to see style changes made to them besides starting the game
so I'm not really sure if it will work the same way, since you actually work with prefab in code
oh I think I get what you are asking, in a way yes. In the editor you don't need a UIGameObject. All Editor Windows comes with a rootVisualElement already. So, the way I design my UI is to try and be harmonious between both in game and editor. Basically, my "pattern" is the start all UI with a root element to make for easy grab create that root and it can be used with anything that is the root visual input
if that makes sense
this prefab is just for being able to display the UI
nothing more
for example even in it
I have a field set as public static VisualElement root;
for easier Query() access
a method called
public void Initialize()
{
UIGameObjectCheck();
uIDocument = uIGameObject.GetComponent<UIDocument>();
Root();
TestVisualElement testVisualElement = new TestVisualElement(root);
//CreateCreateUserInterface();
}
ignore some of the comments and naming
testing things all the time, so haven't removed/renamed stuff
then on my GameManager
void Start()
{
userInterface.Initialize();
}
well that makes sense, i'll try to implement something similar
I'm not sure if this is the "best" route. I just liked it
You can even go further and remove the GetComponent by dragging and dropping the UIDocument reference. I just haven't cared to change it yet
ideally you would put a null check
hey so is there any way to get antialising on uielements? i get these weird jadgginess when making my buttons with radial borders
how are you doing this? RenderTexture for example already has an antialising property.
wdym by this? im just using the ui builder
this is an editor window
I mean that if you imagine the visual elements as just containers, the things you actually put in them have antialising properties
and oh, let me see if there is someway to deal with that in UIBuilder
i just found it out, tho it needs a bit of code
you can actually do this.SetAntiAliasing(4) and itll apply for levels of aa to the editor window
Do you guys know how to best overlap elements using relative? I only know if using bottom/left/right/top for positioning or using absolute
is there an enum or field or interface that makes a style become inherited down the chain? Maybe just make my own interface for this?
Just an example, I have a chain of visual elements that I have style.MinWidth = parent.style.MinWidth and just looking at saving some time
if I calculate overlay screen space coordinates with a camera, will it work with UIToolkit and a position:absolute element with top sorting order?
var pos = cam.WorldToScreenPoint(transform.position);
as long as it's above any siblings that have absolute, but, you need to also take into account some settings still on the parent container. Absolute makes the items ignored on the layoutpass, doesn't make the item completely ignored by settings
hmm, i have the element on top of the hierarchy
it's slightly off, but seems to do the trick:
var pos = cam.WorldToScreenPoint(build.GetTransform().position + build.Config.HoverOffset);
if (pos.z <= minDistanceToCam)
{
el.Hide();
}
else
{
el.Show();
el.style.left = pos.x - (el.style.width.value.value/2);
el.style.bottom = pos.y;
}
and does UIToolkit still work with TextMeshPro? doesn't seem like just specifying the ttf in USS works
It uses TextCore, which is text mesh pro's rendering engine. I believe you can also reference TMP fonts, but I think it's advised that you just create FontAssets. Create > Text > Font Asset
I'm not sure how that works in uss, I'd use the UIBuilder to reference it and see how it saves the USS
ahaaaaaaaa thank you!!
under that same menu there seems to be a Text StyleSheet
I haven't delved that far yet hehe. I just use this UnityDefaultRuntimeTheme scriptableObject that I'm actually not entirely sure where it came from
im having trouble importing ui toolkit/builder
when i install from git url, im getting missing assembly errors whenever i start the project, up until i edit/save a script within it upon which it then works.
yea whenever i change the script the missing assembly is in the errors vanish, but whenever i open the project i get missing assembly on UIDocument types, etc
any ideas?
highly suggest migrating to newest version of Unity. if not, you need to lookup Assembly Definitions and do a lot of the figuring out yourself unfortunately
thats dissapointing, i thought LTS projects would work with most packages
i will though, thank you
they can, from my understanding though, support for features from the following years releases are not normally invested in
yea that makes sense, my previous install was only 2020.3.18f1
which is from a month or two ago only
If it helps at all. I was going pretty strong on LTS for about a year until I finally upgraded to a current release. I'm kinda angry at myself for not doing it earlier
oh so you are saying to not do an LTS post?
ive only ever done those, where might i find the current releases?
the alpha?
LTS is great, just as I've gotten deeper into understanding things it seems that is might be better to stay with the current release (idk about alpha, I don't delve into any alpha/beta things) and as your project gets larger / closer to finish transfer over to an LTS version since it's suppose to remain supported for a couple years
hm yeah that makes sense
people say to only do this because it is apparently unfeasible to keep up with current update. I don't actually understand how that is so unless you coded things in a way that everything is tupled
but idk
it just seems like the LTS version already outdated
ie it doesn't work with preview packages
I still haven't released anything... Hoping to soon β’
preview packages are speculated to be constantly changing while in preview mode, even if they don't, they suggest to expect for things to break every update on them.
yea that makes sense, just dissapointing as a lot of the modern features are locked behind preview packages
like a style-sheet based ui
or ecs
both of which i want to develop using
but, that is where the transfering over to LTS when you want to publish is suggested, because then you should be able to open the project there, hopefully fix whatever is broken, then get a couple years of support out of it
ohh yea that makes sense
so once you have resources/knowledge to do the custom assemblies/dependencies, that is when LTS is meant to be used
yeah, another annoying feature is things locked behind pro. Not that there is things you can't use that only exists in pro, but, if someone hasn't made something, you won't have it. It isn't so annoying, but, one day I'll be there lol
yeah, whatever it may be. Once you have a better understanding of all the UIToolkit in the current release, for example, it might make it easier to fix the errors that popup in the LTS
for sure that makes sense thanks!
thank you that fixed it, as well as the newest version is much better than lts haha
Eh, so, how do i make a row that has a few squares in it (no matter the container aspect ratio) without using px unit?
Sorry if that question is stupid, kinda stuck on it for a while
just take a visual element and put as many visual elements that you want in it. Depending on how you want spacing you can do many different things, but the most common way would be to put flexDirection column on the parent, and do something like flexGrow = 1 on the all the children and they will auto give you rows basically
turn on borders if you want to actually see it
or backgroundcolor
the problem is actually in making this elements squares
since % unit depends on container's width and height
not really. You can either using wrapping, or, split up the parents. What I mean is, for example, a 9 pane visual element could be 1 visual element, 3 children visual elements, then 3 children visual elements of those
then rotate flex directions
in each tier
flexGrow will automagically make them all equal... HOWEVER, until you put content into them
if you dont set anything else, content is larger would make things change without any other settings
but, you can fix that by using max numbers, or, turning off flexshrink, etc...
they are equal, yes
but not square-shaped
i'm trying to make that row of squares like they would be if their width and height were set in px
like that:
but that is I've set their width and height in pixels
and now i'm trying to get the same look with relative sizes
is it even possible to do in USS or i have to make the calculation and set their size in C#?
if you do exactly what I said
but would that work if you give the container size of like width: 500px; and height: 250px;
like will it still keep the squares square-shaped
let me check, I just typed that out rq its 100x100
yeah, there's no problem in making inner squares when the container itself is square
but i want to give them relative size and still have them keep their square shape
however, this should be expected. It's not possible to make a square with those dimensions with this layout
yeah that's what i'm talking about
css in the web however allows doing what I've told you with flexbox
that's why i was asking
no, I mean literally, 500 x 250 isn't a square, it can be 2 squares
i'm not saying about splitting the container in even squares
that's the result i want exactly
yet i want their size to be responsive
and change with container size relatively
oh, okay, I get what you are saying
what you want it a square that maintains its aspect ratio?
yeah
there is aspect-ratio thing in YOGA layout
but it isn't supported in USS currently
as it seems
aspectRatio isn't a real flexbox style
IDK how in UIBuilder, I would have to check, but, simply limiting the mins/max will maintain a square
if you make it so a square can't ever be more than a square or less than a square basically
I think flexGrow auto takes care of those things though?
if you setup your containers properly I mean
this whole style of things is kinda confusing, like, how do I explain, IStyle has how many different fields? Yet, it is almost beneficial to never actually change multiple of those values within 1 element
like I've been working on a a base container for manipulating things which is like 32 elements right now just for the ease of adjustment, though, the saved element from it is as minimal as possible lol
well, i'd just better go and calculate the size for this squares based on container size in C#
xD
it doesn't really change in runtime anyway, i just want this to be flexible while i design it
and also work well with different screen resolutions
I'm still trying to figure out how to manipulate Relative position better. I find it SO easy to just use absolute, but, when I do that, I have to use callbacks more to manipulate other elements
Well i don't really remember who sent me the link to some post about aspect ratio
but thanks, it's actually helped me out quite well
Now i'm kinda wondering what's wrong with that border-radius here
it looks really edgy in runtime, and especially with some really big curves
is there a way to improve this besides using images instead?
and also what could i do about font sizes, cause they don't seem to adjust on different resolutions
I haven't messed with the border-radius yet, on my todo list, however, something you may be able to consider is splitting up the border into separate visual elements
i'd better use a picture instead at this point π
yeah haha. Also something you could do if looking to specifically do things inside code, is make a new texture and color the coordinates in that location. For example,
int[] ints = new int[]
{ // 00 01 02 03 04 05 06 07 08 09
/*09*/ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
/*08*/ 0, 2, 1, 1, 1, 1, 1, 1, 1, 2,
/*07*/ 0, 0, 2, 1, 1, 1, 1, 1, 1, 2,
/*06*/ 0, 0, 0, 2, 1, 1, 1, 1, 1, 2,
/*05*/ 0, 0, 0, 0, 2, 1, 1, 1, 1, 2,
/*04*/ 0, 0, 0, 0, 0, 2, 1, 1, 1, 2,
/*03*/ 0, 0, 0, 0, 0, 0, 2, 1, 1, 2,
/*02*/ 0, 0, 0, 0, 0, 0, 0, 2, 1, 2,
/*01*/ 0, 0, 0, 0, 0, 0, 0, 0, 2, 2,
/*00*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 2
};
is just how I setup a 10 x 10 texture in code
0 is no color, 1 for black end, 2 for white end
yeah i got it
Is the point of IStyle.translate and IStyle.scale etc to eventually deprecate IStyle.transform and the transform methods on base visual element? Or, just another option, or? Just something I've been wondering. I've been using all transform modifications inside of IStyle since upgrading versions rather than the others
I notice in a lot of CSS docs that they include the displaystyle in the root element. We only need to mention the display style if we want the element to be invisible and absent from layout right?
are any of you familiar with IStyle.transformOrigin? I'm trying to figure out how to best handle not letting someone drag a window to larger than the game screen for example, but, having things like shrink on doesn't seem to counteract changes done through translate
Is there something wrong with good old if (newPos.x > gameWindowPos.xMax) return;?
no, not at all, was just seeing if there was anything that had already been natively created just because the pivot will change so need to create a few conditionals
No idea. I would ask on the forums, as the UITK devs are relatively active there so you have a good chance of getting a response.
oh and also, if I'm understanding correctly, might be able to set the pivot with the transformOrigin so in that way maybe I can just base the conditionals off that
but I don't know because I haven't done anything with it yet hehe
I think all of the IStyle transform related stuff is 'new' so I haven't used it yet. I have just been using the normal old .transform property in C#
yeah, that is what I was originally using also, but, I changed over to the style stuff because I thought I read somewhere that some of the things only exist until it is implemented into IStyle, but, I can't remember where i read that anymore
Ah, I don't think that is the case but maybe? Tbh the whole positioning of elements in C# feels a bit messy right now and unclear to me.
Looks like currently TextField fires **ChangeEvent **on every character while I'm editing. Is there a way to change this behavior to commit changes only when I hit Enter or lost focus? Sometimes changes on every character can be very annoying and actually it applies to numeric fields as well. Like if I'm typing 1234 in integer field I probably don't want to use callback four times for 1 12 123 and 1234
Or in that case I should implement custom handling between FocusInEvent and FocusOutEvent?
textField.isDelayed = true; might be what you're after
that's exactly it, thank you!
should have properly read the docs
No problem - if you don't know what you're looking for it's not that easy to find
UI Toolkit: Added UI Toolkit implementation for UnityEvent drawer and LazyLoadReference drawer.
UI Toolkit: Added UI Toolkit implementation of MinMaxGradient drawer.
UI Toolkit: New vector drawing API added to VisualElements.
UI Toolkit: The InputField is now driven by TextCore.
All TextCore text assets (FontAsset, Text Settings...) now work in InputFields.
We have added an inner ScrollView to InputFields.
All TextElements including Labels are now selectable.
UI Toolkit: Added: MultiColumnListView control in UI Toolkit.
UI Toolkit: Added: MultiColumnTreeView control in UI Toolkit.
UI Toolkit: Added: TreeView to the public UI Toolkit API.
UI Toolkit: Added: View controllers used for ListView and TreeView are now public and can be inherited from for more control.
How could i style Slider element in USS? It's kinda hard to figure out by docs, I've only found some C# properties of it.
Some of these native visual elements unfortunately don't offer A LOT of a breakdown yet. You have to use the visual element methods to figure out the nested things in them. For example, a text field has a nested visual element called unity-text-input which you can modify through the UIToolkit API, but, can't inherit from or make an instance of. I'm assuming the slider does the same. Alternatively, you make your own visualElement or Image VisualElement or something and just make your own slider
if you are curious on how to make your own, what I would do is, 1 visual element to be the main container, a child text element for a label, a child visual element for the line texture, a child visual element of the line child as the image
then, either register callbacks on the image visual element to decrease/increase, or, and technically better, make that child element inherit from its own visual element, and alter the default actions of it
Hello guys, so I have one question. How can I like get a debug.log message when someone pressed the determined "cancel" button on UI? Because I set up a join menu and I want the player to reset his actions by simply pressing "b" on controller or any button. I dont really seem to find anything.. im kinda new to this. Thanks for any help
I just realized it wasn't as hard to make a custom input field as I thought it would be. For some reason I kept thinking an input field was different. Just made it so when I click on the field, I can edit a TextElement, or clicking to make a checkmark visible or not
does anyone know if registering callbacks to be called from a visual elements default actions are also better performance than registering to the callback directly?
so I have been creating textures for different cursors and applying them through the style.cursor, but it made me wonder, what is the difference between doing them this way and just doing it through setcursor?
is doing something like this like
VisualElement colorContainer = new VisualElement();
rContainer.Add(colorContainer);
colorContainer.style.flexDirection = FlexDirection.Row;
colorContainer.style.height = 10;
for (int i = 0; i < 100; i++)
{
VisualElement colorElement = new VisualElement();
colorContainer.Add(colorElement);
colorElement.style.backgroundColor = new Color(i * 0.01f, 0, 0);
colorElement.style.width = 1;
}
much more taxing than just doing 1 lets say, 100 x 10 texture?
You would have to measure it but I would certainly expect it to be much worse, yes π .
Side note: Unity will probably release a runtime color picker at some point in the near future. So will I π. Unity one will probably be 2022 only I would guess.
hi how can i change unity input field box to rounded corners?
style.borderTopLeftRadius etc... Fun thing about them also is you can make a full circle if you set them all at 100
They finally made the TreeView public! They have had it just sitting there for years. It was actually one of the 'original' elements along with the ListView. I wish they would backport it. At least it is public now!
Also happy to see the multi column views added. I think all that is missing now is some form of grid view. After that UITK is capable by default of doing everything IMGUI can.
They need to make some of their inner workings of some of the controls more accessible. For example, basic functionality of some things don't necessarily need the overhead that comes with creating something like a Slider through Unitys provided Slider, yet, is easier to just use than creating your own visual element if you don't know what to do
things, like I would personally propose, as an example, would be the polymorphism from UIElements.BindableElement not even exist, and rather the IBindable interface expanded
Why is that?
I disagree, if you need something that simple, then just create it on your own. I think the Slider along with most of the elements have a good level of ease of use, but not overly bloated. Originally the Slider didn't even have a field like the IMGUI one does.
Making custom controls is not some black art. It is a core part of using and extending UITK.
the ease of use isn't my concern. The things they have created are great! What I'm simply stating is that if someone was using UIToolkit and didn't have any experience in the visual element design, I would love it to be easier to access some of the inner workings of some of the elements they have made. The bindablelement comment was more based on the idea that I think certain polymorphism can lead to sloppiness
Ah, I see.
basically, it doesn't make sense to me that something like BindableElement exists and is easily accessible, but, for example, InputField is internal, or private nested within something
but, I know we can also just use reflection hehe. Just try not to first
I could also do what you suggested and actually try and give feedback instead of hoping they read here... lol
Lol, I can almost 100 guarantee that they don't read discord π
Yeah, I do find it odd that InputField is internal...
Note that my opinion is out of frustration also that I just made my own input field haha
Hello guys, so I have one question. How can I like get a debug.log message when someone pressed the determined "cancel" button on UI? Because I set up a join menu and I want the player to reset his actions by simply pressing "b" on controller or any button. I dont really seem to find anything.. im kinda new to this. Thanks for any help
Are you using UGUI (components and gameobjects) or UI Toolkit (new UXML andUSS system)?
im using this
You are using UGUI, so you will want to ask in the #π²βui-ux channel as this channel is for the UIToolkit system.
oh okay thanks
Hey!
I'm trying to use USS custom properties to change the value from C#, is that possible?
I did not see anything like that in the docs, but maybe I did not find at the right place?
Another question: can we create a vector image on the fly to use it instead of drawing via MeshGenerationContext? I hope getting better rendering since Vector rendering is now clean, but not the MeshGenerationContext one
C# has the highest priority if you code properties for him. So, for example, you can treat it as almost an override if you will. You can create the USS as the fallback in a way. In order to not use the C# you need to either reference the value from the USS to the C# part or reinitialize whatever it is the USS side without the C# part
I'm not sure 100% on what this question is asking?
like what are you trying to do
what you say is in C# I can set style.{thing} but, I try to set --some-custom-property? Or I'm wrong?
I want to draw some arcs so I'm doing that via the GenerateVisualContent method, but this does not supports anti aliasing ; recently AA has been added to Vector elements, so I'm wondering if I can create some Vector element at runtime (like I can write SVG via JavaScript in a Web Page), then apply it to any VisualElement or Image
in C# if you set style.{thing} but try to set --some-custom-property which is the same style.{thing} the style.{thing} has priority. The way the style sheets work though is the c# side only applies for that specific thing, so, unless you set something on the c# side for every single property, you can still use the USS as a default case, if you will
But, I want to use custom properties to get the value on many style values instead of defining them manually ^^
that is what the point of USS is for? If you want to do this on the C# side, make a new class that inherits from VisualElement, and make its constructor do the style you want so whenever you use that, it is initialized that way
I don't think you can...
But that doesn't make sense... hmm, you can try looking at the UIBuilder source code to see how it does it.
the point of custom properties is to be customized from the C# side (JavaScript side on the web), otherwise it's useless
custom properties are not variables
This is the best I can find
https://docs.unity3d.com/ScriptReference/UIElements.ICustomStyle.html
only a getter :/ no setter
Yeah :/
make your own interface
yes, I do that all the time, so USS and UXML are useless most of the time... I'm a Web developer and I'm sad about that
@dusty mantle Ah found it.
Apparently you need to register to the CustomStyleResolvedEvent
I'm mostly doing C# to build thing that I should be able to do with UXML/USS but, there are some things that are not available without C# making me going back to C# all the time ^^'
Oh? Did you have some docs or ?
Ah thanks π
Ok so I can get USS custom properties values in C#, but cannot send them?
@tulip sparrow already read that without founding what I want :/
No, the way that it works it seems is that you would register the event with the element that the property effects.
So for text, it registers to that and gets the --unity-font property and edits the text mesh based on that
okay, I'll try to help keep looking. I know it is possible. I just also know as far as the UIToolkit has come, its still very lacking (imo) user friendly in terms of helping people create custom things
I guess it is odd you can't set it
just going to toss out some random links
for a few secs
see if any of them you havent already checked out
I think this is not possible for now, or not documented for now
You can ask on the forums. The UITK devs are pretty active there.
@tulip sparrow I've already check all of links you have sent ^^'
can also try checking out things like https://github.com/Unity-Technologies/UnityCsReference/blob/master/ModuleOverrides/com.unity.ui/Core/UXML/UxmlFactory.cs
And for the Vector thing, I'm doing something like that, and for now it's a lot of pixels ^^' :
Hello did anyone manage to have drag and drop on the new UI builder package ?
I've been trying to learn more about interfaces using UIToolkit. I'm trying to create one and could use a little help if possible. Is it possible to force the use of protected override void ExecuteDefaultAction(EventBase evt) from an interface, but, also, force it to include the correct event to check for?
I guess I could just make a function that has to be used if you use the interface, then make that called from the visual elements override execute?
this is what I'm trying to implement
public interface ICursor
{
UnityEngine.UIElements.Cursor hoverCursor {get; set;}
UnityEngine.UIElements.Cursor selectedCursor {get; set;}
}
rather, rename that to the hovercursor
Serious question:
is there an easy way to force an VisualElement in the shape of a square?
(Without setting absolute height and width values)
Some easy pure css hacks do not work, due to the lack of pseudo classes
a couple I know of is a child visual element with height/width set to make the parent auto change to. A child image with a square texture
I'm not sure if the box visual element they have is default a box
but if it is, they went through the exact process you would need to make it a box also
because of how flexbox works, you need to use these "hacks" to force it as a square. Any square you can get without will not remain a square for long
Hmn damn, i really hoped you'd say "sure, there is a checkbox for that" or something similar π
So your idea is really to add a transparent child image with a square texture to the element and then take those values?
I'd never come up with such an idea, and i'm trying to get a square for 3 hours now π
checkbox, you can use a toggle I guess technically for it's square implementation
ooooooh.. i might be able to put my image into the checkbox instead of any "check mark" content
That might be a brilliant idea!
another thing you can do is just alter the min/max values of a visual element
and make it perma a square size
Thank you for your input π
I do now have hope again, that i'll be able to make it π
the basic way to do that is setting height to zero and using padding-top in percent to get the height
like that, works well most of the time
then in the contents of this visual element you do that:
to get the child positioned exactly in the left-top corner of the parent, avoiding it's padding with position: absolute
that worked well for me cause i've needed to put an image as a child of this square box
so left-top corner works just right
also is it right idea to make all the UI components in C# using UXML-factory and then compose them in UXML?
like the way we do it in web with React basically
may it have any issues?
I've didn't tried yet
it shouldn't. It's important for people to realized that UIToolkit is emulating UXML, as in, it's first and foremost C# code
it's just styled under the UXML banner essentially
I've didn't get that
i mean, i do understand the concept
but what's the answer to my question?
basically, you should be able to implement anything if its on the c# side
i know that i could implement that, and i think i do understand how to use UXML factory
but is it right way to do the job?
like making all the UI elements in C#, and not hacking around UQuery and simple VisualElement in UXML
for example, currently I'm just usually using Query to get the button and add behaviour on it
but what I'm planning to do is to make my own button that has the behaviour in it, and just use it in UXML composing the elements
if I were to base it off of the UIBuilder tutorial, yes? However, strictly speaking, I think there is some differences if you desired it to be primarily be from UXML or from C#. So, if you make something for UXML you should include more of the initialization within the UXML Factory, if C# outside of the factory. That being said, I haven't messed much with UXML Factory yet, so I don't know for sure. I have been including it at all the end of my scripts, but, not actually sure if its correct
when I was looking up some initialization, I think you can initialize elements from the factory, which looked really beneficial imo, but, I didn't quite understand it
like let me see if I can find it again
there is class names and stuff of things that looked to exist inside the factory, but not documentation really on yet, so I was kinda looking I think at what you are trying to do to utilize the factory
doesn't generate visual elements, but visual elements use it to generate schemas
oh yeah, thats what I saw that might help. If you go under window and check out UI Toolkit they have samples on the C# for example
// Action to perform when button is pressed.
// Toggles the text on all buttons in 'container'.
Action action = () =>
{
container.Query<Button>().ForEach((button) =>
{
button.text = button.text.EndsWith("Button") ? "Button (Clicked)" : "Button";
});
};
// Get a reference to the Button from UXML and assign it its action.
var uxmlButton = container.Q<Button>("the-uxml-button");
uxmlButton.RegisterCallback<MouseUpEvent>((evt) => action());
// Create a new Button with an action and give it a style class.
var csharpButton = new Button(action) { text = "C# Button" };
csharpButton.AddToClassList("some-styled-button");
container.Add(csharpButton);
this one adds generated in C# button on the runtime
ohh okay
it's not really acceptable cause i can't see my UI changing in hot reload basically
that's why I'm planning to mess with making my own classes with UXML factory that is exposed to UXML
so i can compose them in UXML before the runtime
if it helps, I just basically just include
public new class UxmlFactory : UxmlFactory<SomeClass, UxmlTraits> {}
public new class UxmlTraits : SomeInheritedClass.UxmlTraits
{
//uxmlattributes
public override void Init(VisualElement ve, IUxmlAttributes bag, CreationContext cc)
{
SomeClass field = ((SomeClass)ve);
base.Init(ve, bag, cc);
}
}
and it works
i know how to do that
the question was if it is best practice for most cases or not basically
yes, what I'm trying to get at is Unity does this in all their custom elements
so I do that
and it works fine
is panel the best way to reference the topmost visual element to make a popup appear above all other elements?
in runtime I have the root visual element to be referenced from anything, but, was wondering other routes
nvm, panel.visualTree.Add(colorPicker); worked perfect
I think I read somewhere that changing visibility completely redraws the element, so, using display = Display.None is atm better? Is that still true?
or do I have it backwards? Or
turns out Unity's panels don't actually have any useful settings already for font. Does anyone know of an easy way to do with font styling? Maybe I need to start learning that stuff idk. Has to be an easier way than if (colorPicker.parent != panel.visualTree.ElementAt(0)) panel.visualTree.ElementAt(0).Add(colorPicker);
mind you, I'm trying to stay within runtime standards so that I can use this at runtime also, so, trying not to use any editor useful things
I didn't know what channel to post in, sorry.
no worries. Just figured I'd send you to the right place. I've been messing around with UIToolkit so much I don't even remember the other way anymore
haha
okay, I think I'm just going to settle with
public static VisualElement RootVisualElement(this VisualElement visualElement)
{
if (visualElement.parent != visualElement.panel.visualTree) return RootVisualElement(visualElement.parent);
return visualElement;
}
for now
now my static visual elements can have a home even if I don't know the root
but to be in front of everything
what am I doing wrong? If I have a container that is 500x500, and 2 containers inside with 1s minwidth to be the width of a 256 width texture, how come that container falls about roughly 30px short
if I inherit from VisualElement, and IStyle, can I override what a style does?
I guess I can just do public new IStyle style;
oh okay, I think I'm understanding interfaces a little better? Can just do something like
public interface ICustomStyle : IStyle
{
int TestInt {get; set;}
}
which will add to the IStyle interface basically? I know I have to do similar with the resolved side also?
What? No? You would need a class that implements your ICustomStyle interface.
There is no way to add properties to a class or interface.
I did, and there is. If you do the layout the same as in the visual element, such as in the case of of visual element, it inherits from the IResolvedStyle interface and creates an IStyle field. You can create your own interface, that can inherit from another interface. The bottom most interface takes priority on any similar named fields.
for example
for example
But you are not adding properties to a class or interface.
you would do it the same way the visual element does it already, such as
I see that, but that still doesn't change that what I said is true. There is no way to add the TestInt property to the IStyle interface.
Directly, no, but to be able to add to it indirectly is conceptionally the same
it means I can extend functionality without clutter
since extension methods cannot override
ehh, yes and no, but sure lets go with that π
one reason I thought this was interesting is it lead me to do
public new void ExecuteDefaultAction(EventBase evt)
{
base.ExecuteDefaultAction(evt);
}
from a base public class CustomVisualElement : VisualElement which actually was quite nice. I've been spending a lot of time in this UIToolkit, and, I find there to be a lot of "clutter", so, I was looking into removing inheriting from visualelement while still having basically all the functionality of a visualelement if I wanted it
also, something I didn't realize till now, is being able to make protected internals public without reflection
Carful with using the new keyword like that as the 'new' method will not be called unless the type is explicit.
To do what...?
yeah, I mostly wanted access to this to specifically call executedefaultaction. Right now I'm just messing around with these things, idk if I'll actually do something with them yet hehe
idk, just something I didn't realize you could do. I've never really thought about inheriting from something and using that object as like a container that stuff from the outside can access
like in the case of the defaultaction based off what you said might be better to not do new and just make a different function that can still use ExecuteDefaultAction
is there a native callback you can register to for style fields specifically? Can't seem to figure out how to. I was assuming you use normal RegisterCallback if you aren't using the INotifyValueChange<T> interface
do all position checks happen from the top left corner? Or does align and justify change those also
hey, what are the possible reasons that a DropdownField cannot be clicked to expand the choices menu? it only works after focusing on it and then pressing space
https://transfer.sh/7oUEcM/a5tQwL4cJx.mp4
I'm confused by some of these structs, why is there StyleTranslate and Translate? I've been dealing with it because that is how it is, but, just something I've been wondering
I can't say for sure based off this, but, when using clicking events there is different things that must be checked, for example, PointerEnterEvent is for a VisualElement AND its descendants, while, PointerOverEvent is for a VisualElement explicitly. Make sure to check you don't have an overlay or something that is receiving priority. Second is focusable you can click on something, and it receive priority from input events, but, if it is the only element there that can be focused, you can still make it receive input events, such as, spacebar, while not actually being the main target of the pointer events
Also, consider using pointer capture and release as it will force a pointer to receive all incoming pointer events while captured
can only have 1 capture at a time, and a new one will overwrite the previous
I'm sure there isn't any overlay, because if I manually assign a MouseDownEvent callback to the dropdown it works perfectly fine
I'm just trying to use the builtin DropdownField component, not to build custom one
how do you use TextElement.MeasureTextSize when some of its params are why you are using it...
I'm trying to make a close container that has options between Remove IStyle.display and IStyle.visiblity, but want to make sure I actually have them correct for what they do. ``IStyle.displayleads me to believe thatIStyle.visiblityalso removes the element from the hierarchy, so, is it doing whatRemove` does?
is there some sort of significant benefit over using the Image control vs just using my own that just alters style.backgroundImage?
I'm add a com.unity.ui in package manager for UIToolkit, but there are some error that spawn like that. So what should I do?
y are my buttons not working?
what buttons? I don't see anything posted about buttons
okay it turns out it was colliding with the old EventSystem
but how do I check whether pointer is currently over the UI without an EventSystem on the scene?
how do I flex equally? Regardless of content, flexGrow = 1 flexShrink = 0? Doesn't seem to be equal, do I need to set the basis also?
on yoga playground doing it this way with no basis makes it equal, but, in actual runtime it doesn't, but I can't put similar content in the playground that I do in unity hehe
I need a good name for my forced width/height. Do you call that absolute?
Not really? That is just setting the width/height.
I mean, yes that would be the name I guess.
oh, does setting width/height force a min/max?
No, setting the width/height forces the element to be that height/width π
min/max is used along with the normal flex sizing
oh, I guess, it might be easier to edit height/width and turn off flexShrink and flexGrow?
trying to think about best way to go about forcing an element to be a certain width/height no matter what
Then yeah, just set the width/height, that is literally the point of it.
To set the element to be a specific size.
oh okay. I assumed flexing would still alter it, but that is good to know! TYVM, will save me extra haha
Order of importance from most to least.
- width/height
- min/max
- flex
oh there was the inherited list
?
The following properties are inherited:
color
font-size
unity-font
unity-font-style
unity-text-align
visibility
whitespace
on that page
how to add layout code (uxml) to a custom VisualElement?
how do I get a strings length at runtime? I'm not quite understanding the domeasure
I've been using UIToolkit off and on for two years or so, but now I've hit a strange problem: images are always rendered downscaled by Unity whenever placed inside a custom inspector. Has anyone encountered anything like this ? (and hopefully: found a fix?)
Hello, do you attach all scripts that update UI elements (i.e label value) to the game object that contains the UI document ?
Or Is it good practice to have multiple UI documents in your scene ?
"document"?
By definition, flex-grow gives all items an equal share .... if you want them to grow by equal factor, you have to set 'grow = [width -or- height]' on each item (grow is only a ratio).
Shrink ... does not use the same algorithm, and is a bit more complicated to describe. But I've used the above to force things to maintain same ratio lots of times, should work fine.
...apparently this is unexpected/a bug, so I'm going to file a bug report on it
ty for the responses! I'm trying to better use relative containers so that I can make more premade UIElements, out of frustration when I can't seem to figure out something yet through the yogalayout playground I just make it absolute, which honestly isn't that bad, I just end up having to make more changes through the GeometryChangeEvent. Do you know if there is any of the interfaces you can read data changes from before the next frame? Maybe have to use ImmediateElement?
hey it seems that Dropdowns dont work on mobile platforms by default - any way to fix it?
Make a script that inherits from dropdown. Do all the initialization in the constructor. Make sure it is registered to a pointer event
thanks, ill try it out
It's worth checking out the default execution that already exists on UIElements. Depending on how you have your ui setup, something else could be capturing the mouse events
hm its already registering PointerDownEvent
in an empty project it's not working either
if it already is, try checking other elements and make sure something else isn't receiving priority through trickledown/bubbleups, or capturing the mouse
only one thing can capture the pointer at a time, but, it's the most recent to capture and capturing always overwrites the previous one
also, make sure you don't have an absolute container covering the UIElement that doesn't have picking disabled
btw do I need to add Panel Event Handler to gameObjects with UI Document?
or panel raycaster
or do I need to have an event system in the scene?
I think you need to just be using the newest input system? Not entirely sure, newer versions already have that built in, what version are you on? Also, are you having a problem with nothing showing up in dropdown, but it interacting? If so, do you have the dropdown being populated? Just from that SS I don't see anything at all, IDK if intended
Im using 2022.1.0a16
and the dropdown is populated
on pc working perfectly fine
on android its showing that it's focused but not opening
okay, the only thing you should need then is UIDocument, however, the UIDocument does not default populate the theme style sheet
π€ maybe mousedown and pointerdown are colliding so one is opening the popup and the other is closing it?
so you need to either create one yourself, or, use one of unities
which could be part of your problem
the UIDocument doesn't default render text
oh okay, that is good to know. Sorry, just trying to go through all steps possible
I haven't tested on mobile yet the stuff I'm working on. I also don't actually use any of the uxml things and just do all my UIToolkit from c#
so everything usually always works hehe
sure
I dont think it's the matter of uxml
give me a second on this, trying to find the answer again because I forgot what it was so don't want to give you an incorrect answer. You CAN use both of these, but, one does have precedence over the other if used for the exact same thing
Mouse events are always preceded by the corresponding PointerEvent
good to know
so, if you could be technically canceling your mouse event if your do something with the pointerevent right after
its receiving pointer down, mouse down & click at the same time
but weird that it works on pc
click is after a downEvent with a successful upEvent on the same element, pointerEvents always precede mouseEvents, not remove them
not necessarily. Depending on your mobile device, it may be only registering pointer events. Have your been able to debug at all through a mobile device
maybe the if statement at the top is breaking something?
the screenshot above is log of the project installed on my phone
.
oh okay
You have populated the dropdown correct?
Hello for updating UI values in runtime , should I use binding or regular .Q<label>.text in my code ?
let me see if I can get my phone setup with the unity remote
from my understanding binding at runtime isn't currently supported.
i think unity remote can work differently
Ok thanks
oh okay, sorry then π¦
i dont know exactly but i suspect it can process events differently
uhh ShowMenu() is private so I cannot open it manually :/
ohhh cool!
well, is the mouse event capturing the pointer?
yeah everything is working fine except it checks if the pointer location is inside visualElement
and it returns false only on mobile
when I mean capturing just in case you didn't know, I mean using the literal property that captures a mouse and makes all mouse events send to that visual element till you release the capture or do a capture from another element
uhh with code, I know you can do a hasPointerCapture check
IDK which, if any any, of unitys visual elements them made default captures
but, I personally use capture anytime I'm dealing with pointer/mouse events
you mean this?
yeah, that checks, to actually capture you use CaptureMouse() or CapturePointer(PointerID) and then the releases
for example, I do something like
protected override void ExecuteDefaultAction(EventBase evt)
{
if (evt.eventTypeId == PointerDownEvent.TypeId())
{
this.CapturePointer(PointerId.mousePointerId);
pointerPosition = evt.originalMousePosition;
}
if (evt.eventTypeId == PointerUpEvent.TypeId())
{
this.ReleasePointer(PointerId.mousePointerId);
}
if (this.HasPointerCapture(PointerId.mousePointerId))
{
if (evt.eventTypeId == PointerMoveEvent.TypeId())
{
so on pc it isnt captured
(d is the dropdown and vi is the visualInput)
lemme check on android
you don't need to capture, so I don't think the defaults have capture, I'm saying I capture in complex situations as to force mouse events to be sent only to that visual element while captured, and so my capture question was mostly towards do you have something else capturing preventing the dropdown from receiving events
oh okay, so no, its just an empty project
with one uidocument
that contains a simple dropdown
just to test it in default circumstances
oh okay. Sorry, I know I haven't been much help. My dropdown menu is custom π¦
you actually helped me quite a lot haha
maybe i can just copy the unity's code of dropdown and remove the containsPoint check
I had a similar problem with elements not showing up randomly in scroll view for example, so I built my own haha
cuz im too lazy to create a custom dropdown
to save your time I personally found in visualElements is inherit from the specific things you want to alter, and then build down, so, for example, inherit from dropdown, and take advantage of the overrides and stuff till you want to make a more complex dropdown menu possibly
the cool part about doing this also is you kinda already create a container for that visual element, some might consider it excessive, but, I love making a separate container for basically every single visual element
sure thanks
btw how do you check if the pointer is over any ui document?
like EventSystem.current.IsPointerOverGameObject
that I'm not sure of, I think you just in a visual elements OnOver do something like ((VisualElement)evt.target).panel to confirm the panel, but, I haven't done multiple UIDocuments yet, so not sure. I just have one UIDocument and make it the size of my screen like the older canvas, and just essentially make root visual elements within that rootvisualelement
how come some styles not defined seems to apply the the auto stylekeyword though it isn't defined, and others dont, and where do I find all the automatic style values that might be set
also, how come something like flexDirection is automated, yet, isn't checked as inherited, so, if you were to do something on the next child element of that element assuming the flexDirection, you have to go back and actually set the flexDirection though it could already be doing a flex in that direction
Hello, what is the best approach to instantiate a visual elements and its children at runtime ?
Hi. How can I change the value of a PropertyField without triggering a notify?
change value without notify
Yeah uhm... How?
I don't think a PropertyField has this method.
Toggles, ObjectFields have it, but PropertyFields don't.
you can add the INotifyValueChanged interface yourself
was more of the link
At least I think? I haven't checked if that is internal
My game is in 240p. UI text looks dreadful. The left is textmesh pro and the right is standard UI text. Is there a way of making this look less terrible, maybe by removing filtering?
Thatβs Unity UI using GameObjects right? This channel is for new UI toolkit that lets you create editor UI and runtime UI like html/css.
Just to make sure, there is no reason I need to if check style.display = DisplayStyle.None on a uielement that I have do something "on open". I just have style.display = DisplayStyle.Flex and style.display = DisplayStyle.None; in the close
like, there is no reason it would set it twice and cause some sort of issues?
Say I want to have a settings menu appear as a pop-up over the main menu. Is it possible to do this without duplicating the main menu, switching between the two, and maintaining both?
yes, depending on what you are trying to do exactly, there is multiple ways. I personally chose an extension method
public static class VisualElementExtensionMethods
{
public static VisualElement RootVisualElement(this VisualElement visualElement)
{
if (visualElement.parent != visualElement.panel.visualTree) return RootVisualElement(visualElement.parent);
return visualElement;
}
}
basically will go to the first visual element in the panel, you could go as far back to the panel if you want, but, Unitys default editor panels for some reason don't have any things attached to them for text etc..
I guess note that that isn't a big deal if you implement your own custom fonts, but, since I'm doing things based off Unitys default things and those are naturally inherited, it was for me
Maybe I'm missing something, but isn't that just visualElement.panel.visualTree.children[0] but potentially with lots of extra steps?
it should be, but, I was encountering errors when I did that
oh, that wasn't it, I remember now
it was to make sure that I was at the top of the root for that specific thing without accidentally being in a different branch of elements
so, if you have multiple branches from the panel, it may not always be in [0] or [1] etc..
Ah
so, for example, this color picker I'm working on, I want it to popup in front of everything in that hierarchy, but, not everything completely
so I use this, then send it to the front, and make it absolute
side note, this was because of editor things that were annoying me. At runtime my UIDocument field is static and accessible from my game manager
so I don't use this there
Has anyone got working code for reading the width of the Inspector window? (NB: there's a Unity API method for it, but it's broken in all versions less than 2021. I need 2020 absolute minimum, and realistically something that wokrs in 2019)
Hey! I can't seem to figure out how to swap a background image for anther sprite of a VisualElement (since that is what I have dragged in the Ui builder). I found that I can access the "Background" struct by calling GetFirstOfType<VisualElement>().style.backgroundImage.value but I can't seem to find a way to set the sprite to something else. I would really appreciate some help with this π
backgroundImage is a struct. Your IDE should be telling you that you cannot set a value on that directly and should auto-fix this for you if you try (if not: get a better IDE). The code will be something like: ....style.backgroundImage = new StyleBackground() { value = { texture = blah}};
(you need a Texture2D reference first, use any of the Unity methods for loading a sprite in C#)
Possibly a silly question, but - is there any actual usable documentation for using UI toolkit at runtime? Seems like it's been recommended as the default for new projects for a couple of years but the only examples are for Inspector and an Editor window - https://docs.unity3d.com/2021.2/Documentation/Manual/UIE-Getting-Started.html
I don't think it's been recommended. It's intended to become recommended
I'd say it's a long way short of being ready for runtime. A few brave souls are using it for that, but there's many gotchas.
That said ... it works fine for basic usage.
Yeah, seems to depend on which page I look at in the docs as to whether it's "recommended" or "intended to be recommended".
It's a bit of a joke to have something that came out 3 years ago and still isn't finished. Not sure what I expected though.
Thanks for the advice though - saves me a bit of grief. π
Well i'm trying to implement a runtime UI in my Game using the ui-toolkit.
It's a bit of a pain. The amount of infos and quality of documentation is painful π
But all in all it works ^^
Hello, is there a way to view the hierarchy of a visual element in runtime ?
you can use the element debugger to inspect it (accessed via the tripple dot hamburger menu in any editor window)
or UIElements Debugger in 2019
jesus sweet thanks, I've been stuck on removing a runtime visual element from hierarchy π
when I do something like
accessor.RootVisualElement().Add(instance);
instance.style.display = DisplayStyle.Flex;
Is there a reason I should make sure the displaystyle is flex before setting its parent?
does unitys default dropdown field have a way to already detect changes? I just hope i'm not doubling down on doing
dropdownField.RegisterValueChangedCallback(OnChangeEvent);
}
DropdownField dropdownField;
void OnChangeEvent(ChangeEvent<string> e)
{
Debug.Log("Test");
}
So this is a game runtime question. I am creating a resizable draggable window control (Popup Window, MDI Window, Floating Window - think floating inventory window that you can drag and resize). Things work except if I move too fast I move outside the control and no longer get events. Is there a way to register global mouse callbacks in the ui toolkit? Or is there some other approach I should be looking at? Unity: 2022.1.0b2
Answering my own question - MouseLeaveEvent/MouseLeaveWindowEvent is the trick. I treat them like MouseMoveEvent which moves/resizes the window keeping it under the mouse.
Are there any examples using the MuliColumnTreeView or MultiColumnListView somewhere?
My Editor window does not match up with the UI Builder whatsoever, does anyone know what the issue is?
public void CreateGUI()
{
// Each editor window contains a root VisualElement object
VisualElement root = rootVisualElement;
// Import UXML
var visualTree = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>("Assets/Game/Inventory/Editor/ItemSheetEditor.uxml");
VisualElement labelFromUXML = visualTree.Instantiate();
root.Add(labelFromUXML);
}
Can I use binding-path of a Button to bind it to a method? If so what format do I need to specify?
Not for runtime methods. For editor binding there is some info on the unity UI elements documentation
There seems to be no mention of method/actions on the online docs though..? So I'm assuming it's not supported at all
Hey guys. Any idea what UI is included in 2019 version of Unity?
I want to make a UI mod for game that is already based on IMGUI, but I don't want to use it. I want to use some other UI system instead.
I don't have any access to editor in this case, I only have scripting options.
Anyone else have the issue that the UI builder preview does not match the runtime ui?
It seems like labels take more space for some reason
Left is the UI builder preview, right is the runtime UI
The thing that seems to be massively different is the spacing between two vertically aligned labels ("dexterity" and "10"). On the right, the strength and 10 are 1 label with a \n in the text, and the dexterity are two labels. I'm not sure why the spacing is so massively different in the preview and runtime. All margins and padding is at 0
Is there a way to disable horizontal scrolling on a scrollview? I want a scrollview that can only scroll vertically.
Hello, it is possible to place elements to static place in scene? (Like UI elements in Canvas world space) Thank you! π