#🧰┃ui-toolkit
1 messages · Page 11 of 1
but it's definetely will cause problems with compatibility
in case someone else would like to use dependency
which includes System.CompilerServices.Unsafe
so I think how to fix that
yeah, it's not portable enough sadly 
either I use openupm dependency
and my package requires about 4 lines
or I use both options via compilation constraints
but honestly, I just want nugget
🥲
just. don't 
it's assembly wise, so good enough
are you also aware with the assets store concept of publishing stuff there?
I don't publish to asset store
can we just tuck in stuffs in manifest.json and be done or is it not possible?
man, if only jsonutility or even Unity's newtonsoft weren't suck so bad
jsonutility is good when serializing game objects
@gusty estuary from the creator of com toolkit you're using https://github.com/Sergio0694/BinaryPack
yeah, can't be used in Unity
dynamic il
Dont think I use it
didn't your mvvm toolit built using windows comminity toolkit?
Not windows one
where did you get the nuggete?
yes that's the same dude who created it
This package includes a .NET MVVM library with helpers such as:
- ObservableObject: a base class for objects implementing the INotifyPropertyChanged interface.
- ObservableRecipient: a base class for observable objects with support for the IMessenger service.
- ObservableValidator: a base class for objects implementing the INot...
he's the creator
I know
mic employee.. active member of c# disc too
did you check his PolySharp repo as well?
no
I wonder tho, if we can use that in unity
not sure on usage tbh
Have you looked at https://github.com/xoofx/UnityNuGet ?
yes, it's horrible
openupm is 1000 times better
lol openupm's nuget support uses UnityNuGet
proly different internals... also makes sense bcos as said he's Unity's employee
UnityNuGet is a service that converts nuget packages to unity packages automatically, it doesn't matter how you consume them (git or openupm)
I'm so happy that my vscripting is leak free now 
If there's something on nuget you want you can just add it to their registry
what do you mean by portable?
you'd have to add them manually via project settings
better than shipping dlls from nuget in your package and causing problems with other packages
if they're dependency free dlls, shouldn't be an issue.. and I prefer that any day
who is? author of openupm or xoofx?
xoofx
if you're talking about dependencies of your own package then using a registry doesn't matter because the user doesn't have to do anything?
it does
in openupm you have specify all dependencies (sadly)
in nuget package you don't
but nuget package also breaks all the time
with the 2d painter can the shape generated detect mouse events
nevermind im going to use a texture instead
writing code for every shape i need is going to take forever
is there a way to stop :hover etc from activating if mouse is over the transparent part of the background texture
it can, you can registerCallbacks as you normally would
yeah i cant use the painter though wont let me use textures
so what about transparency on sprites
it can
since when ? docs says you can't texture the painter atm
anything regular visualelement can do, it can do it too
i think it would still be more performant just using a premade sprite of my shape though
than generating a mesh
they're vector graphic in a sense, so they consist of just vector lines, similar like in SVG
to texture it, you assign to your wrapper class
which is a VisualElement
painter2d lives in your MeshGenerationContext...
MGC is what forms your visualElement's meshes (the order kinda important to understand here)
they're the same.. as in, identical
I tested this intensively when I made my shape gen tool with vector api
another way is to export painter2D to VectorImage type... then assign it to your empty visualElement (the same workflow like in vector package with SVG)
if they are then why does it detect mouse over on the transparent part of the texture
is there no way to stop that happening
because i dont want hover to occur over the whole visual element
in ugui you could set a alpha threshold so it didnt detect mouse over if over transparent pixels on the texture
i cant find something similar in ui toolkit
Ah that, yeah, they're not working properly at the moment due to mouse events/manipulators would take rectangular shape of visualElement for it's bounds, somebody mentioned this on the forum already iirc
i see
Sprites aren't vector, it would suffer from aliasing when zoomed in/out. VectorImages on the other hand are actually true vector graphic that consist of vector lines
also they're in progress implementing texture atlas in VectorImage class, you can see this if you peek at some of the internal stuffs in VectorImage class
so proly custom shader after that 🥹 .. * fingerCrossed
vector api + custom shader.. boy many cool stuffs can be done with it 🥹
i just hate that we have to write so much code atm
i want a hexagon shaped icon
i got to fiddle with painter to do it
all painter has is arc and line - it needs a collection of basic shapes built in at the very least
polygon(radius,numsides) would be nice for hexagons/octogons etc
that's the nature of UItoolkit at the moment sadly
*(whispers.. *cough..cough.. DOTS too)
lmao
but it is by far the best UI system Unity can come up with.. and I like the concept of UITk as ui system in Unity tbfh
and the best of all, making custom editors now are billion-light-years wayy easier with uitk.. it's splendid 🥹
easier but more work most likely
that's a valid statement, no lie..😂
if you ever used any graphic libs in plain c#, they're the almost the same
even the good ole System.Drawing did it like that too
Released
in a custom element script how do i query for a child element
i need to change the width of the child element for a progress bar
or is that not possible
custom elements are meant to store all references during construction
how do i setup the references
during element creation
i want to be controlling the width of the child element since its a progress bar
yes i know but the syntax i meant
i cant use Q<T>
query works, but during constructor you don't even need to use it
so how do you do it then
if query works i dont seem to have access to it in the constructor
MyElement(){
_label = new Label();
Add(_label);
}
no in a custom element class
then you gotta create it on the fly
thats absurd
because whats the point of templates if i have to create it
my CC i want to include the heiarachy so i can control the size of the child element
so theres no getChild(0) or anything useful like that
during constructor element is empty until you fill it yourself
so id have to apply all the styles aswell
that seems a step backwards compared to prefabs they use for gameobjects which work fine
I'd disagree
they exist on completely different levels
custom control = custom logic
it's not asset
because you have to make shit on the fly - writing scripts all day instead of actually making a game
you create all modular controls you need and create hierachies out of them?
I mean, I only had a need in one custom control in total
square element
because there is no such built in functionality
everything else I just use built in
the way i have it is:
progressbar-background¬
progressbar-foreground
i want the custom element to control width % of the progressbar-foreground
so i need to reference to it as a child
then create it via code
don't bother with uxml
the only way to load uxml like that is via resources
and you can imagine how painful that'd be
i really dont want to hard code it all encase i change my design weeks later
thats so damn silly
it might be great for custom tools but it forces you to hard code it all
you lose the ability to adapt quickly for new design
some default controls can be accessed directly here's from Toggle class
they're available as properties
are they creating them in constructor ?
you don't hardcode styles
only hierarchy
just take a look at Button constructor
eh, I don't really agree
you can change hierarchy completely
but keep frontend same
yeh but if you wrote it all in code you have to edit the scripts
that's why it's custom control
not template
if you want template - just use template
by defining custom control you define MonoBehaviour in comparison to game objects, not prefab
so like this:
VisualElement _ele;
public ProgressBar()
{
generateVisualContent += Refresh;
_ele = new();
_ele.style.flexGrow = 0;
_ele.style.height = Length.Percent(100);
Add(_ele);
}
protected virtual void Refresh(MeshGenerationContext context) => _ele.style.width = Length.Percent(_progress);
``` ?
uuugh, why are you using refresh
because unity does it ?
the override uses the context for painter
_ele.style.width = Length.Percent(_progress);
that uses painter
just don't do this
why not ?
if it wasn't the same value it'd be recursive
🤔
because you are not doing anything here
you simply write value again
causing layout to recalculate again
to the child element
but luckily it's smart enough not to do it
when child modifies, layout also gets dirty
unity does the same thing though
so you saying i should just apply it in the property setter
hm
i see
that would break the radial progress bar since that doesn't change width
that overrides the refresh method
you override refresh only when you need specifically refresh logic
making custom shapes
when you modify width - you schedule changes to engine
i see
so generateVisualContent for displaying the change but not applying any changes
use callbacks for drawing only for drawing
if you progress bar is only about modifying width
then do it in property setter
later in frame layout will do all drawing callbacks
if you have those
do i not need MarkDirtyRepaint();
in the property then if i change the style width
is that redundant?
okay
if it's related to changing the context, you'd use markdirty otherwise don't
wdym by changing the context
I don't follow either
changing shapes, changing visual appearance(physically) that modify the mesh
like in TextElement
ah
for common controls, you'd never want to use that
when you don't do width change, no recalculation is scheduled
correct
and if you need to recalculate shape - gotta mark as dirty
so my radial bar that uses painter i should use it to redraw the arc?
if your radial bar has constant size and when you change progress you don't apply any styles
you should mark as dirty
so it makes a generate callback
if your progress bar is literally just width
you do it in progress property and that's it
yes, same as any style changes
(hopefully unity is smart enough to know what styles modify layout)
I recommend to read this horrible docs ...https://docs.unity3d.com/ScriptReference/UIElements.MeshGenerationContext.html
just use your common sense to understand it, nothing to see there.. lmao
pls
ah thats a pain i cant apply a class in ui builder for the child i made in the constructor =/
so i dont have much freedom to change the style easily
you apply classes during construction
i want to change them based on what ever im building not having them applied in the code
usually all relevant custom elements of custom control have unique names
its a progress bar for many things
that's exactly what I talk about
you just said applied in code
you never access style
i dont want to write code for every custom progress bar
you only use AddClass
because im designing my layout in builder
i dont want to write code all day for all the combinations of progress bar styles i want
but i cant see it in the ui builder
actually you can
without writing code to apply them all so its not easy to swap between classes to try them out
it's just broken
kekw
you can inspect all classes that exist on element via debugger too
but since it's your own
you know all classes
so just make stylesheets
using them
you don't ever need to use style
well how else do you change the width lol
via stylesheet
but its related to game code
no
player health etc
if i want to have a blue progress bar i cant simply just change it to blue
id have to write it in code
thats moronic
it shouldnt be though
well, it is
(╯°□°)╯︵ ┻━┻
I know the trick though
this is what i was saying by unity over complicating this
you define 2 visual element
0 sized
(this can be hardcoded too)
apply to them your class names
for example
why does unity's controls let you do it but our own do not
.color-health-full
and
.color-health-low
and then in your progress bar code you read colors of those elements
to modify visuals
when you change Health property
?
I am just telling you how to do it properly, so you can easily switch styles via stylesheets
why cant they just let us do this
then i can change the colour so easily in ui builder
because it's custom control
it seems to be custom controls are also restricted by style aswell which is utterly stupid
its all well and good adding it to constructor but i to test different classes to see how they look
so i have to edit the code every time
don't confuse style and class
class is just a tag
style is actual data about visuals
but you need a class to define unique styles
so define it
eg player health, loading progress bar etc
add both your classes in constructor
and use stylesheet
to apply styles
look at Button implementation, sir
wheres the source code for button
ctrl + click
i meant the c# source code not the uxml stuff
i think i understand
i have to create a matching class in the uss then i can edit it
so for unity's built in one i have to create a class with the exact name they have defined
or add one that matches one i made in game code
You would have known all that if you actually read manual 🙂
https://docs.unity3d.com/2022.2/Documentation/Manual/UIE-USS.html
yeh i just dont know why game code can add a class to a custom control but the ui builder will not let us it seems like a pointless restriction no?
take a look at uxml
and try to find element you want to add custom class to
and you won't find it because it's created in runtime, not during uxml authoring stage (what UI builder is)
i see
You should switch to the latest docs when reporting issues, as you can see it all fixed
Yes 
yeah, I rarely did that, I just linked what came out 1st on my search engine 
ah, good to know
when i google docs it still gives me unity 5 docs some times
very annoying then when you click latest version it takes you to main page not the actual page i was on
yeah, that's why I never bothered.. it's been like that for years
Call Bind on the root when you have populated the fields
on the root VisualElement?
The Bind() extension method sets up an entire hierarchy of visual elements with specified bindingPath properties. You can call the Bind() method on a single element or the parent of the hierarchy that you want to bind. For example, you can call Bind() on the
rootVisualElementof an Editor window. This binds all child elements with specified bindingPath properties.
Don’t call Bind() from the Editor.CreateInspectorGUI() or PropertyDrawer.CreatePropertyGUI() override. These overrides are called automatically on the visual elements that these methods return.
cheers, that works perfectly
Unity packages seem to create settings panels a different way each time
you mean between UITK and uGUI?
just between the UITK ones, some load uxml, a variation of different ways added from code
the entities package has some serious ui framework too
ah yeah, that's confusing too 😅
How can I query this element? (screen attached)
code below returns null
var spriteField = root.Q<ObjectField>("unity-input-RegisterSpriteData.Sprite");
and when I try to print all root's children names I get only 14 children with names like PropertyField:Sprite (which I believe corresponds to just class field). Why I see different names in debugger and in console?
foreach (var child in root.Children())
Debug.Log($"{child.name}");
full code
using UnityEditor;
using UnityEditor.UIElements;
using UnityEngine;
using UnityEngine.UIElements;
namespace NSprites.Editor
{
[CustomEditor(typeof(SpriteRendererAuthoring))]
public class SpriteRendererAuthoringEditor : UnityEditor.Editor
{
private const string SpriteFieldName = "unity-input-RegisterSpriteData.Sprite";
public override VisualElement CreateInspectorGUI()
{
var root = new VisualElement();
InspectorElement.FillDefaultInspector(root, serializedObject, this);
foreach (var child in root.Children())
Debug.Log($"{child.name}");
var spriteField = root.Q<ObjectField>(SpriteFieldName);
if (spriteField == null)
{
Debug.LogException(new NSpritesException($"{nameof(SpriteRendererAuthoringEditor)} can't find field named {SpriteFieldName}, which supposed to be {nameof(Sprite)} field"));
return root;
}
spriteField.RegisterValueChangedCallback((context) => { Debug.Log(context.newValue); });
return root;
}
}
}
nope.. there's IMGuiContainer for that
they already fully switched to UITK in 2022?
to show default inspector on top of uitk host
this line isn't necessary, but hiding it fixes nothing
nah, IMGui in fallback mode since 2022.2.x, it won't be removed anytime soon for back compat
the dot in the name seems suspect to me
I'm curious if ObjectField field exists by the time you query
you sure there isn't any scheduled behaviour?
mee to, but how then should I write my code to access field I want
I mean, I was assuming it's either IMGUI or UITK
not both
same thing, via query
just gotta figure
it should be delayed then
where does it exists (and possibly when?)
YOu could use debugger
and try to inspect hierarchy
ugh I hate how things designed
debugger says that I do all right 🙂
or do it the dumb way, tuck in dummy data to userData
oh, ok, got it
what default?
first method
InspectorElement.FillDefaultInspector(root, serializedObject, this);
shouldn't be
but by the end of this method your call should finish
it may be contained in uitk host via IMGuiContainer which is fine..
and yet it's not even created yet
public override VisualElement CreateInspectorGUI() I am talking about this
that's correct
this is just static method which constructs VisualElement with default UITK elements of given serialized object. What recursive it can be?
you specify Editor this
I guess it is just for extracting some data. If it be recursive then I should get zero console messages, because they happens later on code
It's not recursive.
🤔
just another great experience with unity's great package
It seems I can access serialized property by querying PropertyField:FieldName but field I want access is inside a serialized subclass and when I try to access children unity says that child count is 0. Fantastic!
InspectorElement.FillDefaultInspector(root, serializedObject, this); let me do complex things for u little programmer, but oops, names are not the same at init time then in runtime... and also there is no hierarchy... so pls do dirty tricks and wait for next frame in Editor
there's an init trick with Schedule or AttachToPanelEvent
not really dirty
can u share? 🙂
quite literally either use schedule of ve
or register panel event callback
which you unregister during callback
Schedule allows for specific time frame awaits
and callback is... callback 😅
yeah, but what is Schedule in UITK and what is AttachToPanelEvent?
schedule is property with scheduler
and events are registered via RegisterCallback
@gusty estuary I already make root.RegisterCallBack<GeometryCgangeEvent>() to react to "all is ready". Is it what you mean?
Hi guys, sorry to interrupt but i'm kinda new. If a have a specific graph view question can i ask for it in this channel? should i do something or can i just drop the question here? thanks for the help and sorry again 🙏
Hi, I have a problem with layering. I have a row of bookmarks, which need to be hidden by a book layer. The problem with this approach is that they aren't clickable as the book's background covers the entirety of the document. Is there a way to get around this?
for custom elements should i put public methods that provide animation or should i do animations in game code on the visual element what would you typically choose in terms of clean design ?
i can either do ele.schedule or ele.Animate() which is my own function
not sure what would be a smarter design
isnt there a z ordering some where
Set the picking mode of your book to none (and add a blocking element below everything if you need it)
for a progress bar with text how can i have the text overlay the inner progress bar
my current solution is to use absolute position for text so its on top of the progress bar
but not sure if thats a good solution even though it currently works
seems to work even though the docs says not to use absolute position where ever possible but i cant see a better way
Where does it say not to use absolute?
it doesnt say not to use it just not to use it where ever possible
It’s discouraged to use Absolute position mode, as it bypasses the built-in layout engine in UI
Toolkit. It might also lead to high-maintenance UI where changing the overall layout would require manually updating individual elements.
https://docs.unity3d.com/2021.2/Documentation/Manual/UIB-styling-ui-positioning.html
but i dont see any other way to layer the text on top
I think that's a pretty silly recommendation, definitely not one to take whole heartedly as advice to not use it where possible.
That page is not present in the new documentation, so I've no idea if they removed the advice
ah so i see
2023.2 has Absolute-position elements appear on top of any siblings that are Relative-position. so i guess i am doing it correctly
Ah, the page still exists under a different name and they have removed the nonsense advice
nah they just moved the nonsense under a new heading lol
Yeah... mmrrrr
ill stick with absolute for now until a problem arises
i think their own progress bar used absolute for text label too
I submitted some feedback on the page in the hope that they'll clarify the advice some more. I believe they're practically just not advising it for typical layout, similar to how it's silly to try to do everything via absolute positions in UGUI
To me, it's a tool like any other. You bring out the tool where it makes sense, it's not discouraged to use the tool under those scenarios, in fact it'd be silly not to.
It really is up to you. I'd do it via property like 'shouldAnimate'
So that for game logic nothing regarding ui framework is not exposed
Could anyone help. Because my game have guest and logged in user, I create button events on enable. and then once more when user logins, as behavior changes of some buttons. But as it has already registered call back, it registers it again and I get double call of the button. what is best practice to remove visual elements click callbacks?
visualElement.RegisterCallback<ClickEvent>(ev => ToggleButton(buttonAction));
visualElement.UnregisterCallback<ClickEvent>(ev => ToggleButton(buttonAction)); does not work, as it does not have correct reference and maybe because I pass parameter. not sure tbh
lamda cannot be unregistered unless yoy store it by value
so if I would write this way I could remove the call back? or how should I write it?
visualElement.RegisterCallback<ClickEvent>(ToggleButton(buttonAction));
private EventCallback<ClickEvent> ToggleButton(Action buttonAction) {
throw new NotImplementedException();
}
private EventCallback<ClickEvent> _example;
...
_example = ev => ToggleButton(buttonAction);
visualElement.RegisterCallback(_example);
...
visualElement.UnregisterCallback(_example);
or proly self unregistering via detachpanel + local function
public static T OnPointerOut<T>(this T visualElement, EventCallback<PointerOutEvent> callback, TrickleDown trickleDown = TrickleDown.NoTrickleDown) where T : VisualElement
{
void Unreg(DetachFromPanelEvent x)
{
visualElement.UnregisterCallback<PointerOutEvent>(callback, trickleDown);
visualElement.UnregisterCallback<DetachFromPanelEvent>(Unreg, trickleDown);
}
visualElement.RegisterCallback<DetachFromPanelEvent>(Unreg, trickleDown);
visualElement.RegisterCallback<PointerOutEvent>(callback, trickleDown);
return visualElement;
}
untested, but the local function should capture it properly
Also may not be suitable for the dude, just an idea I've for a while due to how my uitk projects always bloated with registering/unregistering callbacks
another neat usage of local function, love it
what's the difference between Button.clicked += func and visualElement.RegisterCallback<ClickEvent>(func); ?
button.clicked uses pooled event (if any) and automatically stopping the propagation
The latter doesn't, you'd need to handle those manually (if you prefer to do so)
no reason not to use button.clicked, if it's already a Button
surprisingly it works perfect on editor but on webgl for some ghostly reasons it does not. I just gave up and created totally new logic for Login >.>
Thank you for your suggestion. but it made me feel too stupid X.x
Button.clicked automatically implements gamepad/keyboard support
how do you get the pixel width of a visual element
i tried resolved width but it doesn't seem correct
it's important when you tried
on the context redraw
it's still calculating then
i see
can attributes be set by the class selectors etc?
or can that only be set by binding
so i have to write the uxml or can it be done in ui builder at all
because custom element using painter is kinda weird we can't use themes for it
ive setup the factory so i can see them in inspector
but i wanted to change the colour and line width via the usual style class setup
because it uses the painter2d
yeh i didnt understand the trick tbh
@gusty estuaryis there a performance cost if i keep making ui documents of each ui elements and then making a ui document and using lots of ui documents to build the overall result
im using ui documents as a sort've prefab idea
but i dunno if i am going a bit overboard with it 😄
the bigger your current hierarchy - more it costs to recalculate
but if you disable some parts of it via
Display style
then they are ignored (fully disabled)
I personally keep only one UIDocument usually
and just add all screens to it
fully premade hierarchy on startup
and then when I need to navigate between menus I simply switch display style
everything via classes btw
oh i see
so you make a controller which switches what you want to display
i was making lots of templates of different elements
then creating my overall ui with all the templates essentially
so i can copy paste a lot of it if that makes sense
but if lots of templates hurts performance i'll avoid it
interesting do you not have similar elements used through out though
I use basic elements mostly
i see templates kinda like prefabs in gameobject world
they are
i am noticing performance problems thats why i ask
my painter2d is a bit laggy when animating the progress bar
but that could just be ui toolkit being not fully optimised generally rather than my setup
I'll just try asking for it: i have created a kind of dialogue tool with the experimental graphview, but since that the Node class does not inherits from an object, i can't really implements all of the "undo", "duplicate" or this similar stuff. I don't know if i have to create other classes which inherits from some object one or just give up lol
GrapView is somewhat a complete and polished api BUT hella weird!.. that said, all of what you mentioned can be handled directly in the GraphView class
fun fact: Unity staff seem to despise this api 😄
look up for these
this.deleteSelection += DeleteSelectedVNodes;
this.serializeGraphElements += VNodeCaches;
this.unserializeAndPaste += PasteVNodes;
this.canPasteSerializedData += AllowCopy;
Serialization, Undo, Redo, copy, paste all common editor stuffs are handled internally by GraphView class
easy mode with this api!
(they are undocumented like most GraphView apis, look at ShaderGraph/VFXgraph source to learn them)
had a phantom space in a selector name - took me ages wondering why it wasn't working
Any suggestions on how to change the scroll speed?ScrollView.verticalPageSize doesn't seem to work I am using unity 2021.3.18
add this --unity-metrics-single_line-height: 500px; or whatever pixel value. If it's not working, you add it to your parent stysheet instead.
known issue, they fixed the verticalPageSize in later versions
I have a single general style sheet for the whole project because I am not focusing on its visuals. I added it to the :root but it doesn't seem to work
just do it as told...
it's a known issue.. see here https://forum.unity.com/threads/listview-mousewheel-scrolling-speed.1167404/
should be fixed in 2022 btw
I had to do it too to my current project
it's not... some x versions still broken
the magic of Unity!
Still doesn't work even with the suggestions from the post🙁
Guess I'll just drop the scrolling and have pages that swap with a button click
One of the suggested workarounds works but it scrolls out of bounds and I need to fix that too. Which is an overkill for just a list at this point
Thanks a lot! I'll try reading all of the classes methods one by one then.
Is there anything else i should be aware of? I think it's quite difficult to look for something that is even undocumented lol (as a personal project, i also want to write this stuff down)
just look at ShaderGraph/VFXGraph source code, should be easy to learn all those undocumented apis
those two use graphView api
ok, many thanks, you literally saved my project
I'm not saving anything just yet 😅, unless you're successfully implementing it to your project 😄
right, i should correct with "you saved my mental state" because i'm reading documentation without updating the project since one week, at lease i have something i can work on 🙂
goodluck..
so you have like main-menu class that has main menu display: flex and everything else explicitly display: none?
no
one sec
cause my ui root has this:
public void SetUIState(UIState newUiState)
{
if (uiState == newUiState)
{
return;
}
HUD.Root.style.display = DisplayStyle.None;
MainMenu.Root.style.display = DisplayStyle.None;
switch (newUiState)
{
case UIState.HUD:
HUD.Root.style.display = DisplayStyle.Flex;
break;
case UIState.MainMenu:
MainMenu.Root.style.display = DisplayStyle.Flex;
break;
}
this.uiState = newUiState;
}
.mvvmtk-root, .mvvmtk-root-view-embedded {
flex-grow: 1;
}
.mvvmtk-root-view-base {
height: 100%;
width: 100%;
position: absolute;
}
.mvvmtk-enabled {
display: flex;
}
.mvvmtk-disabled {
display: none;
}
here's how I do it
so I just dynamically add mvvmtk-enabled
or disabled
and remove accordingly
this lets me be able to create styles for both
enabled and disabled
why do you want styles for both?
is there a way to add custom attributes to any element in uxml?
because there is no way to create style for non-existing class
no
attributes must be defined in associated factory
what I just started to wonder though is whether there's a way to define factories for built in elements
🤔
there is actually a property bag on visual element, but it's private
what?
is it stored on element?
if it is, holy shit
private List<KeyValuePair<PropertyName, object>> m_PropertyBag;
my bad, GetProperty/SetProperty are internal, not private
on VisualElement
I know, but I just don't see anything that exposes m_PropertyBag with internal access
SetProperty is internal and calls SetPropertyInternal which accesses it
oh
ah, I see
nah, this is exposing it in not very nice fashion
BUT
this is what I have been looking for
a way to figure whether element is created from UXML
created via code will not have one
I just want all the unused attributes to get dumped in there
you could check if it does it
it does not, there's no way to tell what attributes were used anyway
why not?
just foreach list
I don't see a way to get a list of possible attributes
by style here, you mean IStyle?
no, I mean stylesheet style
namings are confusing 😅
oh, I thought you mentioned that we can't intantiate an interface ||to answer that, we can with COM hacks)||
oh well
now with managed ptr magic
with ability to know what elements are created from uxml
I can say that collection binding is possible
doable
and is very efficient
aside from that
I can also implement binding to fields
(without value changed notifications though)
Anyone have a simple example of how to actually use these transitions and how they work?
you define what properties to animate and animation parameters (delay, duration)
when element changes those values (let's say changes it's classes)
they animate according to animation styles
so if you define .unity-button:hover selector for style, add animation values to it - when you hover over built in buttons it will animate
to clearly see it define that style with some bright red background color
I'm rendering a panel to a render texture, but it seems to be one frame behind compared to my camera update. Has anyone experienced this?
It's very easy to notice because my visual elements move based off the main camera's position
any one know why this happens: dont know how to fix it
it should expand its parent but it doesn't
the setup is:
VisualElement¬
Label
both have grow 1 and are set to auto for size
the text i tested was Test<br>Test<br>Test<br>Test
Labels by default will auto stretch it's own container
are you sure you're not using flex-item stretch on your parent?
this is my parent settings
can you try reproduce with the same setup i typed to see if it happens for you
i wonder if its the <br> thats causing a miscalculation ?
man, I despise UIBuilder, it's the clunkiest UIUX I've ever used in my entire life.. I will never use that until they fix it, sorry 
I won't open that shitty thing
even if you type it out its going to result in the same thing
nope, they're working fine via uss/uxml as long as you're not doing what I said above
whether i have stretch on or off its the same for me though
can you show me the uxml
ill try replicate it
to what i have
tbh the uxml is way harder to debug than the builder
it seems to be the actual label element thats not expanding
not the parent
thats all default so that must be a bug
if i turn off overflow it will cut the font out
i want it to expand based on the text
for the label its already 0
To test it out, create empty parent. don't set the styles (flexes most importantly), then add Label to it
For container
by default it should expand as you wanted to
Or do you want something else to expand?
i want the label and the parent to expand
based on the ever increasing amount of text in the label
It's default
huh ?
its dynamic text so i want the label to grow when i add text
one more time.. (they're expanding, by default, it's just you must fulfill certain criterias)
aigh, just woke up, making coffee now
ive literally changed the grow like you said nothing is fixing it
ive tried all combinations
Show uxml
aight, just googled, see this, exactly what I said https://forum.unity.com/threads/uibuilder-how-to-make-label-width-autosized-to-text-width.756779/
For whole hierarchy
the uxml is kinda massive
the auto expanding/growing is default bahavior in Labels, what makes it not behave as it's intended to, usually flexes
on your parent
the parent is also default so that should grow aswell no ?
it is both auto except with is 100%
it seems removing the parent fixes it
no idea why though
the parent was the red border but ive just put the red border on the actual label itself instead
sure but its still a child of another element
just a different one and now it works ¯_(ツ)_/¯
You had grow
i turned that off i said this i tried many combinations
That's why you should always paste relevant uxml
the uxml is ugly its all inlined
everything else is just guesswork
this isnt easier to debug imo lol
It is 100 times better then blind guess
can you see whats wrong here then because i tried adding a parent again to test it:
https://hatebin.com/fnlizmafgj
i turned grow off
for the error box yeah
Then it's not enough
i saved it as a template
i can add the parent panel aswell if you want
for the main menu
I need full one to see where you added grow or height 😅
grow is on the panel element
i think
oh no its off even on that too
the first element Screen has grow = 1
i use that so i can center the menu
setting screen grow = 0 does nothing however
Or height...
Sir
Element can only expand to it's parent size
So figure it out on your own
Yoy have debugger
Highlights
jsut hover mouse over hierarchy and fi d bottlenck
ive been doing that before i asked for help
And if parent already at max size it won't
but how does it have a max size
ive not set a max size for height its auto
so should it not keep growing
as i add more content
which element you referring to ?
All of them
panel or screen ?
none of them have max heights
screen has 100% height but im not any where near the bottom of the screen yet
Then go hover mouse over each
And find element
Which has limited size
Topmost element
This is likely where problem is
well its getting cut off by the bottom of "#panel" but that has an auto height because its suppose to expand based on its children
If it gets cut off at whatever you call panel
Then you don't need to look further
It's already limited by that point
okay so panel is the issue
but why doesnt panel expand ? it does when i add other elements but not when i add more text to a label
(don't use panel for names, this is extremely confusing)
ok call it main menu then
Idk, you never provided uxml
You could paste just that element
simple logic is like this, 600 x 400 pixels parent (this applies to ancestors too), then that 600 x 400 pixel will be your child 100%
Unless padding...
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
but again ive not set a parent to have a fixed width/height
other than the very most parent which is 100% to camera
You have grow
have you checked the ancestors too?
Bruh
grow on which element ?
Pa el
then that, yeah
Unset it
then its 1 again
What
Why is it 1 by default lol
ask unity
VEs default is on 1 when you import it to ui builder
ok now its set to 1
It imports inlined
yes the default by unity is 1
It's not -_-
do you want me to record a gif?
You didn't unset it
why would be setting it theres no class assigned to it
and unsetting it sets it to 0 which brings me back to this image:
its already unset in my uxml
when you said i had grow on which i dont
But that's a start
which element do you refer to
if i remove all then it will break the panel size
I really feel like you'd be having a much nicer time with UIToolkit if you weren't inlining so many styles, you should aim to only inline things in rare cases
well i inline then export to class using the button once im happy with the layout
its what unity's pdf said to do lol
Yeah, that's fine, I would just unset things before starting work unless you want them
half of it doesn't really make a lot of sense to me
Then unset it
if i add an element the panel expands but if i add text it doesn't
If it didn't what you want
unset what specifically ive got a lot of things set
you keep them and then it adds up
is the element set to grow?
Messing your final layout
no
grow is 0 on all atm
the issue the panel needs to expand down when i add text but it refuses
adding a different element it will happily expand down
but not for text
unless unity doesn't recalculate label correctly when text is added i dunno
bruh, I didn't realize you wert adding new line text
its a fixed size
I mean errors
huh ?
Label
#🧰┃ui-toolkit message this is the text
something to do with label first
To make sure it expands properly
I think you disabled overflow expansion
Show uxml for label
component label?
<ui:Label tabindex="-1" text="<u>Component</u>" display-tooltip-when-elided="true" name="component-label" style="-unity-font-style: bold; font-size: 20px; margin-left: 0; margin-right: 0; margin-top: 10px; margin-bottom: 0; padding-left: 0; padding-right: 0; padding-top: 0; padding-bottom: 0; width: 50%; -unity-text-align: upper-center;" />
What
you on about the one with the component label or the error label
I don't get what is your problem now, I thought this convo about error labels
<ui:Label tabindex="-1" text="Label<br>Test<br>Test<br>Test" display-tooltip-when-elided="true" name="error-output" style="color: rgb(149, 41, 41); font-size: 16px; width: 100%; -unity-font-style: bold; -unity-text-align: middle-left; margin-left: 0; margin-right: 0; margin-top: 10px; margin-bottom: 0; padding-left: 0; padding-right: 0; padding-top: 0; padding-bottom: 0; flex-grow: 0;" />
i thought you meant the component label at the top lol
you told me to unset everything
Since you use new line
so what should overflow be set to
Check overflow option
does label expand though?
what is all that space above your element coming from
those are unrelated elements ive turned off atm
So now it's up to panel and error container
Check aling, justify styles
They are usually relevant for layout too
https://hastebin.com/share/egodiyiham.xml
I copied this and I get this
yeh i removed siblings that are not related to the heirarchy to isolate it
can a sibling effect the layout of its siblings? cant image how
theres no overlapping thats for sure
i know its related to those 2 but i dont know why
You should try to reduce the times you're setting the size and just let the layout handle it
other than width im not setting size of height
Just experiment and learn how they affect layout
because it needs to auto expand
why are you setting things to width 50% or 100%
because i was told % is better than pixels
when you can just use align-items: stretch; or something else
And you most definetely need to use less useless inlines
well i tried that too i was told to experiment with things to see what happens
then nothing was fixing the problem then i get attacked for experimenting with things lol
definetely not for experimenting
you just said it right there though
Sounds like encouraging for experimenting, no? 😅
I doubt there's good enough explanation on all styles
So just playing with them is best option to figure them
the only fix is setting a height but thats no good because it needs to grow auto as i add text
auto should resize based on its children no?
What if you remove all align styles
well then i lose the 100% width from stretch
Ang instead make error cont absolute pos, 0 bottom
Does my small version work for you? https://hastebin.com/share/yiyafibiya.xml
yes
you are missing a container though
that goes around label and output
oh wait scratch that
i meant around the output not the first label
What does that container do? Because adding an element there will change nothing
so its :
Container¬
Error title - will center this font
Errors - list of errors left aligned
container creates the red border
Can you copy your whole thing again? I couldn't use the last one because it had invalid characters in it
(< instead of <, and I ain't about to go fixing that)
use uxml 😅
it was the uxml
do you want me to include all the siblings that add the empty space?
But you wrote text via ui builder
It's best to use both
UIBuilder parses things correctly in newer versions than whatever you're using, it has been unreliable in the past
im on unity 2022.2.20
so i dunno
so do you want me to include its sibling elements in the uxml
that will make the uxml horrible to read however
newest is best (thank god I never have to use the full context menu ever again)
I don't care what it looks like, I just want to fix your issue
Whoah
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
it probably wont compile
i stripped it down earlier to the isolated problem
It's got to do with one of your elements taking up 35% of the space
if you remove that the problem goes away
the radial one?
item_container
there are edge cases where %s aren't better than pixels
wait why would a sibling be effecting how the error container expands based on its children its kinda weird to me
shouldnt it just push everything down equally
item container does seem to be the problem i dont fully understand why though
such as?
if it's related to aspect ratios, tons
you can see how % can f'd up your layout from perfect-square aspect ratio, to wide-square aspect ratio.. just a tiny example
I think the way % works is that it will calculate the total height of the parent element excluding the % elements
then it will set the height of that element to the % of that height
oh so it becomes an infinite loop of resizing
No, what you get is: the parent height is set to the height it would be if item_container's height was 0
then you get item_container set to 35% of that height
and it pushes the label off the bottom because it doesn't fit
Not as a part of a flex layout
unless you know there's already space allocated for it
ok i see, thanks for explaining i would've been there all day not thinking the sibling was some how involved
the docs emphasised heavily that layouts were depending on parents and children but didnt mention siblings can cause issues too
for sizes, but not for everything
padding/margin seem to be using whole screen size
when set to %
why would it do that
padding/margin uses their own space yeah
ill just use pixels and make settings use same pixel size i guess
scaling makes everything too small in editor
🤷♂️
definitely not a production solution
well i cant use % so what else can i use lol
I'm not using % in most of my projects, I've my own aspectratio helper..
pixels all the way!
wdym you can't use %
what did you use it for?