#🧰┃ui-toolkit
1 messages · Page 6 of 1
how can I make button change color on hover?
color: rgb(238, 238, 238);
}```
cool, i thought i can do this only using ui builder
so i usually define my elements with UXML, creating custom visual elements is great too. all unity examples create their elements in code (at least the castle crasher example) and use them for updating values. as i have a uxml i would need to query it to get something like a label. but it turns out that i can't query at the constructor stage of a custom VE. so now i have a Init method which queries it. is there any better solution?
I've been wondering for a bit, are there ways to build graphs (such as line charts) through UI Toolkit? Wondering if there are assets, or if there are ways I can draw out lines and build my own graphs. Such as HTML Canvas works in web dev
I'm using UI Toolkit for my data driven game (since it works well in reducing draw calls and improves performance drastically), but I also want to have some line graphs for like market data and things.
Doing some further research I found https://docs.unity3d.com/Packages/com.unity.graphtools.foundation@0.11/manual/index.html
As well as the possibility of using the UI Toolkit vector API to draw things... wondering if anyone has experience with either of these
hello, any news about this? https://forum.unity.com/threads/set-picking-mode-to-ignore-by-default.1259640/ Is there a way to set picking mode: false to all elements?
there's very little need for that feature tbh
I set it only for invisible visual elements at root
This video is an hour long epic into how to create behaviour trees using ui builder, graph view, and scriptable objects. UI Builder accelerates editor tool development by visual drag and drop editing. Scriptable objects are used for serialisation, and graph view is the same node graph backing used by shader graph.
Project files available here!
...
check this out
I did briefly see that. Wasn't sure if it was valid for my use case but I'll check it out more in depth for sure. Thanks!
Oh actually, graphview is unity editor. That means it's only useable in editor and not during runtime right?
yes
custom controls are usually done through constructor
How do I disable the default inputs from UI?
Like the arrow keys, space bar to select, etc.
I don't want certain buttons to be interactable through the default inputs.
I think this problem in the forum is still not proper solved by unity yet, still hard to use query find the popuped field. I had to make custom control instead
It seems still a problem
you make elements unfocusable
ooor
you could just use your own input asset
for event system
Can I do something like this in Code element.style.bordertWidthWithout the need to this for every side this.style.borderLeftWidth
is there way to create a custom label which consists of two labels? Would rather prefer that than manually doing it every time by putting labels insides labels
is there a way to unlock these children?
like this?
yeah but i'd like a custom element that does it
so i'd have 2 fields to add text to, rather than manually making two labels in a container
you need to make your own, this is just visual element with two relative labels in row
Hello, is it possible to use Localization together with the UI Toolkit without having to use code?
but it works, I also have a script that scales it accordingly with the text
there is some weird uss hover class on the dropdown that changes the color back to default, can anyone tell me how is it called so I can override it?
so i got it working with a constructor, but not sure how to call the event of an integer, doesn't seem to work
no
you have to do it for each side sadly
how do i make a variable update when it's changed?
tons of ways
starting from updating it every frame in Update ending with event based binding
I have a label parent with a label child, I need to have the variable for the parent, update to the child
` public new class UxmlTraits : Label.UxmlTraits
{
UxmlIntAttributeDescription myInt = new UxmlIntAttributeDescription { name = "my-int", defaultValue = 0 };
public override void Init(VisualElement ve, IUxmlAttributes bag, CreationContext cc)
{
base.Init(ve, bag, cc);
var ate = ve as ResourceElement;
ate.myInt = myInt.GetValueFromBag(bag, cc);
ate.myInt.RegisterCallback<ChangeEvent<int>>(OnIntChangedEvent);
}
}`
this isnt working
been working on this for days, if anyone can help i'd appreciate it
this is only meant to apply value after instantiation of uxml file
you mustn't do any callback registration here
what if i create a constructor?
also change event only sent on input fields elements
when user writes something into it for example
take a look at UITK manual
it's really well written
i also just need it when the label changes, I want my other label to change too
i've been reading.. honestly I'm coming from python and kivy, and C# and unity has been driving me insane, very little clarity or examples
I would assume making custom elements would be extremely easy, but it seems to be very unnecessarily difficult or maybe not even possible
it is easy
but you barely know how UITK works
thus making tons of wrong assumptions
`using UnityEngine;
using UnityEngine.UIElements;
public class ResourceElement : Label
{
public int myInt
{
get; set;
}
// Factory class, required to expose this custom control to UXML
public new class UxmlFactory : UxmlFactory<ResourceElement, UxmlTraits>{}
// Traits class
public new class UxmlTraits : Label.UxmlTraits
{
UxmlIntAttributeDescription myInt = new UxmlIntAttributeDescription { name = "my-int", defaultValue = 0 };
public override void Init(VisualElement ve, IUxmlAttributes bag, CreationContext cc)
{
base.Init(ve, bag, cc);
var ate = ve as ResourceElement;
ate.myInt = myInt.GetValueFromBag(bag, cc);
}
}
public ResourceElement()
{
Label testing = new Label();
testing.text = myInt.ToString();
testing.style.fontSize = 100;
Add(testing);
}
}`
this is what I got so far, I would assume that myInt would always get the value i put in the input and that the label inside of it would just pull it, none of that is working
it seems
SerializedProperty events = serializedObject.FindProperty("events");
EditorGUILayout.PropertyField(events, true);
display an empty event field but I cannot add any events to it. Any workaround for this?
I think I got what I did wrong. I assuming the traits class is if I'll use Uxml, when reality I'm just creating a class that will build itself with labels and then I can just control the variables from within it
can I change the dropdown hover color?
in case someone missed it: https://resources.unity.com/games/user-interface-design-and-implementation-in-unity
should be added to the sticky. i haven't found it there
I looked at that sample and tbh... it felt like garbo 😅
not book, just sample that is featured on preview
more like learn bad
i'm trying to have an enum in my custom VE to set a class. (small, medium, bigButton) ```[Serializable]
public enum ButtonSize
{
Small,
Medium,
Big
}
public class HotbarButtonElement : VisualElement
{
public ButtonSize buttonSize { get; set; }
public HotbarButtonElement()
{
ClearClassList();
switch (buttonSize)
{
case ButtonSize.Small:
AddToClassList("smallButton");
break;
case ButtonSize.Medium:
AddToClassList("mediumButton");
break;
case ButtonSize.Big:
AddToClassList("bigButton");
break;
}
}
public new class UxmlFactory : UxmlFactory<HotbarButtonElement, UxmlTraits> { }
public new class UxmlTraits : VisualElement.UxmlTraits
{
UxmlEnumAttributeDescription<ButtonSize> buttonSize = new() { name = "buttonSize", defaultValue = ButtonSize.Small };
public override void Init(VisualElement ve, IUxmlAttributes bag, CreationContext cc)
{
base.Init(ve, bag, cc);
var ate = (HotbarButtonElement) ve;
ate.buttonSize = buttonSize.GetValueFromBag(bag, cc);
}
}
}``` .smallButton was set once but it doesn't change. i'm missing something. an event for the change maybe?
it's not even working in runtime. that puzzles me a bit. i set it to medium, yet .smallButton is still the class
oh man, tripped me up again. the uxml layout isn't loaded when the constructor is called. @gusty estuary are you loading uxml files in your custom VEs or do you all create them by code?
no, I don't use uxml in custom controls
when you make custom controls you might as well just build them through code
it's pretty much equal
in result
while being faster
it seems unsupported?
what is?
uxml in custom VE
Well, no one stopping you from doin that
nobody doing that should have been a hint
i have my uxml layouts in addressables so, hm.
and loading from addressables doesn't play nice with custom VEs
just don't
well, i thought we are over hardcoded layouts ^^
in this case why not just use uxml instances?
without custom control
I barely use custom controls
usually only in case when it's very specific
and not comfortable to recreate with uxml
usually paired with my data binding, most of stuff is really simple to implement without custom stuff
i only use them when i need to save a bunch of custom data. like for hotbar buttons, bound spell id, key binding (for the label), some meta data
where would you save custom data if not in a custom VE?
am i missing something?
i would just add some xml attributes but i haven't found a way to do that without setting up the UxmlTraits
ugh, I think you misunderstand custom controls
they are meant to be used to implement custom stuff
for example
radial progress bar
or int field with plus and minus buttons
for your project specific
you use classes
of styles
after hierarchy instantiated
you can just query everything of your specific style
and do stuff to it
for example: attach sound for mouseover and click
are you going by the code i posted? because i've removed everything that didn't have to do with the problem.
well yeah, I was referring to it. YOu can't do that and you shouldn't do t hat
Does anyone have a simple guide or anything that can tell me how to create a Listview within UI builder? Everything I see uses gameObjects, but my whole UI is built within UI Builder. I shouls also mention this is for a runtime UI, where the list elements have to be removed and added.
i tried moving most of the data away. but when dragging & dropping some spell on a hotbar i need some meta data which has to be in the xml tag
you can use style classes all you want
for any random tag
they are parsed then as list of strings
yeah true, but even if it's possible i don't see the value of it compared to a strongly typed field
but i'll keep it in mind. could prove useful
what's the use case anyway?
https://docs.unity3d.com/Manual/UIE-HowTo-CreateRuntimeUI.html should get you started. important part is .makeItem method and itemsSource
oh just a skill bar. and as i'm pretty much new to UItoolkit i'm trying different things to improve the workflow
I mean, what exactly is the need?
uhm, i'm confused. should i explain what the skill bar is capable of?
I assume it's WoW like?
pretty much
so dragging & dropping from 1 button to the next and from different panels (like a spellbook)
I haven't done drag and drop yet
but I don't think it's going to be way too complex
Roger, thank you.
This looks similar to what you're looking for: https://docs.unity3d.com/Manual/UIE-create-drag-and-drop-ui.html
thanks, i'm already on that page. how to do that wasn't my question 🙂
anyone else has the problem that UIToolkit debugger can't expand an element? (unity 2022.2.7f1)
usually a restart helped but that hasn't worked either
Jesus, i feel like this is overly complicated for no reason lol, I'm finding the documentation very hard to read.
it is. you can ignore most of the stuff
Thank you for the docs though. I think I'm just gonna cook up my own solution or design my game to not have to use ListView.
a list is defined by the data source (itemsSource) - an item is defined by makeItem. with this alone a list can get filled
and lastly, bindItem is where you apply your data to the element
some code where i use a list: ```var assets = await AddressablesHelper.LoadAssets<VisualTreeAsset>(keys);
var materialContainer = assets[KEY_MATERIALCONTAINER].CloneTreeSingle(_rootVE, visibleOnInstantiate);
var listView = materialContainer.Q<ListView>("materialContainer");
listView.makeItem = () =>
{
//Debug.Log("make new item");
var newListEntry = assets[KEY_MATERIALELEMENT].Instantiate();
return newListEntry;
};
listView.bindItem = (item, index) =>
{
//Debug.Log($"iterating over item {index}");
var data = AllMaterials[index];
item.Q("materialIcon").style.backgroundImage = new StyleBackground(materialAtlas.GetSprite(data.icon));
item.Q<Label>("materialAmount").text = data.amount.ToString();
};
_listView = listView;
_listView.itemsSource = AllMaterials;```
after you sift through the fluff i think it's not too bad
idk, I'm gonna screenshot your what you have. But I can't think.. (My roomates dog won't stop barking and its driving me nuts.)
Ok he finally decided to be responsible for his pet.
So
If I ever get a hold on this concept with any certainty, I'm going to make a youtube video on it.
Cause my brain is not braining
uitoolkit has a pretty steep learning curve. everything's decoupled so it's hard to know what you need to implement. unityUI is much more straight forward in that regard
Well that does make me feel a bit better lol. But I definately feel like it should be easier. Like.. if I could just supply the root Visual element and use that as a template for my all the listview items, and change what I need to change via script, I feel like that would be easier
you can supply VisualTreeAsset
uxml file
yeah, which can be instantiated. i do exactly that, i just load the VisualTreeAsset from addressables
It NEEDs to be seperate uxml?
for prototyping it's easier to just have a public VisualTreeAsset itemTemplate;
yes
just a uxml definition how your item looks like
man, my uitoolkit debugger is broken. 😦
i can't expand anything in runtime
Ima assume I treat the seperate UXML template as its own thing and not use classes
?
or can I reused the classes from my original uxml file in my template?
there is a section about template instantiation in manual
if it makes sense to you, do it
Just gotta find where the USS file is 😕
wish me luck that deleting library fixes the debugger problem 🤞
Sending luck
In case it helps, selecting the panel (top left of debugger window) can kick it back into action
ok, i'll keep that in mind when i have it again. as i said, the last time a unity restart helped. pretty much everything else was working (picking elements, hovering and seeing the broders, etc...), just not expanding
you are a lifesaver. so when i have the debugger undocked on my 2nd screen it doesn't work. but when i dock it somewhere on my main screen/main unity window it works. (re-importing didn't do anything)
So, now that I have the UXML setup with my ListView Item, what next?
write the code similar to what i posted above. reference the listview, the item template and have the data ready you want to bind
and makeItem is my visual tree asset?
you'd instantiate your visual tree asset there
How do I get reference to my uxml?
public VisualTreeAsset itemTemplate; in your MonoBehaviour
then drag & drop your uxml file
Whoops i set it to private no wonder
And suppose I wanted to bind a List of KeyValuePair<string, List<Messages>> how would I go about doing that?
you can't bind a dictionary, only an array/list
at least i don't think Dictionary implements IList.
just bind the List<Messages>
rage. anger. displeasure
ooooone second. lol
Gotta change my message calss.
class
so I've confused myself, what is 'item'
OH nvm I think i get it
no no i dont
this is a single item 🙂
Gonna just paste my code
maybe im on the right track, idk
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.
welp, I didn't know the title would show
query the tag/element you want from messageTemplate. the above example would by a Label
item.Q<Label>("nameOfLabel").text = data.charName;
messageListView.bindItem = (item, index) =>
{
var data = allMessages[index];
item.Q<Label>("Message_Contact_Name").text = data._contactName;
item.Q<Label>("Message_Contact_Content").text = data._messageContent;
};```
so like this?
yeah
can a ListView have that kind of layout? if so, how? with some deep css selectors?
I imagine that its just about the style the container no?
Looks like flex is set to row, and the elements themselves have a specific size.
Then them maybe the color is changed based on index
On and wrap would have to be on aswell
right, i just don't know where i would set this. if i set it on the listview it doesn't apply to the underlying scrollview
Well Idk anything about a scroll view. But if that yellow box is a fixed size then all you really have to do is make sure the style for the box is set correctly
Oh, but come to think of it, I'm not sure how that would work once the box gets full.
Unless, you could vertically scroll within the yellow box
Then in that case, im outta my league
Cannot convert from template container to visual tree asset? what
where do you get the error? in instantiate?
well its started as an object null ref
I have a static method within my Messege called Instaniate that is supposed to do all the binding and what not for the list view of messages
buuut. The I can't referene the VisualTreeAsset in a static method without making it static, which I also can't do because then I can't drag and drop it in the editor.
So I'm confused as to how I can use the template within the method without making the method not static, cause it doens't really make sense for it not to be static.
don't make it static
rather make the class (UserInterfaceController) a singleton if you need to access it from somewhere else
This is starting to piss me off
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.
Downright confused beyond belief
Ui is proving harder than my actual game logic.
no wonder, your code is a mess. drop all these statics. i don't know why you have them in the first place
Yeaah, i don't know how I managed to have so many actually
if you need singleton access, use this pattern instead ```public class SingletonExample : MonoBehaviour
{
public static SingletonExample Instance;
public List<int> list;
public void Awake()
{
Instance = this;
list = new ...
}
}
// get via
SingletonExample.Instance.list```
it's not pretty but better than messy statics all over the place ^^
Im not to familiar with the concept of singletons so give me a min to educate myself while I clean up my code
very basic concept. you define a class that only exists once and through the static Instance you can access it from anywhere. same as your static usage but instead it's one static that encapsulates all your other fields.
IGotcha, okay interesting.
But I don't think that would help would it? I mean it would make my code look a bit nicer, but if the stuff I have with the static modifier are things that logically would need them I think
right?
they don't need them and especially not something like private static ListView messageListView; as you experienced, you can't even reference the ListView then
Maybe I don't understand static than, cause I only have and only need the one listview no? I don't need instances of the listview. It only exists once and I want to directly modify that one ListView?
And the thing I can't access is the messageTemplate, which isn't static
yes, you don't understand static 🙂 i won't explain it here. anyway, first thing you have to do is move public VisualTreeAsset messageTemplate; to UserInterfaceController.
done
then implement the singleton pattern and you can change var newEntry = messageTemplate.Instantiate(); to var newEntry = UserInterfaceController.Instance.messageTemplate.Instantiate();
sidenote: i'd design this very differently. i can just give you some guidance how to get this done quickly
ill take whatever I can get atp
Somehow a list has taken more effort than the hours of 3d modeling I did today
well add the singleton public static UserInterfaceController Instance; to your UserInterfaceController class
done
copy paste the Awake from above (minus the list line)
done
still any errors? you should do the same thing for any other static. move them to your main controller and access them just like the messageTemplate. I see public static VisualElement notifacationContainer; for example
some can stay. but anything that you want to reference in unity has to go to the controller
Well there are no errors, but my list is empty.
No compile or runtime errors whatsoever
wait whoops
well. Noticing a gaping probelm with everything
Fixed
Guess its time to play the Debug.Log game.
is there a way i can add a ui that the mouse hovers over using this map art asset? is there a tutorial on using onmouserover😭 sorry i am a beginner on this
Well. I think I'm giving up on the ListView
I can't take it anymore
Dog wont stop barking. No errors, the list has items in it, the template has a super bright background color that I can't miss, its sized correclty, but makeitem and bind item lines aren't running.
I'm deleting everything and just designing my UI without it.
I shouldn't need to learn quantum physics and have a PhD in UI to make a simple list.
Raging so hard rn
Hours wasted.
@pale tapir Sometimes it's good to have a break once in awhile and when you come back to the problem with a fresh mind it may help. I do got to say that ui toolkit is neat but very lacking in a lot of basics that shouldn't require paragraphs of manual code to make its features functional. It's requiring loads of workarounds to automate and simplify it and that's frustrating because there are free alternatives, but unity wants a cut. The Unity documentation is also worse than C#'s documentation, lol.
my bug report is doing great 😬
iconInst.style.backgroundImage = Resources.Load<Sprite>("Assets/UI/Textures/Images/icons_0");
For some reason this doesnt take sprites, only 2D textures, any way to make this work?>
new StyleBackground(yourSprite);
how is it possible that i set the style width/height of a VisualElement but the worldBound width/height stays at 0/0. quite annoying because i use overlap for drag&dropping
it's a Sprite class Resources.Load<Sprite>("Assets/UI/Textures/Images/icons_0") in your case
it no longer generates an error, but it doesn't do anything unfortunately, doesn't display the image
have you checked if the sprite loads correctly?
and you should put your sprite in a SpriteAtlas.
now i see it. you are loading from the resources folder. this can't work
atlas.GetSprite("spriteName") is much more convenient
what? why would you ...
way more control over them, now I can put them throughout my text and I can alter their color to whatever I want
they work great for buttons to, because the background image for the button is always stretched and you can't adjust it, with a text, you can
what does that have to do with sprites as text assets?
because you create a sprite into a text asset
<sprite name="rock"> so lets say I put that in my text, it's an image will be always inside it
oh, you are not talking about loading text assets from the resources folder, are you?
nah, no loading I just attach it to my settings
(assume bottom width says height)
assuming this is what I have....this would start the width/height(assume the 2nd width says height) at like 0% and ease it into like 100% then back to like 90% over 1s?
or does it just start it at whatever it was previously...(assume its disabled to start...meaning 0%, then ease to 100% and back to 90%?!?!)
or how do I know the percents it eases it to?
Does UIToolkit support splitscreen?
You can have two times the same UIDocument and each take 50% of the screen no?
Hmm the idea would be choosing the camera that renders it, so I dont have to set the size when its 1 player, again when another joins etc etc, but I guess it could work
I think if you set the grow or expand (don't remember which one) to 1 if you have only one element it's going to take 100% and if you have two or more it's going to share the space. Your elements need to have the same parent
I will do some more testing then. Since Im using the new input system
UI is not rendered by camera
you choose render target in panel settings if you want to go that route
@lean barn is it expected for the UIToolkitAutoReferencesPostprocessor that when it creates the file I should be just copying the code and pasting it into another file that I want?
as it seems to "delete" anything I put inside the "ChestOpeningAutoReferences" file (comments, code etc)
Yup, you should create another script to hold your logic, the AutoReferences files are deleted and recreated every time you make a modification
I'm curious how did you find it, because it don't think a lot of peoples are using my weird scripts 😅
1 vote and 0 comments so far on Reddit
actually finding the script itself wasn't super easy tho
its not actually linked here 😭
still have to try out the world UI stuff...but probably wont use it in this game
script works great...only annoying thing is the 4s reload after I save
Tbh, script saves me much more than 4s tho 🙂
Yeah the Unity script reloading is one of the worst thing
Glad to hear that
I also think I could check if the numbers and names of auto referenced elements changed or not to skip the file update
when using sprite mode multiple as background sprite I can only get the first element, it doesn't matter the one I choose at UI Builder, any help?
that would probably help quite a bit 🙂
Does anyone has this error using UI Toolkit + New InputSystem + EventSystem?
working fine on my end. have you converted the input system for the EventSystem?
with manipulators like MouseManipulator. I'm setting a target which is a custom VisualElement. When the MouseOver event hits, I get a VE in evt.target but I can't cast it to my custom VE class. anyone else got this to work?
huh, picking mode screwed me over that was active on some childs. that thing should really be disabled as a default :/
I don't really agree. 99% of the time I disable it for only 1 or 2 elements out of 50 in hierarchy
Window > UI Toolkit > Debugger
you can Pick Element like you can in something like Chrome dev tools
thank you!
God I needed that hahah
Probably a RTFM moment
How can I override styles from within Unity? For some reason mine aren't applying. This first one is my rule.
My sheet is appearing last in the list of stylesheets:
override unity styles?
Ah, sorry. I mean I would like my rules to override the defaults.
At the moment it seems that .port > #connector is taking precedence
Selectors from user-defined style sheets takes precedence over selectors from default Unity style sheets.
Well, mine are user-defined, but it's not applying.
I mean... I think they're user defined
you sure those stylesheets are applied?
then styles are applied
check actual style data
in bottom
and see
how are they defined
I have a feeling you inlined them
setting value in code also inlines it
top selectors are lowest priority
Yes, like I said, I did not make this elements
then most of the time you'll be out of luck
complex Unity elements are so bad with styles
I prefer to make complex stuff out of simpler if possible
I am just trying to make a port look different
what class is it?
So if user supplied sheets are always higher precedence, why is mine at the start of the list?
because you didn't read manual to the end, there are way more factors that are taken into account
and that's why some elements are just very hard to override
whole page is about style priority
Yes,
It says user provided sheets have highest precedence
Then moves into specificity to tie-break
Selector specificity
I know what specificity is
Unity determines precedence according to the following factors in this order:
- The type of style sheet: Selectors from user-defined style sheets takes precedence over selectors from default Unity style sheets.
- Selector specificity: If both selectors are in the same type of style sheet, the selector with the highest specificity takes precedence
jeez, I am so confused with these words kek
no sir
that's now what I meant
I mean
that your style
is likely Type selector
which is lower priority than Class selector
no matter whether it's user defined or not
I've included both type and class
PortView.Port_Nullable-Single- > .connectorBox {
border-bottom-left-radius: 0;
border-top-right-radius: 0;
border-top-color: white;
height: 20px;
}
oooh, got it!
This is type selector
The top-to-bottom thing wasn't true
If I use the "name" selector it overrides
It's because the ID was higher precedence
hm
highly recommend using chatgpt, it actually knows quite a bit of unity and C# and even if its not perfect solutions, it find and even teaches you syntaxes with examples far better than any documentation
jeez, no
It has limited knowledge up to 2021
UITK has changed quite a lot since then
As I said, it isn't perfect, but it can be helpful
no I completely disagree. Every time I tried to extract some code from it I saw extreme flaws which will be very harmful for those, who don't know what they are doing
I've yet to run into such issues. Obviously it's just for basic things, not creating your code from the ground up. It's a good start on the right direction and has saved me days of time finding stuff that can't be found almost anywhere online
it's a lot better than asking here and getting a response such as "that's easy" and not providing any assistance
just keep in mind that it's just a language model and it can't ever know whether code makes sense or not
last time I asked for some UITK advice, it provided me sample referencing uGUI classes 😅
since then I used it for nothing but english assistance
i've also successfully had it covert python code into c# code to have a better understanding of the language
I do nothing, but worry about knowledge you gained 🙃
is there a reason why my game view and the UI builder show completely different UI stuff?
Left is game view right is the UI Builder
length for both are probably not the same
You also have a drop-down at the top of the window, make sure you aren't using the editor style
Using the Unity Default Runtime Theme
What really bugs me is that they are both using the same class
The only difference between the red and blue elements is the width and color, which is the only thing I wanna change between the two
Oh now I think about it check your panel settings
Inside your UIDocument in the scene view
You should choose match screen size or a name like that and set the cursor to 0.5
Also use the same value size inside the UIBuilder and inside the panel settings
I found the scale mode to scale with screen size, but see nothing about a cursor
By cursor I mean slider* sorry
ah
Looking like that on my side
any idea why this renderTexture isn't rendering anything here?
Thank you this seemed to help for the most part!
Maybe the match slider need to be 0 for you, depends on your needs
1 seems to be working much better
Opacity is set to 0 somewhere?
for the background color or img tint?
🤔
I wonder if its the fact that its a particle is whats making it break
I can get a renderTexture of a sprite to work fine
You are filming the particles with a secondary camera? They are also doing that in the official UIToolkit project
So maybe you can take a look there
yes to first question...no clue what you mean by 2nd?
I couldn't find anything like that when I had looked
oh there, gotcha, I'll check it out again
but no clue why the rendertexture wouldn't work for particles
¯_(ツ)_/¯
😭
it shows other things but not my actual particles
brutal
@gusty estuary you seem to know every UI thing I ask...any idea why my particles wont render?
Do you know where?
that project has so many UI docs I'll never find it manually lol
So I know it's used for the character portraits, but I don't remember what the name was
like in the main menu or the actual game?
If you mean right here...they don't actually use UI toolkit for it :/
No it's the HUD UI with the character portrait on the bottom
I think it's when they have the power up ready or something like that
You can play the game and find them easily
hmmm, I see what you are talking about at least
of course they spawn it all in so I can't find how they do it 😡
Haha they probably are inside UI document prefabs. Maybe while the game is playing you can find the camera filming the particles
wtf kinda camera is this lol
never seen anything like it
I don't see anything unusual, you never made a urp project?
no clue what that is tbh
Just remove "ColorMask RGB" or replace it with "ColorMask RGBA", you will get the correct picture.```
🤔
gotta figure out where that ColorMask RGB is located then hopefully that fixes it
😡 from what Im seeing the asset pack I was using for particles used ColorMask RGB...and didn't provide the shaders themselves so I can't edit it to fix this
(granted I know nothing about shaders)
Time to learn how to code shaders 😅
I legit have no clue what shaders even do
It's the code that tell your GPU how to render thing on screen
is there any kind of style sheet setup to have the runtime ui look like the unity editor ui?
Particles-> Alpha Blending shader shows not$$anonymous$$ng... BUT Mobile->Particles->Alpha Blending works for some strange reason. You can see the particles with the correct shader!
any idea what this means..can you change all shaders to somehow go from mobile?
I found that the normal Particles shader has "ColorMask RGB", while the mobile one doesn't. Removing that allows you to use it with a RenderTexture. The only side effect I've seen is alpha gets slightly greyer when your RenderTexture includes the skybox, but it's so small it's worth it. Otherwise it works flawlessly.
You need to search the material used in the particles system (it's inside the render section)
When you found your material at the top you have a drop-down named shader
And you need to find the one the person is talking about
gotcha thanks...what shader do people normally pick? (ignoring the mobile thing above)
all the ones I see are on Legacy Shader/Particle
Depends on the render pipeline you are using
ah...what render pipeline do people who not know what that means normally go with 😄
When you created your project you had the choice between built-in, URP and HDRP
Which one did you choose?
Okay so you should have access inside the drop-down the mobile/particles/alpha blending
Or any alpha blending below a "particles" section
ah, so anything that says like "alpha blending" means it saves the alpha values and thus can be used with rendertextures?
I can't be sure without seeing the shader code but it's worth a try anyway 😅
is there a way to modify the default shader codes? (like Legacy Shaders/Particles/Additive)?
not even sure how I got these shaders lol
Online you can download the built-in Unity shader library yes
ah cool, thanks...turns out I just need to click Mobile->particles->additive and it fixes it ❤️
What do i need to do to have a dropdownfield show a text that is not the object that is selected?
For example i want the dropdown to display a list of Fields of a Type and the Type of the Field in Brackets:
TypeA(Vector3)
TypeB(float)
TypeC(int)
.
.
.
so I do this to fill the DropdownField.choices list:
{
var fields = new List<string>();
if (type == null) return fields;
foreach (var fieldInfo in type.GetFields())
{
fields.Add($"{fieldInfo.Name}({fieldInfo.FieldType.Name})");
}
return fields;
}```
But now when I select a choice i do actually only want to get the FieldName returned and not the Type in Brackets. Do i have to format the string again? Seems like i am missing an easy solution to this
Quick question.
When two visual elements are siblings and one is covering the other... is it possible for a click event to hit both of them?
I'm trying to build a UI that resembles operating system windows... but each window has a rootvisualelement that covers the whole screen.
So elements that are "siblings" don't get hit one after the other, only the top one gets hit.
Wondering if I can make the event path hit one after the other.
If you're wondering, the reason why each rootVisualElement covers the entire screen is because for dragging windows around, if I go too fast I fly off the window, so catching the event across the entire rootvisualelement prevents that from happening.
make picking mode = ignore on every invisible element
picking mode is what stops event propagation for clicks
but I need it for dragging
Wondering if I can only have picking mode pick when dragging, then switch it off when not
why do you need picking mode on invisible elements?
.
Is there an alternative approach to this
you don't need picking mode on invisible elements for that
I have PointerMoveEvent. Does that not matter for pickingmode?
just register click event when you start dragging
and move window to cursor until mouse up event
Yes, I do this with a PointerMoveEvent across the entire "invisible element".
The reason I do this is because I can get an event.localPosition from the PointerMoveEvent which is the only way I've gotten this to work.
If you're referring to use Input.mousePosition, that doesn't seem to work as well for me.
I don't refer to any input frameworks, allthough you might need one
but no matter what you do
picking mode stops event propagation
and you can try to develop some overcomplicated solution to toggle it
or just do it the way unity does
This seems like it's doing it through the editor and not in-game?
keep in mind though, that this example is for editor, so it'll need some rework for runtime
yeah...
but it'll give the general idea how it should be done
I do it through pointermoveevent which is how most people seem to have handled it
though now that I think about it... I may have come up with a possible solution
Talking about things helps me lol
haha yeah it seems that is how most programmers handle things. I've been working on this UI for like a week now and every so often I bang my head against the wall
I've thought about just making YT tutorials on UI Documents doing more complex stuff cuz it seems to be an area that's lacking
there's Unity manual
that is better than any YT video
I've been using it for figuring these things out but some things are buried deep or not documented as well as they could be
plus YT videos on unity are generally why I've preferred unity in general over UE5
UE5 was... a nightmare lol
I have two elements - a button #DropdownItem, and a button #Button. I want to achieve the following behavior:
- When I hover over #DropdownItem, only #DropdownItem should become grayed out.
- When I hover over #Button, both #Button and #DropdownItem should become grayed out.
Is there any way to accomplish this?
Hello, I have a health system using the UI Toolkit asset. I have an int called Health and depending on health in should change the amount the sprites of the health icon. For some reason, the initial sprite is not being changed but the last two are. Any ideas?
[SerializeField] private Sprite healthFull;
[SerializeField] private Sprite healthEmpty;
int health = 3;
List<VisualElement> healthSprites = new List<VisualElement>();
healthSprites.Add(gameMenu.rootVisualElement.Q<VisualElement>("HealthIcon1"));
healthSprites.Add(gameMenu.rootVisualElement.Q<VisualElement>("HealthIcon2"));
healthSprites.Add(gameMenu.rootVisualElement.Q<VisualElement>("HealthIcon3"));
var healthEmptyBg = new StyleBackground(healthEmpty);
var healthFullBg = new StyleBackground(healthFull);
if(healthSprites[health] != null) healthSprites[health].style.backgroundImage = healthEmptyBg;
for (int i = 0; i < health - 1; i++)
{
healthSprites[health].style.backgroundImage = healthFullBg;
}
why are you doing < health - 1 and not just < health
because the index will be out of the array. If health is 3 then i do health - 1 so all sprites should be full
healthSprites[0], healthSprites[1], healthSprites[2]
2 is < 3 not < 3 - 1
I also don't entirely understand your logic, as you are setting the last one to healthEmptyBg, which when this is corrected will be immediately overridden
you're also not using i, you're just doing healthSprites[health]
it's not
im just setting the one after my health as empty
because im gonna add a feature where the player can pick up more lives
thx for the help tho
you know when you have a ui element selected with a controller? How would I make that bigger? Currently it is at 1px and it is near impossible to see lol
doesn't seem like it's possible to override remove and add functions for elements... really unsual, basics, not possible
if you'll go over this part of manual you'll have no further questions
https://docs.unity3d.com/2022.2/Documentation/Manual/UIE-USS.html
seems like you are trying to use uitk engine not in a meant way
what is the point of a custom element if you can't override anytihng for it
constant workarounds
sir, you are not meant to have just 1 element
you create proper logic through composition of elements
you don't override anything
because underlying logic is way too complex
what are you arguing for? any other game engine allows you to alter elements and override them, unity doesn't
I donno what you're making excused for
if you need something to override - you are most likely using it wrong in UITK. that's about it
i need an function to occur when an element gets added to a elementbox, no possibility via events or overrides
you might want to take a look at scroller logic to see how it handles it
no substance you provided what exactly do you mean
Scroller does some stuff on startup, when elements are added through uxml to it
potentially that's what you want
but tbh
can't you just handle that logic when you add elements to elementbox?
none of game logic should rely on UI logic, aside from input
I'm trying to make a groupbox hide or unhide based on elements within it, should be done if element is added or removed event, but none of that is possible, literally basics for any other game engine
you are adding elements to it. You are pretty much responsible for that logic in the first place. Can't you hide/unhide them as you do it?
also, you can implement this through styles
that's the point of automation though, yeah I can manually do everything in my gui, but it's better to automate everything
the best way to do that, is via the construction and events of the class itself
if element X has class Y, and your elementbox has class Z which overrides children with class Y, this will apply
well sir, seems like you are trying to tie game logic to UI
this will strike you hard when your project will scale
it's much better to treat UI as one sided connection. YOu only send data to it, never expect anything in return
Is there any way to overwrite uitk source code? I tried doing the embedded package method but there was no source code inside the com.unity.modules.uielements folder
you don't?
You can just override it in a custom class
This if we're speaking of overriding visualelements public MyLabel : Label
No, I mean I want to modify the source code
You can do that with hdrp for example, just clone the package locally and modify to your hearts content
I believe it's part of engine, so doubt you can
Yeah, I figured. Ended up with a retarded solution, but, hey, it works :)
curious what it was
I needed to blur a uitk panel and use the resulting rendertexture as a background for an element
I split the whole thing into 2 documents, with the bottom one rendering to a texture
It worked, but there was a massive issue
I could only blur the texture in update or lateupdate
oh yeah, anything involving rednering texture is a bit clunky
can't you just use post processing?
And because uitk renders during the overlay pass, there was 1 frame pag
Post processing would not solve it because I need to render the blurred background inside the uitk element
I would need to blur the rt after the first panel has rendered but before the one on top of it starts rendering
I found the code responsible for rendering panels and thought I could use harmony to inject code before each panel was rendered
But there was one small issue
The method I needed to patch was internal, just like the class
So I couldn't pass the method signature to harmony
What I ended up doing is:
- Find the uitk assembly in the unity install and publicize it
- Create a c# runtime library that references said publicized assembly and uses InternalsVisibleTo and SkipAccessCheck to access internal/private shit
- Do the harmony patching in this library and expose an event called right before rendering each panel
- Add the library to plugins and use the event to blur the texture
It's as shrimple as that
I could theoretically also make uitk render into a camera too with this method, I can patch almost all code after all.
I'm not even sure you can render ANYTHING after uitk is done
Not with post processing at least
I don't think that's true
there's always a way to hook player at any point
you just need to figure where
but you'll need to render to texture
You mean the unity's playerloopsystem thingy?
and then use some uGUI object
yeah, just register your own player to loop
Now that I think about it, you probably won't have to do anything like the playerloop modification. You can just make ugui render after uitk by setting a high sort order.
I wouldn't want that though 😅
but maybe it fits your case
I would have to rewrite my uitk panel using ugui, so no, it does not fit my case lmfao
Not undoing 2 days of work just to fix 1 frame lag
but harmony doesn't support AOT
I'm on mono, so it's fine
we're using urp so we do this just by using a custom renderer feature to blur the result of one ui panel and composite it before rendering the second - no frame lag or reflection etc. It's a shame it's not easier but at least we're still in full control of the render stack.
hold on, render feature can affect UITK panel/
ah no probably not in the way you're thinking - as in a panel set to output to render texture
ah. I wonder how you handle screen resolution change. I assume it's trivial for one script?
yea exactly - nothing more complicated than checking screen size on update basically
Not sure if my question belongs here or somewhere else, but I was wondering if anybody knows about a tutorial or resource that can help me make an analogue/joystick control using UI Toolkit?
Hello! I'm new to this discord and I'm new to UI Toolkit as well. I'm currently running into a bug where I can't seem to change fonts at all? It doesn't recognize any of my font assets, and the font line gives me an error saying there's an invalid character in the url (tried removing all spaces along the path I set up, didn't help). My unity editor version is 2021.3.9f1, does anyone have any suggestions for what to do or where to look?
tmp fonts don't work with UITK
use built in font creator
ahhhh that makes sense, thank you so much!
wondering is it possible to change the display in code?, as i want to hide different menu's at certain times. Thought it would be Q<VisualElement>("WhateverName").display but this does not appear to be the case...
worked it out! style.display instead of just .display!
anyone know a good tutorial for IAP that work with UI Toolkit?
so far the few Ive found used components you add 😦
is there anyway to make a slider's input box larger, so the text actually displays? (it appears all greyed out, and won't let me change the size...)
Hello again! Another question but any suggestions on how to use the builder to make auto-scrolling credits? I know that often you'd just use a standard canvas and the timeline animator but I was wondering if there was anything specific to the UI builder?
this will require code
https://gamedev-resources.com/use-style-transitions-to-animate-a-menu/
Hello! I just now found this and am about to see if I can leverage what I learn from it to make a scroll using a really slow "transition" that I'll try to trigger in code
No, scroller logic relies on either input or code. trsnsition animation are totally unrelated
oh, I may be misunderstanding or miscommunicating, my apologies, but I don't need the player to have any input for this, I just want it to scroll up when a button is pressed and then fade away after the full scroll has been completed. Like film credits. Uncertain if it's possible, but I've learned a lot along the way of trying to figure it out so it's no biggy ^-^
possible, through code
background-image: resource('Assets/Resources/icons.png#icons_2');
using uss any reason it's not using the icons_2 image for the sprite?
nvm used url instead
I setup asset references through UI Builder. Way more convenient.
Hi, Im trying to do a brightness controller but i think i need a canvas with panel to do this, is posible using only ui toolkit to do it? Thanks
I figured it out with the resource I shared, combination of transition animations and code ^-^
With the current state of the UiToolkit package, how easy is to port anything from uGUI? Should I make the change? (We're still using v.2020 LTS for compatibility reasons...)
I'll need to teach this new system to my students eventually, so I'm a bit worried about..
There is zero reason to port anything, runtime is not recommended yet and support for it in 2020 is bare.
Meh! Thanks @rough scarab . I'll keep waiting, then...
my textmeshpro on canvas is very blurry in game view but not in scene view, anyone knows why?
is this the right channel for this lol
i need help, i m doing this:
brightnessSlider.RegisterValueChangedCallback(ev => SetBrightness(brightnessSlider.value));
and this is the method:
private void SetBrightness(float value)
{
Screen.brightness = value;
}
Not Work, the param value is correct but i cant set Screen.brightness (i have same problem with audiomixe to control masterVolume) i think is the type of registercallbak maybe?
So something Interesting regarding UI, in my script I am adding a class of a UI element within a function as so:
Do I need to query the Button within every function I write? that seems redundent to me. But if I try to move the GetComponent outside to the beginning of the monobehaviour script, I get errors
This would mean that if I bind the value to a scriptable object or variable, I need to call this function in the update loop? 😮
You can always cache all references
they are very slow
and must not be called in update loop
Sometimes when I enter Play Mode my UI document doesn't respond to clicks, I can't click on text fields or buttons or anything, and changing my code in any way, even just adding whitespace and having Unity recompile scripts, reload domain, etc, fixes the problem
I don't understand what's going on
Disabling Enter Play Mode Options doesn't fix it however
inspect event system when that bug happens
it might show some related info
I just noticed the Sort Order field 🤦♂️
something invisible was over your buttons? 😅
I implemented a crosshair as a UI document with a 100% width and height container with 2 rectangles, yes
I think the Rival/Unity.CharacterController OnlineFPS sample does the same
you don't need sort order here
just make root of your doc pickingMode = ignore
if it's set on ignore it won't take over click events
Currently when I register to RegisterValueChangedCallback for an object field, it gets called even when creating the inspector, is there a way to only get callbacks when the actual value in inspector is changed?
callbacks are called when value changed - thus it will be called on literally every change
no work arounds for it
Anything you could suggest as a workaround?
Although this usecase is pretty common so something should have beeen there for this kind of callbacks to only be called when the actual value is changed
I wonder why in UI Builder the default UI differs so much from what is actually visible in the game? How can I make it WYSIWYG ?
Switch from the editor theme to your runtime theme using the drop-down in the top right
any idea why it isn't set to runtime as default...or why anyone would use editor theme anyway?
Because runtime is not yet recommended, and editor scripting is
fair enough thanks!
hey how do you make the UI have post processing on it?
render it to texture and then render that texture in any way you want which supports postprocessing
Is -unity-text-outline-width: 1; not compatible with <color=green>x</color> on richtext?
outline + rich text color
This is really bad
Does anyone has any advice on how to ease my workflow with UITK? Basically I need to make a panel of buttons where only 1 can be selected.
I'd use ListView for that, but it doesn't support horizontal + vertical item population.
So far I have to rely on registering callbacks on each button which is really painful to manage, and requires tons of code to implement (and I need a lot of them!)
Maybe anyone else has worked out some good pattern on this?
you can make your own custom ListView in UITK pretty easily
ListView is just for convenience, like List<T>, pooling and all
making generic version? hmm
you can use scrollview as your base and make your own observablecollection
I already bind to observable collection
but I do it manually 🙃
yeah, I guess I need to come up with some generic solution
custom everything is where UITK shines
is there any UI Toolkit equivalent to SearchWindow (https://docs.unity3d.com/ScriptReference/Experimental.GraphView.SearchWindow.html )?
yes ToolbarSearchField
thank you! ill look into it
sry might be a stupid question but is this just the searchfield without any search implemented already?
okay then ill delay using it for now. Searchwindow is way too convenient
aight, goodluck 👍
thanks anyways!
For menu navigation, I've just been using a simple system that I made but I've been wondering if there is a more robust go-to popular UI system asset that everyone uses and that I should also consider buying and using instead. I check the asset store but I'm not sure what keywords I'm supposed to be using to search for this kinda system, most UI searches just give me visual assets. 
I developed a framework for UITK and it's free
https://github.com/bustedbunny/com.bustedbunny.mvvmtoolkit
Can anyone help me to spawn my Popupwindow correctly?
I just spawns on very wrong locations... This is a known bug.
https://issuetracker.unity3d.com/issues/popup-window-will-be-drawn-at-a-incorrect-position-when-using-popupwindow-dot-show
But how do i fix it? The provided solution with GUIUtility.ScreenToGUIPoint does not seem to work correctly either...
How to reproduce: 1. Open the attached project (case_1310730_PopupPosition) 2. Click Tools > Popup 00 3. Observe where the pop up...
Thanks!
I did it all in code 😄
help!
Idk what is wrong but my font size does not change at all
Label{ -unity-text-align: middle-center; -unity-font-style: bold; -unity-text-overflow-position: middle; text-shadow: 2px 2px 2px rgba(0.5,0.5,0.5,0.5); font-size: 40px; }
because default font is set through class selector, which has higher priority than Type selector
but I didnt specify any font size for any class in this sheet... does it mean that it would be better to give this label some class and then specify the font size using class selector instead of type?
yeah, that works
So I guess some native style was overriding it, I will remember the priority next time if something won't work, thanks
but now I would have another question. Is it possible to make font smaller if the text stops fitting into its container?
not through styles
code could do it
in c#
catDesc.obj.style.flexDirection = FlexDirection.Column;
catDesc.obj.style.overflow = Overflow.Visible;
catDesc.obj.style.whiteSpace = WhiteSpace.Normal;
catDesc.obj.style.unityOverflowClipBox = OverflowClipBox.ContentBox;
catDesc.obj.style.height = 50;
catDesc.obj.multiline = true;
pls no
don't do styles through code 😅
woooo yeah coding!
I don'tnormally do this, I've my own fluent lib for uitk
this just copy/pasted from my old stuff
Need to know how to parent/child UI Prefab into another.
_choiceContainer = Root.Q<VisualElement>(UIUtilities.GetUIClassName("loot-menu", "choice-container"));
LootChoice newChoice = Instantiate(_lootChoicePrefab, transform).Constructor(choice);
_choiceContainer.Add(_lootChoicePrefab.UIDoc.rootVisualElement);
This doesn't work properly, it adds everything as its own root instead of inside the container
So confused why this doesn’t work..
VisualElement.Add(someRoot) should parent someRoot to the target visual element no?
Someone help
hi ,
this is the first time to use canvas
when I tried to add a child to the canvas, everything I add seems to be rendered behind the canvas
I added a button to the canvas and on play mode, i wasnt able to hovor or click on it
I was only able to click on it if i move it to the far left side where the convas is not covering it.
It's as simple as
parent.Add(child)
Yes but it isn’t spawned in the container
elaborate
I'm concerned that you're adding your 'prefab' not the instance
is there anyway to group certain ui elements together, like a visual element, but i don't want it to affect the position or change anything else, i just want to be able to target it in code so i can enable and disable large amounts of ui elements easilly, is this possible?
I instantiated it, it should be the clone instance?
It spawned outside the container its supposed to be parented on
As its own root
No? The instance is returned by the Instantiate function
Ah, I see the mistake, thanks!
from googling it really seems like this isn't possible sadly
Its parented, but only the last choice is parented.
It's parented what you've told it to parent, so just check to make sure you're getting the right stuff
I am telling it to parent rootVisualElement of each clone instance's rootVisEle
foreach (LootChoiceParameters choice in choices)
{
LootChoice newChoice = Instantiate(_lootChoicePrefab, transform).Constructor(choice);
_lootChoices.Add(newChoice);
_choiceContainer.Add(newChoice.Root);
}
Hmmmmmmm
Root is just get property for UIDoc.rootVisualElement
Only the final choice is properly parented.
I'm not really sure what your setup looks like internally, but rootVisualElement seems like the wrong thing to be parenting. If you want to dynamically add stuff to UI you should be using VisualTreeAsset, not a UIDocument
a UIDocument is a dynamic structure, and is intended to only represent runtime data when it's already in the scene
it's not meant to be used like a source of a prefabbed UI doc
VisualTreeAsset is the UXML?
Yes
I see, I'll give it a go
The only reason I tried this is because I want to be able to use prefab with it, with UIDoc & MonoBehaviour attached.
It worked properly when I generated it procedurally
Is this how I use VisualTreeAsset?
// Constructor
public LootChoice(VisualTreeAsset uxml, LootChoiceParameters choice)
{
InitializeUIElements(uxml);
if (choice.Icon) _iconImage.image = choice.Icon;
_titleLabel.text = choice.Title;
_descriptionLabel.text = choice.Description;
_selectAction = choice.SelectAction;
}
private void InitializeUIElements(VisualTreeAsset uxml)
{
if (!_lootMenuManager) _lootMenuManager = CombatManagement.Instance.LootMenuManager;
_root = uxml.CloneTree();
_iconImage = _root.Q<Image>(UIUtilities.GetUIClassName(UI_NAMESPACE, CLASS_ICON_IMAGE));
_titleLabel = _root.Q<Label>(UIUtilities.GetUIClassName(UI_NAMESPACE, CLASS_TITLE_LABEL));
_descriptionLabel = _root.Q<Label>(UIUtilities.GetUIClassName(UI_NAMESPACE, CLASS_DESCRIPTION_LABEL));
_selectButton = _root.Q<Button>(UIUtilities.GetUIClassName(UI_NAMESPACE, CLASS_SELECT_BUTTON));
_selectButton.clicked += () => OnSelectButton();
}
I just CloneTree(), and then Query it like usual?
I can't see where you're adding it to the UI, but sure
Hey, does USS support something like CSS keyframe animations? I'm currently using some unholy combination of code and USS transitions to do what I want but tbh I'd rather do it all in USS
Like, feels like a real hack having a USS class for each keyframe and then using code to add classes after each transition finishes
nope, not supported
you'd be better off animating it through code w/ AnimationCurve
The way I can see how it could be done - you can register transition events
which will change style when transition is over
thus
retriggering new transition
This is how I have it done currently
welp, that's the way it is for now
ok so. I've been getting a segmentation fault when loading a new scene. The stack trace shows that it involves UI toolkit, IMGUI, and URP. Here's the managed stack trace:
at <unknown> <0xffffffff>
at UnityEngine.Rendering.ScriptableRenderContext:Submit_Internal_Injected <0x000e0>
at UnityEngine.Rendering.ScriptableRenderContext:Submit_Internal <0x00072>
at UnityEngine.Rendering.ScriptableRenderContext:Submit <0x000d2>
at UnityEngine.Rendering.Universal.UniversalRenderPipeline:RenderSingleCamera <0x01b52>
at UnityEngine.Rendering.Universal.UniversalRenderPipeline:RenderCameraStack <0x02b8a>
at UnityEngine.Rendering.Universal.UniversalRenderPipeline:Render <0x00ca2>
at UnityEngine.Rendering.RenderPipeline:InternalRender <0x001e8>
at UnityEngine.Rendering.RenderPipelineManager:DoRenderLoop_Internal <0x0041a>
at <Module>:runtime_invoke_void_object_intptr_object_AtomicSafetyHandle <0x00234>
at <unknown> <0xffffffff>
at UnityEditor.EditorGUIUtility:RenderPlayModeViewCamerasInternal_Injected <0x00106>
at UnityEditor.EditorGUIUtility:RenderPlayModeViewCamerasInternal <0x00092>
at UnityEditor.PlayModeView:RenderView <0x00caa>
at UnityEditor.GameView:OnGUI <0x02922>
at UnityEditor.HostView:InvokeOnGUI <0x003e8>
at UnityEditor.DockArea:DrawView <0x000d2>
at UnityEditor.DockArea:OldOnGUI <0x014c2>
at UnityEngine.UIElements.IMGUIContainer:HandleIMGUIEvent <0x00b92>
at UnityEngine.UIElements.IMGUIContainer:DoIMGUIRepaint <0x0082a>
at UnityEngine.UIElements.UIR.RenderChainCommand:ExecuteNonDrawMesh <0x00ae1>
at UnityEngine.UIElements.UIR.UIRenderDevice:EvaluateChain <0x02842>
at UnityEngine.UIElements.UIR.RenderChain:Render <0x00cfa>
at UnityEngine.UIElements.UIRRepaintUpdater:Update <0x007c2>
at UnityEngine.UIElements.VisualTreeUpdater:UpdateVisualTreePhase <0x001e9>
at UnityEngine.UIElements.Panel:UpdateForRepaint <0x00212>
at UnityEngine.UIElements.Panel:Repaint <0x00592>
at UnityEngine.UIElements.UIElementsUtility:DoDispatch <0x00478>
at UnityEngine.UIElements.UIElementsUtility:UnityEngine.UIElements.IUIElementsUtility.ProcessEvent <0x002c2>
at UnityEngine.UIElements.UIEventRegistration:ProcessEvent <0x00233>
at <>c:<.cctor>b__1_2 <0x0009a>
at UnityEngine.GUIUtility:ProcessEvent <0x00114>
at <Module>:runtime_invoke_void_int_intptr_intptr& <0x001b5>
Does anyone have any leads on where UIElements may cause a seg fault?
anyone know of a good website that provides interactive ideas for mobile games? Such as functionality, what works, what doesn't, etc.
probably a stupid question, but how do i make an integer field show the int inside it? (there is a 0 in the one in the screenshot)
so trying to bind a UI elements list view to a list of strings i got in a ScriptableObject
var definesListView = root.Q<ListView>("ManagedDefines");
definesListView.itemsSource = _defineSettings.ManagedDefines;
definesListView.makeItem = () => new TextField();
definesListView.bindItem = (element, i) => {
var elem = (TextField)element;
elem.BindProperty(managedDefinesProp.GetArrayElementAtIndex(i));
};
this seems to be doing the job as far as binding existing items. but not sure how to handle the creation of new items or removals
managedDefinesProp is a SerializedProperty for that list in the SO
just add your item like usual to the itemSource (List) then all you need to do is myListview.Rebuild()
well that would be the reverse
its the UI needing to update where its stored not the other way around
pardon?... you wanted your listview to be updated when you add new item to list, right?
no the listView has add and remove buttons
and it needs to update the stored value
oh, gotcha... it should be simple
right now with that code the binding works for existing elements like i change the text and i can see the changed text in my diff
but adding just indexes out of range, since it does not exist yet
i tried binding to the whole collection and that does not work, so thinking i need to hook into itemsAdded
you need to tailor your own container for the makeItem like this
Func<Foldout> makeItem = () =>
{
var root = new Foldout();
var tmpName = SGlobalTemplate.STextField(" Name : ", "");
var tmpDes = SGlobalTemplate.STextField("Desc :", "");
root.Add(tmpName);
root.Add(tmpDes);
return root;
};
the enable the addremove property of the listview
then inside the bindItem, you can do something like this
Action<VisualElement, int> bindItem = (e, i) =>
{
if(myItemSource[i] == null)
{
myItemSource.Add(new MyClass());
}
}
so it won't throw null exception
should be more than that, but it will get too long to explain it all here
Note: The showAddRemove footer is for top-level Lists, so if your class is deep nested, you should use the method above
otherwise just use buttons to add and re-draw everything when added
yeah that code would not work, im am just going to mess with it
aigh, have a nice day 🥳
all that would do is a index out of range like i already get, guess i will just have to detect if the index is in range first, then doing a InsertArrayElementAtIndex if out
I said it here 👆 ... addRemove would not work if your custom class is a nested class... you should do it like what I've shown there to make it work
by creating dummy/default instance it would not throw
Just use buttons and forget the addRemove footer stuffs if that's too confusing 🙂
managed to get it binding for the array size correctly now too, did not realize in bindItem i could just build a string that contains my index for the binding paths of the sub elements too
how should I have a button setup so clicking anywhere on the button works?
spawning a child into Offer makes it so when I click the child nothing happens
ended up placing an invisible button covering the entire thing...is there a better way to do this?
I added com.unity.ui via PM yet not coming up in PM and showing as a "shim" in my packages. I have deleted my Package Cache and a bit stumped 🤔
It's built-in in most Unity versions now.
Hmm I knew that things like UI Builder were built-in but I thought you still needed the package for some editor elements. Cant find TwoPaneSplitView. Deprecated? Or am i missing it?
https://docs.unity3d.com/ScriptReference/UIElements.TwoPaneSplitView.html check if it's in your version using the sidebar
Yeah not showing up in UI Builder library.
Editor authoring enabled and everything
It might not be available in the UI builder, no idea
Definitely used to be
Ah there we go. They removed it from the library in UI Builder, but you can show hidden elements by enabling dev mode in the editor.
its works you can either sublcass it with your own type, and it will show up in the builder with your project components
or just add it in the uxml
please educate me on this, in any class UI toolkit provide its has blablaclassName , so as far i understand, like from the pict inputUssClassName referring to input when we type text textfield, labelUssClassName refer to the label of the textfield, and to be able to styling the textfield or any UI toolkit class, we can create a class selector like .my-input-text-field and blabla, the set that to inputUssClassName, or am i wrong?
looks like the way unity handle IMGUI editor window and UI Toolkit Editor window are different in time its called, so i make test which from On Enable, Public Static void OpenWindow, and GUI method will be called first, so the results is:
if using IMGUI, the flow is On Enable => static OpenWindow => and OnGUI will called last,
while if using UI Toolkit, On Enable => CreateGUI => static Open Window, so this lead to if i want to open Window from Custom Editor and pass the target object from there, the target Object will be null if using UI Toolkit, but the target will not null if using IMGUI
I want to make as suite of Editor windows that all have access to a secure local database. Ideally I would like one editor window to act as the login window and all others to allow for the direct manipulation of data under a secure connection. I can make the secure connection I just want to know if there is a nice way to handle globals in editor windows so that as I go from window to window and they are all aware of the secure login tokens while the application is loaded.
More of an #↕️┃editor-extensions question, but you might make use of SessionState or EditorPrefs @tacit forum
So many people doing fancy things I didnt know was possible lol
How do you set a styleClass via code? .button, .header, etc
I found it. public void AddToClassList(string className);
How do I use default OS cursors, like for example resize-horizontal?
Everywhere I only found that it isn't supported
But this kinda seems like a really useful thing to just leave out?
sorry, what exactly do you want?
In the style settings of a UI element you can define a cursor when hovering over the element by Texture...
But I want to use the default OS textures, the one where you for example - resize a window on windows, or the move element cursor
Is there no way to just use these by ID?
Most of them exist on every OS
.
There is an EditorUtility for it - or there was rather, but even that only works in the editor and not in build
now I could just yoink the ones from windows, but thats a lot of extra work for something that could be and should be a default feature
Also, what's even the copyright on these? What happens if I distribute to Linux with these texture files?
seems like a no-no
is there any callback for when a visualelement about to be detached from \the parent?
Like when we removed them from the hierarchy
there are panel callbacks
Attached/Detached to panel
Hello, I have a custom property drawer for a struct. Any idea how I could use PropertyDrawer.CreateInspectorGUI() from UIToolkit? It's inside a graph, not the editor so I don't have access to a serializedProperty to hook to the custom drawer
like ListView scrollview sorta broken too https://forum.unity.com/threads/how-to-refresh-scrollview-scrollbars-to-reflect-changed-content-width-and-height.1260920/
I just found a bug regarding capturing the mouse pointers - if you remove the element that was capturing from the hierarchy completely it will still have the mouse, and capture all events itself
if this is ListView then that's expected (you should unregister the callbacks)
any UIElements that does pooling would behave like that (I only know ListView, not sure about others)
hi im trying to create Custom Control for Grid layout with pagination, and what event actually if i drag Visual Element or Button or whatever, to that custom control, its will be automatically child of content-container, thanks in advanced
this may help to start, but make sure you don't use anything from the UnityEditor namespace, because that won't work from a build https://docs.unity3d.com/Manual/UIE-create-drag-and-drop-ui.html
can I somehow get on which ui element I clicked?
click event propagation goes over multiple elements
I have a dragging feature here and I need to check if in the area I defined I clicked on the right element and not the one on top of it
MouseController.RMBPressedChanged += delegate
{
var mousePos = Mouse.current.position.ReadValue();
var top = new Vector2(root.style.left.value.value, Screen.height - root.style.top.value.value - root.layout.height);
var bottom = new Vector2(root.style.left.value.value + root.layout.width, Screen.height - root.style.top.value.value);
if ((mousePos.x >= top.x && mousePos.x <= bottom.x) && (mousePos.y >= top.y && mousePos.y <= bottom.y))
//check if i didn't click on some other element inside the box
{
sortingOrder++;
gameObject.GetComponent<UIDocument>().sortingOrder = sortingOrder;
StartCoroutine(DragWindow());
}
};
I wanted to do this through OnPointerDown(), but strangely it doesn't do anything
sorry i missed it, so this is for Editor Scripts, maybe my question is not clear, so lets say i drag ListView to hierarcy in UI Builder, then i add Visual Element to that ListView, UI builder understand that was a child for ListView, and put that as child of ListView content Container, this what i want to know, as for now, if i drag a Visual Element to my Board Pagination its become child of Board Pagination as supposed to be child of board-pagination-content-container thanks
Should you use UIToolkit for in-game UI currently? I've seen people say that it's not that suitable for UI in playmode.
Should I stick with the older ways of doing things?
it is fine to start development, there are some bugs, that have workarounds, but other than that it's ready
Alright, thanks!
Heya! Is it possible to make a VisualElement clickable or are buttons the only items that are able to be clicked? I've sifted through tutorials on how to make uGui images clickable as there isn't a whole lot out on ui toolkit yet, and have tried adding a pointer click event trigger to the UI Document object but that doesn't seem to make it clickable-- would you guys have any ideas?
RegisterCallback<ClickEvent>
Thank you so much! 👍
If it's a very simple UI then you could use UI toolkit with the benefits of the styling and auto layout
But it has major downsides currently:
-No ZIndex, the hierarchy is built from top to bottom
-This means if you want any dropdown / popup / tooltip you need to create a separate parent for these elements that are at the bottom of your hierarchy
-As far as I know you can't make an element click-through
-No way to render anything with custom shaders
And it's a bit buggy yes
-As far as I know you can't make an element click-through
If I understand you correctly, you are wrong and click behavior is managed withpicking modeproperty
It's also possible to render stuff with custom shaders but it requires reflection
And you can't do multiple passes
There's honestly worse things than lack of zindex
elaborate?
this sounds like a very cool stuff
There is a material field on the visual element but it's internal
internal? no need for reflection then
just assembly reference 😅
There's actually 2 but I don't remember which one is used
interesting
What you do is literally just download unity shaders, find the uitk shaders and extract to your project
Then just swap the material with your shader
No need to set any keywords or values on the material I think
Awesome, thank you for all the replies (goes for everyone)
Anyone know why I cannot click on my Button? It seems like it's inactive and I don't know why.
All I did was add it to my scene via an empty game object with a UI Document component
Am I right in thinking that the ui toolkit is unsuitable for things like unit life bars?
I tried a really basic implantation of having 300 units each have their own ui document that just contains a status bar, and moves that above their own head, and the profiler has that function alone taking up about 10% of my cpu
Mostly this
Repost:
so this is for Editor Scripts, maybe my question is not clear, so lets say i drag ListView to hierarcy in UI Builder, then i add Visual Element to that ListView, UI builder understand that was a child for ListView, and put that as child of ListView content Container, this what i want to know, as for now, if i drag a Visual Element to my Board Pagination its become child of Board Pagination as supposed to be child of board-pagination-content-container thanks
That is not a style variable, is it?
and tooltips and other informative popups
why would you want them on tooltips?
like you could have a whole info section with images of an item
well yes, and why would you want clicks to be ignored by visible elements?
that would mean user will click blindly
if he decides to click tooltip somehwere
well, that part is handled by other events
user hovers over something else tooltip comes up
hovering doesnt work with picking mode?
not sure, I believe it shouldn't
is that what you mean?
but
I haven't been able to achieve it yet myself
but I believe tooltips can be implemented as children of main element you hover
so this way
you believe wrong
no Zindex
remember
why is it relevant?
if you have anything below
as child of element it will be on top, as long as main element is on top
it will overlap your tooltip
yeah, I had to create a specific element for dropdowns aswell
well
which is annoying af
one way to work around
is to develop a check which determines whether tooltips should appear at all
for example if currently dragging - no tooltip
but I strongly against making them not picked
as this hurts hyperlinks inside tooltips as well as user experience with accident clicks
ideally the tooltip in the case I mentioned appears with a fade and disappears with a fade while you can start fading in a new tooltip
look at Minecraft's inventory
how the tooltips for items are done
I'll go remember how my tooltip implementation works 😅
ah, my implementation just makes tooltip appear so mouse is already inside
yeah, I remember now
how parenting didn't work out
oooh
I know
you can change picking mode dynamically
or wait
nvm
that will not help new tooltip appear
as you hover over another
but that's a good thing though
🤔
yeah, usually in web dev it should, also in most other xml UI frameworks xD
well, dynamic changing stands valid actually
it isn't if you want something similar to Minecraft's tooltip
if mouse left tooltip
you make it ingored
it fades
and you can already hover element behind it
I don't remember at all minecraft tooltips, but I don't think swapping tooltips as you hover over them is a good idea
at least
I do it with having hyperlinks inside of them in mind
tooltip inside tooltip
and etc
what about a usecase where you have something transparent, like a looking glass in front your elements
and you want them to be hovered
set picking mode to ignore
if it works on hover
okay
over another
Anyway, missing features missing features