#🧰┃ui-toolkit
1 messages · Page 27 of 1
Hey Everyone, I'm trying to create a PanelSettings asset per this tutorial https://docs.unity3d.com/2021.2/Documentation/Manual/UIE-HowTo-CreateRuntimeUI.html, but the only option under right click -> UI Toolkit is to create UI Document. I also don't have Unity Default Runtime Theme under the theme dropdown in UI Builder. I'm running 2021.2, so the runtime stuff should be integrated. When I try to install the com.unity.ui package just in case, I get an error that it's incompatible with my current Unity version. Anyone have any idea how I can get to the runtime stuff?
hmm, I installed 2022.1, and those features are still missing
oh geez, I solved it for myself. I was right-clicking in the hierarchy window or the game view. Right-click -> create in the project window has the panel settings asset.
Does anyone know how to use sprites in the text above like you could with TextMeshPro? See top of the screen.
UITK doesn't have this functionality built-in afaik
Is there another way to have pictures in text in UITK?
Not really. You could maybe implement a custom TextElement. But in the end, you have to add a VisualElement for each image you want to have in the text. That's just how it is, custom element or not.
Is this what you’re wanting to do? Does this help? https://forum.unity.com/threads/feedback-wanted-new-text-engine.1007585/ not sure if the bug with only working at runtime is still true
is there a better way of forwarding camera output to a UI element than manually making an image and setting it as backgroundImage?
This sounds fine - if by image you mean a rendertexture hooked up as the render target of the camera?
I couldn't directly set a rendertexture as the background image, that's the issue
ah - I just realised I think you might not be able to set an RT as a background Image for a ve (yet?) - but you can set it for an <Image>
UI Builder doesn't let you add Images directly but if you edit the uxml and replace VisualElement with Image (and any corresponding closing tag), you'll then be able to set myThing.Q<Image>().image = myRT;
ah, cool, I'll try that!
Hello, how can i put a viewport into my UI? I am basically trying to make an app, not a game, that utilizes a viewport within the UI, instead of the UI being on top of a viewport
I think you can just use a Image and set its image as the RenderTexxture of the camera
I also got to that point, but doesnt the scene just render in the background too then? Basically twice
From what I know, no. As long as the camera has a target texture it will render to that instead
It is an easy thing to check though 😉
Awesome! Thank u very much🍻 cheers man
Why does the slider always revert back to 0 when clicked?
How are you setting it?
In the WYSIWYG i set it in the proprrty window. In the code i set it with a value
Literally testslider.value = val
So it resets to 0 even if the default value in the builder is different(and no code affecting it)?
And the val comes from vois SliderChanged(int val) thats called by the TestSlider.RegisterValueChangedCallback blabla in void Start()
When i start the game it starts at the value i want it to be but when i drag it then boom 0
And then when i drag it again to lets say 4, it stays at 4
But when i drag again, boom 0
Does that happen if you comment out your callback?
It happens when i dont even have any code attached
It happened already before ive even created a c# script file
Just the ui itself
It has nothing to do with code
Okay. Where in the properties do you have the value set?
take a screenshot
Sorry i have no wifi on my laptop atm so this will have to suffice. I dunno what u mean, u can literally make a toolkit ui file, drag a slider onto it and see for yourself. It has literally just one option to set a value. Did u ever used toolkit before?
I never encountered this problem in Qt, gtk, tk, sciter, kivy, delphi or any other WYSIWYG
The value is 0 though..?🤔
Ah yes sorry i changed it
Just think of low as being 0
And value 6
Dont mind it
Thats not the issue, dont think im dumb. I created literal apps from scratch before haha
Dw i dont make such stupid
I only use unity infact cuz doing 3d app is too much
So i use 3d function of unity
Okay. Should be able to do some debugging then. Add a breakpoint in on value changed and look at the stack trace.
So what changes the value to 0?
Even called it on every frame
I mean, in code...
Well, where in the source code does it set the value to 0?
a log would do as well. It should have a stack trace, no?
Ok how to do that in unity, i tried turning debugger on but nothing is printed anywhere
you need to add breakpoints. It's the same as debugging any other app.
And where am i supposed to put the breakpoint? The only thing i can see that i can debug is the value itself, which i did
I didnt invoke the slider via code, i invoked it via the WYSIWYG
Its not coded is literally drag n drop onto canvas
On value changed callback.
It doesn't matter if you do it via code or the editor. There's still code running behind that changes the value whether it's yours or unity's
Ok i seriously have no idea on how to do that in unity
Yea ik but i dont know how to access it
I tried doing that earlier like 3 hours ago too but didnt find anything besides the debug mode thats not giving me anything
Like full clear log
Nothing
Not unity. In visual studio add a break point in your method that's subscribed to on value changed callback. Then see where the first stack trace leads to.
You don't even need to use the debugger for that. Just look at the first log(that says that the value is set to 0) and check it's stack trace.
I use VS Code
Well, VS code is not really an IDE, so I'm not sure you can debug your code from it.
You can
So the only option left is looking at the log stack trace.
It allows breakpoints
But i never did it like this, i only did it via running code within vs code
Not externally
Okay. Then either it's not configured properly, or I've no clue. Never debugged with VS code.
https://marketplace.visualstudio.com/items?itemName=Unity.unity-debug you need this and the rest configured
Either way, you can look at the console log stack trace with the same result
Console is empty tho
I thought you were debugging stuff with logs..?
So you do have logs in the console?
No i just used Debug.Log(val) because apparently debbuging doesnt work for me rn. I setup vscode to debug and attached it but now it says since 4 minutes "Reload Script Assemblies" and i cant do anything
Ah now it goes further
Wdym? Debug.Log is supposed to output logs in your console...😅
Yes it does put out the value, like i said
I did so that every frame it outputs the value of slider
well, then look at the log message, look at it's stack trace...
Look at the stack trace(call stack) of the message
I told u that it ouput the exact value of the slider and once you touch it, it said 0 until u dragged it back somewhere and then touched it again upon which it jumped back again and output 0
Or what
No
I just tried debugging now but it outputs nothing besides initializations
No changes in values
It's the chain of calls that lead to the Debug.Log call. The history of the calls. You're supposed to know things like that if you really have several apps released.
That's weird.
Anyways, if you look at the log details, you'll see the stack trace, like that:
I dont have that tho
What do you have then?
Man, i just want to know how to stop the slider from jumping back...
Well, I can't help you without you providing enough info...😅
What happens if u make a toolkit file and put an INT Slider in and then press on preview and try to drag it a couple of times
Does it not jump back all the time?
I'm installing it now
Eee thank u very much that u try it! Because ive not seen any thread on this issue. Maybe is a bug with my version of Unity?
I use 2021.2.7f1
Bruh
I feared that my version might have a bug
Worst thing is that i have no wifi to change version
I don't think it's the version.🤔
I created a new ui file and there it works too, thats so strange! Maybe my file was just corrupted all along
Probably just messed up with some setting...
Aha wait, try to set the flex direction to be the left one so that the text is above the slider!
Yeah, it does reset to 0
Strange! Isnt it?
The package is still in preview, so no wonder there are bugs. If it's really a bug.
imo this is a good approach. Worth submitting the bug or at least posting about it on the forums though - provided you're on a recent Unity & package/included version of UITK of course.
Unity ver 2021.2.7f1 and i dunno where to see the UITK ver, i tried finding it but ehh😅 i only found "Unity UI" which says ver 1.0.0 dec 11 2021
I believe it's built-in with 2021.2 (though maybe editor only?) anyway, posting that unity version should be sufficient
It seems UIToolkit requires InputSystemEventSystem.cs in order to work with New Input System (at least on 2020 LTS). But I can't add Hold InputAction because the script supports predefined amount of inputs. But I can use PointerUpEvent to mimic the hold action with ClickEvent and deltaTime. Is it how Hold UI Action should be implemented?
I feel like this is something silly, but when I have an image in my resources folder, and I use the
background-image: resource('my_image.png');
It works in the editor, but does not appear in the build, any idea why?
hmm, I think I figured it out, but it feels weird / not sure why.
If they are in the same resources folder, it works as expected, so I guess the USS needs the path to be relative to itself?
oh nvm, that only works if I use the url('...') instead of resource('...');
yep, it helps to read the docs...
Hi, I have a problem. I've started using UI toolkit and faced an obstacle. I don't know how to disable OnMouse*** events when object is hidden under UI. Can you help me?
am trying to create tool to editor using the new Ui elements am having ObjectField the problem ObjectField doesn't persist the object after attaching it became empty again
I'm trying to create an enum field for some editor gui and it looks super broken (completely white, no label). am i doing anything wrong here?
var value = EnvironmentPrefs.Environment;
var field = new EnumField(value);
field.RegisterValueChangedCallback(evt =>
{
EnvironmentPrefs.Environment = (EnvironmentType) evt.newValue;
});
same thing happens for DropdownField 🤔
but ToolbarButton looks fine for the two buttons to the right of the dropdown
Ended up doing it with imgui 😦. not sure why the style wasn't workin with ui elements
return new IMGUIContainer(() =>
{
var env = (EnvironmentType) EditorGUILayout.EnumPopup
(
EnvironmentPrefs.Environment,
GUILayout.Width(100)
);
EditorGUILayout.Space();
if (GUI.changed)
EnvironmentPrefs.Environment = env;
});
How UI toolkit works input wise?
Is it using old input system to detect click/mousover and etc events?
@stiff briar Don't cross-post. Also not related to this channel.
well which channel then? @ornate cliff
Where can I find any guide on how to switch UI windows?
For example:
Main menu -> settings windows -> back to main
and etc
@gusty estuary It's just logic activating and deactivating UI elements. You can find UI Toolkit examples in the pins here top right.
What is correct approach at making multiple windows?
Do I make them as different elements within one document or different documents instead?
whats ui toolkit?
Read the pinned documentation
I intend on creating a tool for myself to better keep track of how scenes are connected in my sidescrolling adventure game (similar to the attached image from one of AdamCYounis videos). I'm looking into either learning editor extensions (and editor windows) or the UI Toolkit. What would you folks recommend me choose for this use-case?
How to use Text Fields?
I can't seem to find anything in it's class related to allowing editing it
meanwhile when I simply try it out in play
it just gets blue
on click
and nothing else happens at all
Hey guys, Ive got a question regarding TextMesh Pro... Im trying to customize an UI and there doenst seem to be a way to customize the dropdown list area?... Ive added a screenshot of what area I mean.
it can be customized completely
It is made of normal UI images and TextMeshPro - Text components
Im not sure how to find the way to change the colors and text styles around on this list area... as you can see everything else is stylised but the dropdown list.
I can see the components I need to customize and I can customize them in play mode, but once I leave play mode they dissapear and it doesnt save the changes I made while in play mode.
Not sure if I'm being clear, I'm quite new to this whole thing..
It's all based on this Template stuff:
you can activate it and modify it
and then deactivate it again
Oh so you just need to activate it in order for the changes to be saved!
I will try it out, thanks a lot for the help!
no you need to make the changes outside play mode for them to be saved
Yes! Ive got that hah
how to bind list of gameobject with list of ui elements
i managed to bind a list but for some reason it doesn't save when i drag elements to the inspector
serializedObject.FindProperty("_scriptgameObject").arraySize = root.Query<ObjectField>("GameObject").ToList().Count;
List<ObjectField> uiGameObjects = root.Query<ObjectField>("GameObject").ToList();
var ScriptGmaeObject = root.Q<ObjectField>("GameObject");
for (int i = 0; i < uiGameObjects.Count; i++)
{
var uiGameObject = uiGameObjects[i];
SerializedProperty _scriptgameObject = serializedObject.FindProperty("_scriptgameObject").GetArrayElementAtIndex(i);
uiGameObject.BindProperty(_scriptgameObject);
uiGameObject.RegisterValueChangedCallback(evt =>
{
uiGameObject.value = evt.newValue;
Debug.Log(uiGameObject.value.name);
});
}
serializedObject.ApplyModifiedProperties();
calling this at the end will solve the problem of saving but it throw error
NullReferenceException: Object reference not set to an instance of an object
i found the problem it was causing RegisterValueChangedCallback just be sure that uiGameObject.value is not null
any tip which one is "row"?
the one that's selected - you can hover over the icon for a tooltip
there is no tultip besides name of field which is
uuugh
"direction"
xD
yea maybe they broke it recently - I remember it previously saying. Anyway, they are in order: column, reverse column, row, reverse row
reset doesn't work in ui toolkit why
foldout out of the container
Any idea what am I doing wrong?
basically, on it's own doc is fine
meanwhile nested in some other doc it's broken
is there a way that I can get the UI builder to know about my PanelSettings object, so that it will include the styles and classes I have defined in a USS file attached to that and display things correctly according to that?
anyone know why my event.localPosition keeps jumping around between the previous value and the new value?
I'm assuming it's because I'm checking for changes and applying them at the wrong parts, but, I'm not sure what. I'm doing it in
void OnPointerMoveEvent(PointerMoveEvent e)
{
if (e.target == slider)
{
Debug.Log(e.localPosition);
slider.style.translate = new Translate(e.localPosition.x, slider.style.translate.value.y.value, slider.style.translate.value.z);
}
}
Is there a way to register callback on literally any event?
Sort of make "press any button to continue"
Okay so I have an ObjectField that I'm trying to have take in a ScriptableObject. under the type section for the ObjectField I type in ScriptableObject, but it says "Type Attribute is an invalid type. Make sure to include Assemble Name." When I go to the docs for SOs it says https://docs.unity3d.com/ScriptReference/ScriptableObject.html that SO is implemented from UnityEngine.CoreModule. When I search through the Unity Assemblies I find that ScriptableObject inherits from UnityEngine.Object
So what is the actual assembly that I'm supposed to add to the Type field in the UIBuilder ObjectField?
Scripting button question here:
Currently I am working on generating TextMeshPro buttons at run time and the buttons themselves are being "made" but they are not rendering anything except the text of the button. Is it possible for me to generate the buttons at runtime or should I just have hidden buttons that get moved & activated at runtime?
Either way is possible and which one you want to do is up to you
Try this:
<UnityEditor.UIElements.ObjectField type="UnityEngine.ScriptableObject, UnityEngine"/>
You need an "assembly qualified name" here. There are multiple formats which might be supported. My example seems to be the simplest one. The issue is a little more complicated than usual because Unity does assembly forwarding (you access everything through UnityEngine or UnityEditor, although internally they split things into multiple dll modules). But well, it seems to work with using the forwarding assembly "UnityEngine" and also without specifiying any version.
element.resolvedStyle
If that is what you mean
actually i found it was smth about
element.stylesheet.Add()
and then element.AddExistingClass(string) or smth like that
ngl, it was hard to find
So I've got a whole bunch of UI I've already built using game objects and custom scripts, is there a simple way to go about attaching a style sheet to modify how those elements are displayed?
Also, is USS SCSS compatible? I'd think most likely but figured I'd ask
No and no. UGUI is not related to UIToolkit at all, and USS is highly specific right now while it's still just being built out properly.
Ah damn, that's unfortunate. I'll still play around with it and see if making the transition is worth it for me.
Anyone know how to make it so that the objects with an .uss file get visually updated automatically when I modify my .uss file in the UI builder? They only update when I press save. Maybe there's a way to autosave?
Does anyone know if UI Toolkit can be used to make custom ShaderGUI?
any idea how to apply my style to elements of list view correctly?
I add my style .label-profile to it, it actually exists upon making item, but for some reason style wouldn't be visible.
Text is supposed to be centered, different size, no borders and etc...
nvm, I made a typo in class name
🙃
How do i register a mouse click in the sceneview? Im using a script inheriting from EditorWindow and nothing seems to work
What are the general standards for usage of UIToolkit? Is it generally wise to have a new VisualAssetTree per 'UI window' (eg. main menu, settings, load world) or to have one VisualAssetTree for all of said UI windows?
I prefer the former - one way to think about them is similar to prefabs. Each uxml can be used inside other uxmls so making components that you can reuse is very beneficial. Instantiating at runtime can be expensive though so in general, trying to instantiate on load then show/hide what you need works well I find.
Cool, thanks for your input. This is what I was leaning towards too - It just seems very much inline with the webdev style of the UI Toolkit
Excited to use this new system, it looks like it'll make a lot of UI management easier
I have an asset which is two labels within a container. If I use it as a nest asset within another UI Document, can I edit the two labels' text inside it without unpacking?
Alternatively, can I at least edit those inner labels via code?
Hey
I'm looking for a way to add 3D elements into an UI document.
Is this possible?
Or would i be better of with the previous gameObject based UI system and put it in screen-space?
hi, im having a problem setting the background for ui, i know i can set the clear color to work around it, but i wanted to ask if im using the canvas background wrong here
What are you trying to achieve by doing so?
Apparently there is a way to draw a 3D model in CSS but it's fiddly, especially without a JS engine
https://codepen.io/bryanbraun/pen/JdLoyd/ This is an example of doing so. I would not recommend
I think the canvas background is just for the UI Builder's display
What you actually want is a visualElement with its background set to the colour
(take that with a grain of salt)
if i do that there will be bars on the top and bottom of the document cuz margins
Remove the margins then?
Is there a cleaner alternative to using
VisualTreeAsset template = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>("Assets/Editor/UIRichLabelTemplate.uxml");
to load uxml files within a custom VElement?
Serialize it into the script asset
It's an extremely handy way to set up references with Editors and EditorWindows
Oh of course. It’s still a script, not some new mystical object. How did I not realise that 🤦♀️
Thanks
Actually, I've had a go at it and can't figure out how to get Unity to allow serializing into a script asset. I can find some stuff on serializing into EditorWindow inheritors, but VisualElement doesn't seem to follow the same method
VisualTreeAsset you mean?
The script is a VisualElement inheritor, I'm trying to put a VTA reference into it, yeah
Ah, yeah that won't work. The reason it it works for editors and editor windows is because they're scriptable objects
Sorry for leading you down the garden path there
Ah, I assumed VE was a scriptableObject by your first response 😭
Oh well, hardcoded path it is I guess
Interesting that it's still Unity's solution to these issues. It seems fickle
Any idea how to restore all uxml if you move them from one folder to another?
if they reference smth
Well that seems overly complicated. I didn't realise the UI document was based on actual webtechnology, just thought it was modeled after it.
I tried using the UGUI, the one with gameObjects, canvas, anchors...
I put the canvas in screenspace and can put 3d models there.
It's not ideal, but using the UI toolkit will be too much of a hassle.
You never said what you were trying to achieve
Because it’s likely there’s a better way than what you’re trying to do lol
You know, in Autocad or Blender, on the right top corner of your 3d view, there's this cube?
the one you use to rotate around or set up your Top View..
i want something like that
I figured. You should blit / use a camera render target to render the model to a texture, then apply that to an image in the UI
That's possible with UIToolkit as well as canvas UI
If using an SRP you might run into overhead issues with using a camera to render it (you also might not). In that case you can pass a fake view projection matrix to the shader
Is the display style able to be transitioned?
Since in css it's not
And I want to animate my opacity and display so visual elements can fade in and out
Transitions do exist in css
Anyone know if there's a fix for this? https://puu.sh/IFiIg/6159a13f63.mp4
This are the default UIElements sliders. They appear to only respond to MouseUp if the mouse is over them. So if you drag off them, they get stuck. This is incredibly irritating.
Sorry, I meant that the "display" style specifically isn't supported by css transitions
But since in UI builder it shows display in the list of transitionable properties
Unity probably has some way to transition it
Similar to how css transitions visibility ig
Wow, the source for UIElements is insanely unworkable
This is incredible. Please can someone tell me how you're supposed to register to input events within UIElements? All I want to do is get events for PointerUp regardless of where the cursor is, but I absolutely cannot figure out how this Manipulator/EventPool stuff works. It's impossible to follow
Provide some more context, why would you want to have an event that fires no matter where you click?
Surely you have some UI you are clicking on, do you want to know when you're not clicking on UI?
This is presumably the result of PointerUpEvent not firing when the cursor is lifted off the slider. It's incredibly irritating UI to use
If it's not clear, I want to remedy this. Initially I was considering inheriting from the slider class to fix it, but I'm not convinced that's viable considering how spider-webby and difficult to understand the UIElements control / support classes are
(I'm also on the latest version of Unity 2022.1.0b4.2571 in an effort to determine if UIElements got any better since the version I was on)
I presume you're just registering a value change on it and not doing anything weird
I'm not even touching the slider. Only checking the value when preview is clicked
Aside from the styling and min/max/value properties it's default
Well, then their implementation probably sucks, it should use .CaptureMouse(...) until up is detected
Well, I can't find it in the source relating to sliders. I still couldn't tell you what on Earth they're doing in any of these classes though
it's sad that now UITk is back to being built-in you've got to update the engine to get any fixes
I'm... A little shocked they built it in while in this state.
The documentation is atrocious, and features just don't seem to work // work really poorly. For example I cannot for the life of me get UI Builder property fields to retain their values when you click off/back on to the element. (Eg. if "Name" were a custom field, you could change it and it would reflect that in the UXML but once you click back on the element the "Name" field is empty)
I was under the assumption it was production ready, but it seems it is definitively not
This works as expected, thanks. I've mashed my keyboard enough to figure out that VisualElement.RegisterCallback<> is.. probably the way to register events properly
The UI builder has been less buggy as I'm using the latest 2022 version
but I have all sorts of annoying bugs still
tags not being closed by the builder causing it to just clear all the data
sometimes when I try to type in a field it just instantly defocuses so I can only type one letter at a time (I just do it via the UXML instead)
the range slider's so inconsistent and buggy that I will need to modify it somehow to make it more consistent
Restarting the UIBuilder fixes this for me, but yes frustratingly I have noticed this consistently as well
the label dragger tracks mouse delta instead of total delta so if you are rounding the field it just works extremely poorly
so I had to replace their dragger so it would work with rounded fields
Is the UIBuilder also kinda... slow for you? I'm not sure if that's a local issue but typing in the fields yields a 0.5-1s delay on characters actually showing up
I've not noticed
No maths in the UI builder fields is really stupid
1+1? Oh that's 11
I'm not sure if I'm missing it - but is there a way to maintain an aspect ratio on an element ala the Aspect Ratio component?
I encountered that issue earlier
use %'s for the width and height
The %'s are only based on the associated axis. I mean if you wanted 50% width, but then for it to be square (so the height should also be 50% width)
Height driven by width and vice versa
I think you have to click that bar perfectly in the center line section
Also I for some reason cannot click dropdowns
Me too!
I have to use the keyboard
I have a dropdown that seemingly does nothing
I'm just hoping some of it gets fixed in the next Unity update and then I can fix the rest of it myself
just leaving it all to the last moment, forging ahead actually making content instead of fighting
I fixed the label dragger though as I doubted they'd fix it
That's probably a good idea. Is there any acknowledgement of the state it's in?
Acknowledgement seems like a fair indicator that they're going to address it ASAP
🤷 you'd have to check the forums, but I post their occasionally and I feel like my threads are ignored so I don't bother that often
Ooft. If a community moderator is ignored, what hope is there for the little guys 😛
It's still a massive improvement on UGUI imo but it still feels early days
well I'm not a mod on the forums lol
I can see the potential but the implementation has definitely left me tossing up between sticking with it or jumping ship back to UGUI
I guess the version history of UIBuilder/UIToolkit is separate from the unity versions, but these default controls have existed for a fair while.
Yeah, I also try to do complex UI toolkit stuff in the editor every now and again and run into all sorts of major breaking issues
some as basic as "you cannot use arrays"
I wonder if that was fixed with the introduction of generic serialisation into (I think specifically) UI Toolkit
I distinctly remember building a UIToolkit custom inspector that serialized an array - actually scratch that I think I manually created a UI for the array lol
Does this also mean the changelogs for UIBuilder/UIToolkit will be included within the editor logs??
In the release notes, yes
But they've already been doing that even for packages not in the editor
https://unity3d.com/unity/beta/2022.1.0b5
UI Toolkit: Fixed missing enclosing character when using attribute overrides in a uxml.
Well, that's one of the basic broken things in the builder
Hey, does UITK have any sort of runtime binding yet? Or is it still on the roadmap?
There is no runtime binding afaik, and I do not know if it's on a roadmap
I see. I took a look on the roadmap and they seem to be working on it in some way I think https://portal.productboard.com/xvo8kmgtx7tkv7desh8cyaj7/c/285-improved-ui-data-binding?utm_medium=social&utm_source=portal_share
Improved workflows for binding data to UI element attributes and registering event handlers on controls.
Yeah I have no idea as to the details of what that means. "Improve" doesn't give hope that it's runtime, but they've probably elaborated on the forums somewhere
Probably somewhere. I know I saw them talking about it saying that they know it is something people want
My current UI does not snap to safe area
Everytime I apply a tutorial, it pushes everything into 0,0 and removes all the anchors
I have tried 3 tutorials at this point 😦
Is there a way of getting cursor position in GraphView? I'm trying to create GraphView.Nodes at my cursor position.
I don't think UI Toolkit has anchors - are you sure you're not using the UGUI with canvases?
Hey guys, I have two questions about the new UI Toolkit. The first question I have is whether there is support for data-binding in the same way there is for WPF, where you can bind directly to properties in a View Model from UXML? The second question I have is about document/UI switching and whether that can be done from UXML also using resources/templates (or whatever the UXML equivalent is)?
I don't think data binding currently exists. Take this with a grain of salt though - I read it was on the roadmap at some point in my own earlier troubleshooting
Everything I can find recommends manually binding using properties so I assume that's still the case
I'm not 100% sure what you're asking in the second half.
The second part of my question was more about the best way to switch between views/documents. Let's say you have a menu and you want to transition between other menu's or UI's or maybe transition between tabs
Generally what the best practices are when navigating between UI's
Ah yeah, I had that same question myself. I ended up using a UIDocument per 'window'. You'll need to switch between them using C# either way
Plus modularity is probably better than monolithic documents, especially in projects with more than a single person
I agree, as someone who like to keep in mind good programming practices (SOLID and good architecture), I definitely don't want to opt for monolithic documents 😛
When you say "window", are you referring to the idea of using one UI document as the base and then layering other documents on top of that and switching?
'Window' being the main menu, the settings menu, the new game menu all as separate documents
To switch between them I have a UIManager static that sets the UIDocument.rootVisualElement's display style to hidden
(IIRC)
I'm not sure if you are familiar with Winforms or WPF but a similar approach there would be to use the main window/form as the main control and have your UI's in UserControls that can eaily be swappedout/added to you window/form
Ah
I understand
Yeah I don't do any swapping of elements. Just hiding/displaying documents as needed
Ah it's style.visibility, not display
So the manager will know about all the documents and just show/hide them depending on what document you want to show
Yes. In my case I call UIManager.Register("WindowName", this) on start from the documents
So the UIManager has a reference to every document by a name
Interesting, that seems to the way the documentation shows as well but wouldn't that get messy at some stage?
How so?
Especially if you have a lot of in-game UI. Imagine having menu's, inventories, shops, HUD and one script knowing about everything
The issue with having decentralised UI control is that you'll probably run into a lot of issues with UIs overriding eachother, or being shown/hidden when they shouldn't.
Having a centralised controller means that if something calls UIManager.Show("MyWindow"), it guarantees that only that window will be shown.
It also makes it easy to store window history (I chuck the windows in a stack when they're overridden so you can go 'back')
Ah, that's a good idea
An 'open shop' button might call UIManager.Show("Shop") while the Shop's exit button does UIManager.Back(1)
If you want a confirm menu, you'd do UIManager.ShowAdditive("Confirm")
Really it's just a wrapper for a Dictionary<string, UIDocument>
I was thinking of creating a state machine to manage the UI's but a stack seems like a better approach
Lol funny you say that because during a project last year one of the other programmers wanted to implement UI the same way. He then tried a stack and managed to make the most convoluted thing I've ever seen
I'll shoot you my UIManager code if you like, for reference.
That would be awesome mate, thank you
I really like the workflow of the UI toolkit and I'm planning on using it 100% in a project that I'm doing with a friend of mine
UIToolkit is an excellent workflow, owing to its basis on webdev. It is somewhat unrefined at the moment though
All fixable issues, but worth noting. If you have issues with it, it's a higher than normal chance of the issue being UI Toolkit's fault
If anything in that script doesn't make sense, feel free to ask
I'm hoping that it's flexible enough that you can work around most of the issues. It seems to cover a lot and you can always create custom controls if needed as well
Will do, I'm currently learning this technology and I need all the help/resources I can get 😛
Yes, it is from what I can see. The issues are mostly just annoying like how the default sliders don't capture your cursor
Could you elaborate a bit on that?
Does the slider not move with the cursor?
That's bizarre
Yes, as Vertx helpfully informed it is in fact a single line of code CapturePointer() that fixes this. The PointerUp event is only usually sent to elements under the pointer, but CapturePointer forces pointer events to be relayed to the element regardless of position
How the devs shipped it with this issue I do not know, but hence annoying.
I'm sure that will be fixed soon
Fingers crossed. For now you can either live with it or ofc fix it yourself
I'm really excited about this piece of technology Unity has though and I hope they continue working on it, there are a lot systems that I could care less for and some even seem to be in buggy states but the new input system as well as UI Toolkit are fantastic tools
They show potential the most out of all the Unity tools in my opinion. UGUI is good but it's not a good workflow in my opinion. It's decent if you know Unity but having separation betwwen the UI and the logic/code is how it should be 😛
The only feature I would love is if they allowed you to write UXML in the preview window. It's good that it lets you preview the generated UXML but they should allow you to edit the UXML in there as well, rather than having to open it up in another editor. They could also go a step further and add auto-completion and intellisens for the Unity -specific commands
I think this would be redundant work though. Time better spent improving the core functionality of UI Builder.
Only apt response is "Get more monitors, nerd" 😛
UI Toolkit and the input system are very nice, yes. I've been a big fan of the new input system since I first started using it
Speaking of which, have you used both of the systems together? Linking UI Toolkit with the new input system
I don't believe it requires any particular linking
Nor did UGUI (except setting the event system to the new input system) iirc
Ah
Which kind of font type do I need to make it render in said font? I have TMP_Font Asset types and regular .ttf but I cant get my text to show up with that font
(while I have tested the font and it works with TMP itself, I cannot provide that font asset or its original ttf file to the Label element)
A FontAsset. It looks like it might be an old font asset type when looking through the assets menu but it's the modern one
What am I looking at
the asset in question i am using does not have the font asset included, it was generated with the Font Asset Creator
yahuh, not in the assets menu
tbh its a little confusing to have 3 different font asset types xD
tho I guess TMP isnt the base text asset stuff, and considered 3rd party
thx! vertx to the rescue once more 🙂
I'm trying to debug the visual elements in the inspector by drawing a colored box on top of them
but I can't seem to make it work
private void DebugElement(EditorWindow ownerWindow, VisualElement element)
{
Box debugBox = new Box();
debugBox.name = "Debug Box";
debugBox.style.position = Position.Absolute;
debugBox.style.left = element.style.left;
debugBox.style.top = element.style.top;
debugBox.style.right = element.style.right;
debugBox.style.bottom = element.style.bottom;
debugBox.style.width = element.style.width;
debugBox.style.height = element.style.height;
debugBox.style.backgroundColor = Color.magenta;
ownerWindow.rootVisualElement.Add(_debugElement);
}
I've never used UITK before, I'm used to GUI.Box(myRect)
how can I set the position and size of a box in UITK?
that code just produces a box with this Rect: 0,0,2,2 😓
Another .style isn't going to have values unless it's also inline. There is evaluatedStyle or something similar (I am on my phone)
Also overriding width and height and top, bottom, left, right seems fishy
Why not just use the UIToolkit debugger to debug? Why do this at all
@rough scarab hmm I see
yeah it's just a learning exercise to see how I can draw elements over already existing ones
but I don't really know how to position an element at all
resolvedStyle is read-only
That's all you need, read from that instead of .style like you are doing to get what's actually in use
ooooh I see
@rough scarab ah thanks a lot for the help! works now
and yeah, setting top, left, width, height is enough
or left,right, top,bottom
so I was tinkering around with my old gameobject based UI system and noticed I was using the EventTrigger script on a few objects. Would it be possible (and a good idea) to migrate those scripts (or the underlying functions while leaving them interactable in the editor with that component)?
These buttons have PointerEnter, PointerExit and PointerDown event handlers on them (in the game object architecture) which is all I would need.
or is there some other way to go about attaching (dynamically in the editor) functions that need to be executed on these (without hardcoding them in separate C# files / uxmltemplates)
anyone know why I can't export my project with UI elements?
Hi guys, does anybody know what is the best approach to change inbetween UI's? eg. (change from Main menu UI to Game UI)
Have the Game UI and Menu UI be on separate UI Documents
As UI Document you refer to a gameobject or a asset? I'm asking because you can create UI document as a gameobject in the hierarchy view and as a asset in the Project view
Okey, thank you 🙂
Hi guys, I have a couple of issues regarding UIElements (I'm using Unity 2022.1.0b5). I've created blank xml, uss files and each time I do anything I get InvalidOperationException: Collection was modified; enumeration operation may not execute. error. The syntaxs and code appears to be valid. Second issue is when checking the UI in-game it appears to be all over the place. The pictures below are from editor and in-game. Any thoughts? Should I downgrade Unity version? Thanks in advance
Hi, regarding first question have no answers. Regarding second question, what do you mean "all over the place"? For me they look the same
There is some padding on the right, text is different color, there is some padding on the top, its clearly not the same 🙂
Do you have Runtime theme in the UI builder?
That was it! After deselecting the default theme its now rendering properly
Thank you a lot! Now I just need to figure out the constant errors about the collections being modified. Thanks again @bleak salmon
Glad I could help 🙂
Regarding your error, I can suggest to create same project in another unity version (2021 / 2020) and see if error would appear, if its not - then it is unity problem
Thats the plan! 🙂 Thanks for your advice
How do I get the #Image to be replaced on the hover event of the #Start element (which is a custom C# control class HoverButton)?
The image resource I am trying to change it into is currently located in Assets/Resources/ButtonSelected.png
HoverButton:hover #Image{
background-image: resource("ButtonSelected.png");
}
preferably, I would place it in Assets/Menu/Resources but if that isnt possible and it needs to be in the root that isnt a big deal
Maybe its important I mention this is runtime code, not editor UIE
im aware I could do this from the C# control class but I would like to use USS for styling purposes as intended, keeping the C# side purely for the functionality to make it as dynamic as possible
Try background-image: url('')
that does not appear to resolve this
HoverButton:hover #Image{
background-image: url("Resources/ButtonSelected.png");
}
The hover event works, so the USS selector is correct.
I dont know why the image does not replace tho
I tried with normal button and it worked, but the path was quite strange. (I used unity provided arrow-down texture )
that's how it looks like
thats a rly weird path to find an image tho 🤔
lol true
I assume the path to my image is the issue tho, as I can tint the image just fine on hover
that is the path of custom texture
background-image: url('project://database/Assets/a.jpeg?fileID=2800000&guid=f73d2f22dc4ec0945a575121a7e421be&type=3#a');
By the way, did you try to add your texture not through the code but by selecting it in the inspector?
yes
still doesnt work tho
thats not the intended behaviour tho, There is text next to the button that also needs to fire the event
if I dont use background-image, but -unity-background-image-tint-color it does apply the style to the button image. which is why I know the selector works
Don't get it 😄
this is the region that is hovered, and the image is only part of that element
so logically you select the C# control and then ask for an #Image child
but that doesn't work for me, I'm testing now.
HoverButton:hover #Image {
background-image: resource('ButtonSelected');
-unity-background-image-tint-color: blue;
}
hmmm, it doesn' work for me tho...
oh probably its because i have a class selector and you have element
first is a class selector, HoverButton more than likely does not exist in your project as that is smt I made myself
What I want to say is that when i have .buttons:hover - then it works, but when i have
.buttons:hover #login-button it stops working.
P.S my button is called #login-button
and on my side a class selector doesnt work...
how you know that?
you tried complex class selector or something very simple?
Try create .container:hover then change background color to any random color and add it to your button. Then tell me does it work
i mean yeah
adding colors works, as that was how I deduced the issue wasnt related to the hover pseudo selector not firing
If #Image:hover doesn't work for you then I don't know what to do
This does not work, so I guess its just a bug```css
#Image {
background-image: resource('ButtonIdle');
}
#Image:hover {
background-image: resource('ButtonSelected');
}
since it is showing me this but not doing it
but if you instead of "resources" would choose texture in inspector then it would work or still not?
still not, I cleared out the content of the classes in the USS, saved, and set the parameters in the editor without any change in the situation
Can you show me how your uss looks like after you chose texture from the inspector?
#Image {
background-image: resource('ButtonIdle');
}
#Image:hover {
background-image: resource('ButtonSelected');
}
this is telling me that the images are valid and found, its just not replacing them for some reason
ok it is completely different than on original button
its just a standard VisualElement im handling everything functional in the C# control for the HoverButton.cs
From what I can see on the original button, it uses ObjectFieldSelector, maybe you should try to use it to?
thats what I did tho. Its the little cirlce with the dot inside it to select from the dialog popup
hmmm
I guess I'll have to post it on the forums and hope someone sees it
I could ask vertx, who im 90% sure will have the answer but I know tagging people outside of the convo is frowned upon
yeah, probably you right, I have no more suggestions for you, sorry
vertx is somekind of guru of ui toolkit?
they are one of the community moderators on the server with a fair bit of experience on UI toolkit
roger that
Hi,
I am new to UI-toolkit. Iam currently working on a multiplayer fps game . I need help to activate a screen in the UI.
Basically I need to instantiate button in a pannel with its text equal to player name.Please help me.
hey @bleak salmon how did you find the string that also includes the fileID and guid?
I tihnk that might be what im missing but I dont know how to get that info
this one 'project://database/Assets/a.jpeg?fileID=2800000&guid=f73d2f22dc4ec0945a575121a7e421be&type=3#a'
In UI builder there is USS preview bar on the bottom of the screen
damnit, that waasnt it
I think this string is generated by some kind of builder rules. Which I don't know
yeah it probabvly is, but putting that in there doesnt work anyway
Hi, What have you tried so far?
By the way your image is in the Resources folder?
yup
It is png/jpg/jpeg textures right?
It just because I just tried with my texture and it worked
Great!
It is magic 😄
I did remove all of the inline styling and do it purely in the USS file, which is likely the solution
Yeah, I spotted that everything what was edited in inline won't be ovveriden by selector
Yeah, event if you change value from 0 to 1 then back to 0, this value won't be ovveriden. But you can right click on value name and choose Unset
yea I see now
same 😄
at least it works now xD
I made a button as a child of transparent view, loading screen, and a player list menu
You said that you need a help to activate screen in the UI. What is the "screen" in your context?
I got that. Now I need to instantiate a button with player info from photon server
I know nothing about photon server
Anybody knows hot to get rid of the white text input box which appear when trying to type in the input field. I want text directly appear in the input field instead of that white extra box.
Hi!
Is this the right place to ask about how to use the UI toolkit for editor tooling?
I'm trying to show the contents of a list that is not serializable by unity.
Question about UI Elements and I guess sprites in general. So you can rotate a UI element like so along the Z Axis. Is there anyway to do this instead?
The only non-custom way I know of is to use skinned sprites to parent the upper and lower verts of the sprite to separate bones
https://answers.unity.com/questions/1815514/how-to-skewshear-a-2d-sprite-without-perspective.html
You'd probably be looking at modifying the vertices of the VisualElement. Something like uGUI's OnPopulateMesh / FillVBO
There are some scraps in the documentation that make reference to VisualElement vertices, but nothing that gives a solid idea of where or how you could do that
Regarding non-UIToolkit uses: yes, you can do this with a shader, or some methods like I mentioned above (Though I'm not sure if there are equivalents for sprite renderers)
Hey, wanted to see if anyone knows how to do a scrolling tiled background using UI Toolkit?
I.E. I want my texture2d for my background to wrap around and I am having trouble figuring out how to get that done with UI Toolkit.
Not sure if it's doable
The only way I could see it being done is entirely manually with GenerateVisualContext, allocating your own meshes and texturing them
would using a Render Texture maybe work, I haven't tested that path out yet?
Probably would but that sounds pretty disgusting 😛
let's see if that works
Okay, looked into it and I am giving up on that... I would rather just try and fake it by loading in a copy and wrapping around... probably not the best solution, but much better than trying to figure out things that go beyond my mortal understanding. Hopefully the guys developing the ui toolkit will solve it for me in the future and I can make the change.
Maybe I'm just bad at writing Custom Inspectors, but UIE make this process stupidly easy even if everything is created via code.
Previously I had to serialise the object, create a bunch of variable in Editor script for each property and assign everything.
Now I can just bind visual elements to public properties, and the whole thing simply works.
I am trying to make a fade transitioner. I have one working with canvas but I want to move it over to ui toolkit. I don't like the idea of using both.
Anyway, how do I do this? I managed to create a document that has a black background and i want to tween the opacity (screenshot)
Sorry, I should add I mean how to get/set this value from code. I use DoTween's DOFade with canvas right now. But that works on Image.
Never mind, I got it working using a basic tweener.
How do I pass a custom UxmlAttribute in a UXMLTraits class of a C# control class? closest I got was ```cs
private TypedUxmlAttributeDescription<Texture2D> Default =
new() { name = "default-image", defaultValue = null };
Do I need to override that property and create a custom uxml attribute for this type?
Does ui-toolkit have something along the lines of bindings/viewmodels? I want to populate a UI based on data (levels, high scores for these levels and progress) and rebuilding the ui every time seems like a waste.
I found bindings in the docs but they seem to apply to UnityEditor ui and also they only apply to inputs. I want to mark levels as played for example so really what I want to do is update styles and label text based on data.
Shucks.
My fallback was UniRx. Does that sound like a terrible idea? As in, has anyone here tried that and thought "well, that was a mistake"
It'd come with some boilerplate, but I thought I could have central collections with observable properties. Then a "viewmodel" could subscribe to those and update ui elements. I think it'd look something like:
level.description.Subscribe(x => level.Q<Label>("level-description").text = x);
Which I could probably tuck away in a method.
@verbal quiver While it is pretty early on, I made a very lightweight. (keyword: lightweight), MVVM package. If you could do Issue Reporting for me, I'll let you borrow it: https://github.com/crazyjackel/redmoon-reactiveKit
I just found out that unirx is basically dead unless they pull upstream changes. So instead I made something myself using the Proxy pattern
But I am still checking out the project because I'm curious
It works very well, being built on Unirx and UI Toolkit. At least for me. It also is easy installation, because I became the goto expert at my college for Unity Packages.
I believe you 😄 I'll have a look at it tomorrow
How do I pass a custom UxmlAttribute in a UXMLTraits class of a C# control class? This doesnt appear to be valid, is this not yet implemented in UITK or am I going about this the wrong way?
private TypedUxmlAttributeDescription<Texture2D> Default =
new() { name = "default-image", defaultValue = null };
Hello. I want to create UI with the toolkit. But I need it for AR. So it needs to be in canvas to be interactable with the raycast from the controller. Can be that done?
Last I remember no. But I think you can use a render texture
Although it might have been implemented by now, who knows 😄
render texture to put UI on canvas?
https://docs.unity3d.com/Manual/UI-system-compare.html
World-space (3D) rendering : planned
Yeah. I found this: https://gist.github.com/katas94/7b220a591215efc36110860a0b1125eb
oh, cool. I'll give it a try now. Ty. I appreciate
I'm unable to use fonts in the UI Toolkit in Unity 2021.2.8f1. I've tried storing the .ttf files in the Resources directory, but that's not helping. I can select the font I want inside UI builder, but it doesn't render as anything but the default font. In the second pic you can see the font selector not previewing the fonts.
I'm not sure what's up here and haven't found anything that helps on the web, so I'd appreciate any advice.
Figured it out, you must custom define it in the USS with ```css
-unity-font-definition: none;
-unity-font: resource('NEXON Football Gothic B');
Is it just me or are the ui-toolkit docs not great?
I found more answers in the shadergraph package cache than I did in the docs
I am getting a strange error, wherein on startup, Unity was missing Background.FromSprite() and gave a startup error. I was able to solve it by just using Background.FromTexture2D instead.
Not sure why this happened, but was the most weird error I have ever seen.
this occurred after I updated visual studio unity version from 2.0.1.1 to 2.0.1.4, which is what I assuming caused the error. was weird, not sure if I could replicate the error though.
This is an incredibly common error message I get with UI Builder, and it trips on editing many elements in the UI Builder- most commonly when modifying text that displays in an element
InvalidOperationException: Collection was modified; enumeration operation may not execute.
System.Collections.Generic.List`1+Enumerator[T].MoveNextRare () (at <cdc4992cc04a4e77a24a09cd121af77b>:0)
System.Collections.Generic.List`1+Enumerator[T].MoveNext () (at <cdc4992cc04a4e77a24a09cd121af77b>:0)
UnityEngine.UIElements.UIElementsRuntimeUtility.UpdateRuntimePanels () (at <9fb9706855a847a1926259ab0baf1b3c>:0)
UnityEngine.UIElements.UIElementsRuntimeUtilityNative.UpdateRuntimePanels () (at <05a8bc2f25e84bdebc90d31147b4881d>:0)
Also, is there a way to modify existing structures in UI Builder. The label inside dropdown is, vastly ugly in many situations (Also cannot find how to even change the color when necessary)
so looking at the error, somehow a runtime panel is being added during UpdateRunTimePanels
and that's throwing off the the Enumerator
It's a bit strange that the function UpdateRunTimePanels is not thread-safe, since it is expected to run during runtime.
I did find that I can delete the label text to hide the label text from showing
but it is odd that it is not all that thread safe to cause that error (May be an issue with unity 2022). Adding a single new option on a dropdown, caused 20 errors to throw
If you want, you can try changing the code from:
foreach (BaseRuntimePanel panel in GetSortedPlayerPanels())
{
panel.Update();
}```
to
var splayers = GetSortedPlayerPanels();
lock(splayers){
foreach (BaseRuntimePanel panel in splayers)
{
panel.Update();
}
}```
(probably not the correct solution, but should stop the error)
UIElements as a package is always editable.
Unity console does not seem to want to scope to it in Visual Studio
open up the package inside your project folder system and type runtime in search, you will find the script.
Honestly, I have no clue how ui-toolkit works. Sufficiently advanced code is magic.
That's why I am loathe to touch stuff
but that should stop the error, however, it might just delay the error to somewhere else
I can only even find "Unity UI", but thought that was a different package
Toolkit is one I want to get used to, since it is more close to home being based on HTML/CSS
It is much nicer, but if you jump over to the https://portal.productboard.com/xvo8kmgtx7tkv7desh8cyaj7/tabs/49-ui-design
You discover so much is missing.
Product roadmap and feature requests. Welcome to our product portal.
Right now, in order to do a mask, I have to use a scrollview
Personally, where it is now is plentiful - if I can figure out how to get dropdown's to work (Made the options "option 1, option 2...") but they don't seem to do anything on click
are you programming the dropdowns yourself or are you borrowing code, cause I don't think dropdowns are standard?
Not even touching code yet- just UI Builder (Literally first day using UI Toolkit)
so a dropdown, would probably be a combination of a foldout and a label. You populate the foldout with buttons for selecting things.
there's a dropdown element in UI Builder...
oh, I know your problem, I think. There're some options that are editor only
check the top right three dots
and remove editor extension authoring
no wait, I don't have those
oh... it's unity version
I clicked that, and it actually added even more elements after it
UIToolkit isn't particularly stable on any version
I can believe that
yeah, I didn't know I was missing features because I am using a LTS version of Unity
I mean, I probably should upgrade my project if I need features
it shouldn't be that bad for upgrading
unity 2022's usage of .net 8 is, really helpful to me... so i have been sticking with it
Definitely, UIToolkit is built-in now, so only by updating the engine can you get new updates
yeah, built in for 2022,
just stuck here using 2020
2022.1 is working fine for me apart from this annoying one https://issuetracker.unity3d.com/issues/nullreferenceexception-is-thrown-when-removing-uitoolkit-button-from-the-hierarchy-after-removing-an-earlier-sibling where their advice is to just use 2021. Although the features I need are not there
for absolutely no reason
Do you have experience using the dropdown in 2022.1? I am having just a tiny bit of trouble getting it to actually popup the choices on click
It doesn't work for me either
I'm just waiting for them to fix it
you can interact with the keyboard in the meantime
or you can create your own dropdown
I mean, that's what I will probably end up doing (haha, 2020)
Most I am looking to self-create is a generic tool-tip (Had one working for whatever the original UI system is called)
it is odd though, that the most basic action of click activate does not run it, yet click followed by [return/enter] opens it up
WAIT, would it be possible to create a simple script that in general on click of dropdown, would trigger whatever the dropdown open command is as a temporary fix? (and make a template off that). It recognizes a click in general, as it focuses in on it
Yeah, I mean, here's my crap tooltip script https://paste.ofcode.org/W3ywSAXbHyEj4dMyvM5jDf
It would probably need improving if I wasn't using it in 2 non-important places
is how I use it
There are definitely better implementations out there
Thanks, I will consider using it.
There will likely be minor places where the code won't compile, I think one is just a the name of the uss class I use for the toolkip, I haven't checked properly, just consider it an example 😄
Imma try updating from 2022.1.b6 to 2022.1.b7 to see if that solves some issues
that would be a negatory
if I am going to make a popup element, say a menu that is not reliant on anything, do i make that as a separate ui document or is there some method like html5’s template?
Not Seperate UI Document, seperate Visual Tree Asset
UI Document = Visual Tree Asset + Styling
You can make either a template or you can use a UXML Factory to define it via code
The code one, let's you add in manipulators by default or have additional customization/styling settings
the Template is you get what you get
Ah, ok
https://pastebin.com/R2ZNvciv
Here is the Foldout which shows an example of how to build out a control.
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 works by having a toggle and a visual element container, whenever the value of the toggle changes, it changes the flex mode of the container to be flex or none. It registers those two things to the hierarchy and adds the additional settings via UXMLTraits that adds the UXMLFactory for it's settings
I just learned i can double click any label in the editor, and type replacement text for it without any errors going. Now if only changing the Name in the inspector didn’t cause it (i think it is caused by the rendering engine trying to render it with every, single, little, value, change- so two threads accessing a single variable at the same time… Is there an option to not live update and only after change?)
Howdy, all. I started up a project with the intent of trying out the UITK with the New Input System, as I saw that the former supported the latter now. I'm on a new project, 2021.2.9f1, and I've done the following:
- Created the Panel Settings for UITK.
- Switched to the New Input System in Project Settings > Player.
- Made a sample Visual Tree Asset with a button.
- Created a script which ties a callback to that button when clicked.
- Placed the Visual Tree Asset in an empty Game Object + put the script on the object.
I've got pretty much nothing else in the hierarchy, just the camera and the HUD object which contains the VTA and the script. Nevertheless, I get the following error:
InvalidOperationException: You are trying to read Input using the UnityEngine.Input class, but you have switched active Input handling to Input System package in Player Settings.
UnityEngine.UIElements.DefaultEventSystem+Input.GetAxisRaw (System.String axis) (at <40001ab788e241b094dbea03f2ab96e8>:0)
UnityEngine.UIElements.DefaultEventSystem.GetRawMoveVector () (at <40001ab788e241b094dbea03f2ab96e8>:0)
UnityEngine.UIElements.DefaultEventSystem.ShouldSendMoveFromInput () (at <40001ab788e241b094dbea03f2ab96e8>:0)
UnityEngine.UIElements.DefaultEventSystem.SendInputEvents () (at <40001ab788e241b094dbea03f2ab96e8>:0)
UnityEngine.UIElements.DefaultEventSystem.Update (UnityEngine.UIElements.DefaultEventSystem+UpdateMode updateMode) (at <40001ab788e241b094dbea03f2ab96e8>:0)
UnityEngine.UIElements.UIElementsRuntimeUtility.UpdateRuntimePanels () (at <40001ab788e241b094dbea03f2ab96e8>:0)
UnityEngine.UIElements.UIElementsRuntimeUtilityNative.UpdateRuntimePanels () (at <022e0d17f3324664894729afe55099b0>:0)
This is similar to other errors on the first line, and I've looked through them, but none seem to be related explicitly to the UITK. Do I need to add some kind of event handler or something?
in project settings, check for input to switch over - ui needs to switch to support the new mouse inputs
I'm not exactly sure what you mean: in the Project Settings, under the Input Manager tab? Or the Player Tab? I've switched my Active Input Handling over to the Input System Package (New) in the Player Tab.
Find the EventSystem in your scene and make sure it has been switched.
Ah, one wasn't created --- I thought that was only for the old UI system? Should I create one if it doesn't exist?
Yes
It seems to be okay with everything --- but I'm not exactly sure what I'm looking for, to see if it's switched.
That's weird, it should be prompting you to switch
delete that one, and try and spawn one in via adding a temporary canvas?
it should be using the InputSystemUIInputModule instead of the Standalone one, but it was a click of a button on that interface to switch mine for me
I get the same thing attempting the temp canvas thing. No prompt. Hm. I can try to make a new project, make an event system thing first, and see if that works out better, maybe.
Oh, maybe I can just add the component then?
this is what it would be looking like if it worked right :/
That'd certainly be sweet to have. Haha, lemme try with a new project, I'll make an event system right away.
try removing and re-adding the new input system, switch player active input setting?
Yeah, nothing, totally new project, tried toggling new input on and off, canvas-created event system and otherwise. Okay, but at least I know what I can google now. Lemme look around a bit and see why this "Replace with InputSystemUIInputModule" isn't coming up.
Though, actually, this should have been fixed after the alphas. So, I dunno actually. But this does seem to be my issue.
have you tried a LTS version of Unity? (only time i’ve used the new input system was in those)
2020.3.28F1 is the newest marked one atm
Solution to my above problem: The version of the the Input System packaged with 2021.2.9f1 is 1.2.0. The earliest package which works with the UITK seems to be 1.3.0, which does not appear yet in the package manager, but can be added via "Package Name" with com.unity.inputsystem and version 1.3.0.
This seems to give Unity a kick and allows the EventSystem thing to pop up. A pretty silly thing to miss, but at least it's really easy to fix.
ah, nice - but odd miss most certainly
Yeah, kind of strange --- I didn't see anyone say this before in the forums. I wonder if I'm just on one of the weird versions that didn't put it to 1.3.0 automatically. Who knows.
Either way, thanks for your help, y'all!
None of the 3 settings elements added will show, unless I manually re-add the 3 style changes (position & left/top) (pp = post processing)
private void Start() {
root = GetComponent<UIDocument>().rootVisualElement;
micButton = root.Q<Button>("MicSettings_Button");
avatarButton = root.Q<Button>("AvatarSettings_Button");
ppButton = root.Q<Button>("PostProcess_Button");
micButton.RegisterCallback<ClickEvent>(ev => PressMic());
avatarButton.RegisterCallback<ClickEvent>(ev => PressAvatar());
ppButton.RegisterCallback<ClickEvent>(ev => PressPP());
micSettings = micSettingsTemplate.CloneTree();
avatarSettings = avatarSettingsTemplate.CloneTree();
ppSettings = ppSettingsTemplate.CloneTree();
}
private void Update() {
if (!hasFlipped) {
hasFlipped = true;
root.Add(micSettings);
root.Add(avatarSettings);
root.Add(ppSettings);
micSettings.style.position = Position.Absolute;
micSettings.style.left = new StyleLength(new Length(400, LengthUnit.Pixel));
micSettings.style.top = new StyleLength(new Length(400, LengthUnit.Pixel));
}
}
How do i make it if i hold my mouse and hover it to my left button it clicks it
I don't know the keyword for this specific thing so please help
Basically if i hold and hover to the next button it will trigger the button hovered
Like a slider but with 2 buttons
So… the idea is to have it so that while you are hovering over the thing does a thing. You can use visualElement.RegisterCallback<PointerEnterEvent>(callback); to register an event that occurs when you first put the pointer over and do the same for PointExitEvent.
And that callback can start a Coroutine or something that you cancel when you exit. Wherein you call some updoot function.
Hello everyone,
I'm thinking of learning a gui framework something like maui / noesis gui / unity ui element..
which one would you pick & why?
I'm thinking of noesis gui because it's cross platform and support vs design also vector rendering. also true native towards gamedevs ,
but maui has more functionality like native api using .net5 BCL also akain to blazor binding it could intergrate with blazor but require asp core and some background in razor .
I think no doubt unity element is necessary for GUI and extensions development .
Does anyone have some material on doing but more fancy stuff with UI toolkit, as Foldout right, instead of folding out towards bottom. Or any tutorials and etc. As for Now I can only find things like basic tutorials, but cant find more specific data there.
or things like how to add animation of foldout and etc
masks & animate properties
you can get the foldout to foldout right through style sheets.
Does anyone know if it is possible to use the Dark Editor Theme for UI Toolkit (outside of just the editor- so that it shows up that way in game)
whatever it is using for the base text and ui looks real nice and clean - besides the fact that sliders are broke
i am also not able to modify the USS for base controls (like .unity-base-field_input)
strange, in my version, I am able to quite easily. Like that is the whole purpose. Check that you don't have [control-name]:active or [control-name]:focus overriding in the debugger
none of that in my USS. When I hover over the selector in the builder, it doesn’t even highlight the elements associated with the class name
I don't know, seems like something that I would need to be in the driver's seat to debug
you can try adding your own custom-selector and then doing subselections
like .myFoldout > #content
can’t modify the children of template based classes (built in ui tools like dropbox or toggle) to add my own class selectors :/ which is why I am trying to modify existing ones
.RootWindow {
background-color: rgb(38, 38, 38);
border-left-width: 2px;
border-right-width: 2px;
border-top-width: 2px;
border-bottom-width: 2px;
border-top-left-radius: 4px;
border-bottom-left-radius: 4px;
border-top-right-radius: 4px;
border-bottom-right-radius: 4px;
color: rgb(163, 194, 214);
border-left-color: rgb(72, 72, 72);
border-right-color: rgb(72, 72, 72);
border-top-color: rgb(72, 72, 72);
border-bottom-color: rgb(72, 72, 72);
}
.unity-label, .unity-text-element {
color: rgb(163, 194, 214);
}
.unity-base-field_input, .unity-toggle_input {
background-color: rgb(72, 0, 0);
}
label and text element work fine too (which makes it kind of more odd)
one thing I would like if unity added would be something like sass.
Something like preprocessing for style-sheets.
Would be nice- but that is a long ways away from what I can tell
with similar syntax and all
heck, I bet you, I could build that, in say, three weeks, if I wasn't busy with other things.
since, we have ui toolkit source and all
and then they rewrite half that base of USS XD
yeah... I hate supporting Unity as it is rarely stable on anything
what I would probably do is rewrite a subsection of PanelSettings that applies all the preprocessor defines. And then the PanelSettings would serialize them all out so you can set it on Panel.
and within the builder, I would just add a new window with those settings.
something like that seems like a good place to start figuring it out, but hey, might be a bad idea
make it 6 weeks
The more important thing I would force in a fix, is that the prebuilt tools are imported as optionally either template or fresh (template, you can't modify the children- but "fresh" would be as if you set it up all yourself and have fully GUI control of it)
no way to modify the children of toggle for me in my version of Unity, where even the USS selectors just flat out fail
anyway, I am going on roadmap page and putting out an Sass precompile equivalent suggestion for UI.
GL. It is a smart thing to add, SASS makes a ton of work simplified
or I guess, it may be SUSS for Unity xD
Syntactical Unity Style Sheets
SyntacticallyAwesome
Unity
Style
Sheets
I am hoping they keep the SUSS for the meme if they do make it, because it would be hilarious.
idk, sauss sounds kinda suss too
SAUSS isn't bad either
sometimes, you just gotta pour on a little SAUSS to your game
Haha, I really hope someone at Unity is listening to this conversation, because it is actually a real nice feature.
all your talks sounds SUS to me >.>
How to edit premade buttons. For example i can add Radio button, but I want to change #unity-checkmark, but it is grayout and I cant change anything or change style at all.
And same goes with every single premade thing. only button is customisable as it dont have enything inside
Anyone have examples scenes or UI examples for tool kit? I kinda too lazy to code everything from scratch 😄
I guess manually adding
.unity-radio-button__checkmark {
//stuff to change
}```
works, but it isnt very nice 😄
but that doesnt let me have unique radio button, for example have a bit different from others >.>
use the # followed by sub-component name 🤦♂️ i only just realized it. I’ve been trying to call the classes in USS this whole time (which logically should work - but don’t, or at least for my version of Unity it doesn’t still)
I will try, thank you
well it works, how to indentity more precisely. For example have two sliders:
#unity-dragger which name I cannot change, and cant change class. Only thing I can change is like parent.parent.parent name 😄
as changing this ID parameters literally changes all UNITY sliders for me :DDDDDDDD
when you change 1️⃣ but end up changing all unity UI builder style :DDDDD
nwm found out 😄
same as in css
just write parent name next to child name 😄 but it is pretty cool i can change my unity editor style now
yeah, it’s a bit of a pain but it’s nice as you get more used to it. Sadly, it’s still very well in early development after 2 years (mine has so many issues, for unity 2022.1.b6)
If you want to modify the dragger for a single element you should use one of the complex selectors https://docs.unity3d.com/Manual/UIE-USS-Selectors-Complex.html
but it is till better than default unity UI 😄 I am loving it 😄
Add a class to the root element and then target a descendant with the name or a class
Thank you, found that by experimenting 😄
Are the pre-fixes necessary when manually writing the uxml? I’ve seen some prefixed with VisualElement:, united prefixes them all with ui:, and unity docs show no prefix…
<Label />
<ui:Label />
https://docs.unity3d.com/Manual/UIE-WritingUXMLTemplate.html you can read an overview of the requirements here
Yeah, that's where I saw it without the ui prefix's, and I wasn't sure if either or were out of date or something. Just makes it look even more odd compared to what Unity auto-generates with UI Builder
when a slider is draged whihc sub class is on? Active? selected? as hover dont work as I expected
as debuger states tehre is no Pseudo classes when draging
One more question, how is UI toolkit handles Japanese and chinese symbols. As I gues it uses text mesh pro, and for example in webgl you need a lot of work to have nice text with text mesh pro.
that a lot of work is create FontAsset, which is not friendly if you missing some kanji\
and it dont let me chenge Inter-Reugal SDF (FontAsset)
things like this happens.
one is more bold than another. Tried different fonts, same problem. any tips?
I'm trying to write a custom ui element. Basically something I'm calling "EnhancedList" based on Odin's list drawer: https://odininspector.com/attributes/list-drawer-settings-attribute
Customize the behavior for lists and arrays in the inspector.
Finding the sparse docs and simple examples lacking in guidance for what I'm trying to do.
Seems like I'm supposed to override the create method in the factory to build the more complex list view. (No example I've found does this 🤷♂️ ), but it seems to work in UI Builder.
Also I'm inheriting from ListView to try to get all its attributes to start, but they're not showing up 🤔
Examples: https://github.com/plyoung/UIElements
this shows some examples of custom ui elements
alternatively, you can look at internal implementations like foldout: https://pastebin.com/R2ZNvciv
They are implemented in the same way as you would impliment
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.
ahh ok, so I'm not supposed to build the hierarchy in factory
very helpful. thank you.
Make something simple, then make some more complex, then make the thing you want... that's how I end up learning systems, so that's what I recommend.
is there a setting somewhere that I am missing, to disable arrow keys from moving across visual element inputs?
?
if i enter an input (text box for example), arrow keys will start moving between others as if it were tab
I don't know. I am not sure, but probably is connected to the Input System so as to allow for easy non-mouse gameplay with UI
Controllers and the like.
i’m fine with keeping tab key for that, but arrow keys could be useful to reclaim as functional keys (i’m making software, not game)
If you doing it with Unity's New Input System, maybe check out the input module and just don't set something
i haven’t even switched it over to new unity input system 😅 (i like it, but getting inputs can be a b’ sometimes; compared to dropping a Input.KeyPress sometimes - but i probably should)
There is a way to do that with the new Unity Input System if you build out a container, but in general, it leads into bad code...
Personally, I like Using Unirx observer streams for everything as there is a lot of small changes you can quickly change to make it easy.
nywy, I g2g and do some demo on my game: https://crazyjackel.github.io/SF/Builds/Alpha/0.0.4/
I built it entirely in the UI with UI Toolkit. And then it breaks everytime I do a build of it... haha
At least a webGL build
sounds like fun 🙂 😅
it's a concept for a trippy 2D rubix cube. I have a level builder and anything, though I can't really show that off, because I don't have a level select yet.
luckily, this is just a school project
all I have so far after 2 days since starting fresh on my project are - instantiating a properties panel, and transform controls (pos/rot/scale)
yeah, this has been around 3 weeks of development so far... but on a part time basis
and it technically is a group project, but... the team is 3 artists
and me
all of them know how to code, but actively avoid it most of the time.
i know that feeling - except i usually got stuck without anyone wanting to do anything and then just me dropping the entire project a month later (not school, that stuffs too expensive 4 me)
I really hate working with my fellow college students on projects, just because around 90% of them don't program in their off-time, so they haven't developed out the sense for coding the 'correct way' (pre-style)
the 'correct way' refers to actively thinking about how you are coding while you are coding
and is mostly about learning tons of patterns
there is no "correct way" to style your code, but there is a 'correct way' to code.
a right way to stylize and format code, but not exactly a wrong way to lay it out?
what I am talking about is that they don't think about how to interact with their own code
So, a lot of them end up using 1-time hacks that brings things to a crawl
and would've been avoided if they thought it through as they coded
the 'correct way' to code is to code with the expectation that someone is going to read it
and use it
and change it
ah, yeah. That seems to be a very common problem - along with code anticipation, potential methods to add ahead of time.
it is a common problem... but a couple minutes of thinking through hypotheticals results in code that is easy to upgrade and maintain.
but your also in school - minimum work for passing grade
The classes that tend to work out the best are the graduate level ones wherein everyone tries one-up-man-shipping
I think, in general, at a certain point, you can't be taught programming as much as you just have to experience it
nywy g2g 4real
I was working with the ui builder in the past and I was able to reference sprites/textures directly for setting a background image of a visual element. Now it seems to break my uxml file. I noticed if I put the sprite into resources it works. So is this the only way to use sprites in the UI now? or is something broken for me? Or can I only change sprites at runtime?
Hey, is there any way to use the new input system with the ui toolkit. I tried putting the ui into my project but it gets an error with the You are trying to read Input using the UnityEngine.Input class, but you have switched active Input handling to Input System package in Player Settings.. I was wondering if there is any way to get them to work together yet.
Is there a way to check for specific style of visual element through name?
So let's say I have empty class .label-autosizable
Which I want to use as tag. Now I want to find all labels with this class and only with this class.
How can I check do it?
var query = this.Query<Label>(className: "label-gamescreen");
query.Build();
autoSizedLabels = query.ToList().ToArray();
yepp, took some time to figure out
hmm
any idea why I can't put TextMeshPro font asset into Label FontAsset property?
it's just empty
and I can't drag SDF file as well
you mean TMP font asset won't work?
Is there a way to define custom variables to USS Class?
Basically I want to have Text class that will have 2 custom properties
width and height relative size, so my custom containers will auto adjust all elements text font size depending on those 2
and I don't want to define custom Label Visual Element for it
Hey there, i have weird problem that scroll rect of built in ui canvas, breaks when scrolling down, just on android.
more info here(i opened post there yesterday)
https://forum.unity.com/threads/scroll-view-rect-breaks-on-android.1242772/
i suspect it might be some bug in version of unity that i updated to(2021.2.11f1) because it didnt happen before, but maybe there is known solution
if anyone has idea, that will be cool 🙂
by the way, idk where I should report this, as it is insignificant , but still an error in Documentation.
You can report issues with documentation at the bottom of the page
ty
TeleportListView.makeItem = () => {
Debug.Log("NewUI FillTeleportList. Making items");
// Instantiate the UXML template for the entry
var newListEntry = m_ListEntryTemplate.Instantiate();
}
is logic if we want to add data to ListViewObject, but what should be if I just want to add to ScrollView element? is there any special function for it?
Well there is .Add(newListEntry ), but that wont do all other functions as setting values and etc.
TeleportList.Add = () => {
}```
I wanted to make horizontal ListView, but was not able to make it look pretty, like disable the scroll bars and etc. And selection editing was challenging. so simpler ScrollView as enough for me. Unless there are some tips on handling it?
Hello! In the Unity UI, in the Image settings, there was such an item "Pixel Per Unit Multiplie". It allowed the Sprite to be scaled in "Sliced" mode. Is there something similar in UI Builder? I've now selected the background of a VisualElement and can't adjust the scale of a sprite that has "slice" margins set.
Um... There is no answer on this page. It says here that there is support for 9-slicing in sprites. However, a sprite cut in this way cannot be scaled in the 2D Sprite Editor, as it was possible in the Unity UI with the "Pixel Per Unit Multiplie" option.
As a result, the entire area of the VisualElement is occupied by the corners of a large sprite, since the sprite itself has dimensions of about 1400 pixels.
Here's what the sprite looks like in the VisualElement in the background. This is what a sprite looks like in the sprite editor with 9-slice enabled. How to fix it?
VerticalScroller = rootVisualElement.Q<Scroller>("unity-slider");
So I know that there are two Scrollers in root visual element, how do I select second one? I cannot change the names because they are grayout as it is ScrollView element.
you can get the horizontal or vertical ones using their class
or you can use .Query to build a more advanced query
HorizontalScroller = rootVisualElement.Q<Scroller>("unity-slider", "unity-base-slider--horizontal"); something like this?
Just use the classes provided by the ScrollView so you're not hard coding things unnecessarily
ohhhm thank you <3, missunderstood:)
But yes, if the name is "unity-slider" that should work
Also the ScrollView itself contains references to its Scrollers
any tips how should I approach idea that I want to scroll to selected element. Besides using proportions? Aka if selected item is 3rd in the list, I should scroll 1/3 of max value?
thank you ^^ I learned a lot
Another question. It about events.
CarouselItem.RegisterCallback<ClickEvent>(ev => SelectItem()); this is most generic way to create a button press. And I understand how it works inside class. But what happens if I want to have this script in a class which is not monobehavior, and is assigned to Visual element?
To explain more:
Parent class -> ScrollList
Child class -> ListElement
It is initialized during runtime. Visual class elements are generated and assigned with ListElement class, so I could change values inside from parent Element. So when going from up to down in a tree it is simple, but what happens if I want to register event callback on that button to run function in Parent class.
A) should I assign those buttons on Parent class (SCroll list) when I am initiating them?
B) there is a a global access to events registered in any of classes?
C) I can somohow access parent class function from child class.
In object programing I would just take parent gameobject and access script, but with UI builder I am not sure about best method
As I want to on button click get data from that button.
In List view I could get it just by getting selected parameter, but inScrollView that is not an option, so I am trying to return the Visual Element of the button. I tohught ev.target or ev.currentTarget will work, but I missunderstood it.
This setting does not scale. A clips and distorts an existing sprite. In your screen recordings, you can see that in the first case, the corners and side edges are scaled, and in the second case (with a change in the Slice parameter) they are cut off and distorted.
For example, when setting the value to "1" of the "Slice" parameter, something normal is obtained, but 9-slice no longer works and the sprite is completely distorted.
And if you set "10", then the sprite is distorted. And the 9-slice mode doesn't work either.
For an example of how it works in Unity UI. This is what I want to achieve from the UI Toolkit.
// Instantiate the UXML template for the entry
var newListEntry = m_ListEntryTemplate.Instantiate();
// Instantiate a controller for the data
var newListEntryLogic = new CharacterListEntryController();
// Assign the controller script to the visual element
newListEntry.userData = newListEntryLogic;
what is the difference between this and Binding?
Or is it binding can bind monobehaviours and game objects, and userData just adds Class to the UI element??
Hey, I'm looking for a simple 'hello world' reference project to get me started with UI Toolkit.
I tried this: https://github.com/Unity-Technologies/UIToolkitUnityRoyaleRuntimeDemo/tree/unity2021.2-update
But half the scripts don't compile, and the materials are all pink. Fixing it has taken me 2 hours and gotten me nowhere so far, and all I need is a quick and simple reference for the UI toolkit lol.
how to make this text better to fit in camera without problems?
I would need to make it all a lot bigger, and with Font Size 1 it isn't visible
Don't crosspost.
Use TextMeshPro, not the Text component.
If you want to see it on the screen space, use a Screenspace Canvas and a TextMeshPro UI object.
Thanks
Hello there. I have a question about a prefab being instantiated inside a grid list (in a canvas). Whenever I change my resolution of the game, the prefab keeps the old size and appears bigger or smaller. Usually I solve these type of problems by setting the rect transform to inherit the parent's size and stay relative to that one. But the Grid view does automatically set the orientation point to left bottom. So I cannot overwrite it with the "strech" option. How do you solve/bypass this?
EDIT: Nvm, I added code that sets the localscale after instantiation to 1,1,1 . For me, that does the job
Hello guys I'm looking for good tutorial for this Amazing UI Toolkit.
I didn't succed to make a pop up display with a bouncing animation.
And now I am looking for customizing radiobutton like an abilty bar where you can select only one ability.
Do you know where I can have these information ??
@twin salmon Well you are looking for radio button group. Where you give option that it selects only one. Sadly tehre is not a lot of recourses, and toolkit documentation is pretty much main one 😄
private void SelectTeleportTarget(ClickEvent evt) {
// Only perform this action at the target, not in a parent
if (evt.propagationPhase != PropagationPhase.AtTarget)
return;
// Assign a random new color
var targetBox = evt.target as Button;
TeleportList.IndexOf(targetBox.parent);
Debug.Log("SelectTeleportTarget " + targetBox.parent.name + "and index of that element is " + TeleportList.IndexOf(targetBox.parent)); // correct name but incorrect index
ScrollToSelected(targetBox.parent);
}
so what I am doing wrong?
I fill scroll view with templates that is:
VisualElement->ChildButton
And on button press I get the correct data of visual element and button, but I cannot get the correct index of that element in scrollview. I get index of -1, which means that object does not exist in TeleportList scroll view object.
Or how Should I know which ScrollList element triggered the event?
Yeah I don't succeed to change the pictures of the radiobutton and add a selected pictures too :/
Yup, I am in same situation. So in the end I just made buttons and wrote custom code for that X.x The only way currently is I uess rewriting radio buttons and other stuff in code only. You can change background images if you are creating custom selector on UI toolkit window, aka #parentclass_name #yourradiobuttonname and then change everything inside
You can rewrite UI élément from scratch ?
Yes, there are multiple ways of doing it. It just doing that from scratch takes time 😄
How can I set mousewheel scrolling speed of ListView? I tried changing verticalPageSize and --unity-metrics-single_line-height: 500px, but none of them seems to work in Unity 2021.2.11f1
official answer from Unity developers on scaling 9-slicing sprite (maybe it will be useful for someone)
Hello, we have a fix in the 2022.2 branch that takes the "pixels per unit" value into account. We also added a "-unity-slice-scale" style to modify it on a per-element basis. Unfortunately, this cannot be backbported to earlier Unity versions.
How do I do keyboard navigation in UI Toolkit? I want to be able to navigate through buttons and form elements with arrow keys and/or tab key.
From what I have seen it is possible to do only through code currently, as there might be some problems with it 😄
the canvas has a raycaster?
Yes, it's called a Graphics Raycaster
How to register button click callbakc which would run on another script? Aka would be able to be seen on parent script?
Or I must use qurry and create those events on Parent script?
Maybe I'm overlooking it, but is there a way in the Unity editor to see the visualelements / buttons that are currently in the "DOM" (not sure if this is the correct term for this)?
For example, I'm adding a bunch of buttons to a particular VisualElement via a script at runtime, and it would be nice if I could check to see if they're all there. I looked at the Unity debug mode for the inspector, and nothing popped out at me ---
EDIT: In case anyone searches for this: I was overlooking it. It's in Window > UI Toolkit > Debugger. You can "Pick Element" and it works perfectly. Exactly what I needed.
lol I was asking Ender
really stupid question, how change property from CreateInspectorGUI()?
I mean not change UI values with values from script, but change parameters in script from UI. When UI is created is just by putting Binding Path, but when I create Ui from C# code, I am not sure how to do it. it must be super simple..
in property GUI it is just " CreatePropertyGUI(SerializedProperty property)" but in InspectorGUI i dont know how 😦
so like, swapping out objects with a ui inputsystem module just breaks input entirely, im assuming i need to have a single constantly active ui object and swap the ui document's root asset?
I was following this tutorial. Everything works, but I am keep getting You are trying to create a MonoBehaviour using the 'new' keyword. This is not allowed. MonoBehaviours can only be added using AddComponent(). Alternatively, your script can inherit from ScriptableObject or no base class at all
Any ideas why? or should I ignore it?
var newListEntry = m_ListEntryTemplate.Instantiate();
// Instantiate a controller for the data
var newListEntryLogic = new CharacterListEntryController();
// Assign the controller script to the visual element
newListEntry.userData = newListEntryLogic;
// Initialize the controller script
newListEntryLogic.SetVisualElement(newListEntry);
it comes from here
Only difference as I am not using ListView, but scroll view, so I dont have m_CharacterList.makeItem = () => call. But besides that everything is same
You probably made CharacterListEntryController inherit from MonoBehaviour. Check the tutorial if they did the same.
https://docs.unity3d.com/2021.2/Documentation/Manual/UIE-HowTo-CreateRuntimeUI.html
As using this example, is it possible in CharacterListEntryController.cs create an event like Button.RegisterCallback<ClickEvent>(SomeFunction), but that event function would get triggered in CharacterListController.cs? Or it is a must to register callback there?
As it is convienient to have logic in smaller function which handles all UI changes, but when it comes to values changes, it is more convienent to handle it in bigger controler
I'm showing a sprite that is using the image grayscale for alpha. However, the antialiasing appears to be against black rather than against the background. Any idea why?
I'm creating a dropdown menu and I need the default option to be the third one, how can I do this without scripting?
@summer moth how did you make the texture?
More than likely it's a premultiply issur
Just in photoshop. Where would I mess with pre multiply stuff?
ah, photoshop doesn't make it easy. Its best to fill further out from the alpha. I'll send an example
What does the image look like? if you don't mind posting
Huh, that’s interesting, I thought I’d made sure that wouldn’t happen but it goes really make sense that would be it. Thanks!
Do I need to import something to get the tooltips for the ui builder to work correctly? I can hover over the controls in the ui builder and rather than getting an informative tooltip I instead get the name of the parent control
is there a way to call RegisterCallback fro another class which odes not have game object, aka is mounted ad userdata on another UI object?
Does w_MainMenuSubMenu.ToggleInClassList("submenu-style-hidden"); not trigger transitions?
How to disable selected feature in ListView ?
How can I add runtime generated buttons to focus ring navigation?
This is how it looks in UI builder.
and this is how it looks at game.
Resolution is the same. But it looks incorrect
any tips?
Anyone know how to get Resolution of current visual element? as it sales depending on screen size, so I would like to get current one of specific visual element.
This is definitely a UI rendering scaling and object placement issue. The scale is the same, but the second image represents an alignment change, it seems. There's less padding / spacing on the right side of the, 'Off', text. Honestly, to avoid this ever happening I might cheat and make the little bar around 50% wider so the text wasn't quite as close to the edges. But even that wouldn't be complete. I'd additionally split the text into two parts - one aligned to the left side and one to the right.
Do I have any control over the layering in UI Toolkit? I am using visual elements as containers
Here is my hierarchy:
Root Visual element
|
--Top Visual Element (container)
|
----Menu Button
|
|
--Middle Visual Element (container)
|
|
--Bottom Visual Element (container)
When the menu button is clicked, a dropdown appears that is located in the top visual element, but it expands down into the middle visual element. This works.
However, when i attempt to click a button on the drop down, it does not work. seemingly because it is located in the top visual element and the middle visual element is receive the click.
I'd like this dropdown menu to go to a higher layer so that it can receive mouse clicks before the middle visual element container.
It is actually two label elements with this aligments, Middle vertical and to edges on horizontal.
versus Intended. The difference is small but I can see it just like previous posted On/Off slider.,
Hello there, is there a way to get pen pressure when using UIElements? I have a method that is executed on mouse move and upon checking the available properties within MouseMoveEvent class I couldn't see anything related to pen. Is it currently not possible to acquire such info, or am I looking in the wrong place? Also, I am using Unity 2021.2.1
Hi, my button is not reacting on click, seen in the image, i used both methods to assign Click Event but when clicking ingame, the callback does not get fired
(of course i tried each method individually before, so RegisterCallback and the way assigning via += Operators, refering to line 38 and 39)
ello does aynone know any good inventory tutorials
You have your input system and event system on your UI element In Unity right?
Hey there,
I have a Problem with UI Builder. I try to make an editor window which allows me to create custom hex grids. For that i made an editor window which has a custom control for displaying a grid. It works fine as long as I am working in the UI Builder, but as soon as I hit save i get the error: Element 'UnityEngine.UIElements.HexSelection' has no registered factory method.
In Builder:
After save:
Here is the Code for the custom control
Any ideas how to implement Input with Japanese symbols on WebGL?
as in it to support Japanese input. similary as this plugin did.
https://github.com/kou-yeung/WebGLInput
Or is it possible to make Input field work just like if it would be game object?
Hi, thank you for looking into my question✌️ I have the ui document, inside i have the elements like images and the Button, and then in the code i connect the button to "EXC_btn_exitGame" object and then try to assign the click event. Is that what you mean maybe?
I am talking about these things. As without them the events will not get trigered and you code will not run
Hi, i´m currently trying to do a healthbar with the progress bar element and i encountered a problem. I can´t change the color of the progress bar and background, because i cant change the values in the inspector. Does anyone of you guys know how to do it?
@rain pecan can you post the inspector view too please, i mean the place where you would want to change the color
@winged oak
thanks, let me check
is there any code connected to this already? Maybe some enable/disable functionality? As i have not seen these items on the left beeing greyed out before, they look like "disabled"
i would probably go and manually check the uxml code of uidocument, see if you can find any hint there on why these are disabled
ok i´ll try that
no, i didn´t implement code yet
ok then check the uidocs xml, if not sure what to look for, paste it on pastebin and send me the link
wait where is this file?
i found the uss file but not the uidocs
Should be looking like this and it .uxml file ending:
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.
@rain pecan
Try replacing the full content of you uidocument, with the one pasted here: https://pastebin.com/raw/fFFdqcpF
This is the same, but i have changed some character encoding. If that works now, then congrats, you found a bug in ui toolkit : )
i will go for a smoke, brb in 5 mins
unfortunately it doesn´t work, it just lets all the items disappear, but i just found a way to edit it. Thank you for your help!
well it was worth a try. Did you manage to get the items enabled with your editings then?
no, but i can just change the style with a stylesheet( i tried it before but i used the wrong name, because there were two _ instead of one in the name)
oh ok, well if anyone comes past here and knows how to enable them again, i would be interested in the solution too. Nice you found a workaround 👍
Hi there. You can fix this in two ways:
- create correct selector. In your case, you would need to name your progress bar name in any name or give it any custom class. then create new selector.
#ProgressBarNameyouneedtoadd .elementyouwanttochange class
This will let you to change that element class. Because otherwise you would change your Unity visual elements :DDDD
This is how you find the names: Window -> UItoolkit -> debuger. press Pick element. Then press on element you want to inspect.
so what you need would be:
#ProgressBarNameyouneedtoadd .unity-progress-bar__background
with this elector you can change color of background
#ProgressBarNameyouneedtoadd .unity-progress-bar__progress is forthe loading part
- second way to do everything thourgh C# code.
get your ProgressBar element by querry, and then in code you can change colors of each element
Thanks!
Do we know why FloatField and IntField are editor only...?
anyone know how i could setup a custom UxmlAttributeDescription with a list of strings? When I try to it always shows an empty string field.
If I mimic the enum version it doesn't work. I was trying to use some other methods to try and make it show but doesn't want to
even better would be an object field if that is even possible
They're not in 2022
Yeah I know, I am asking why though
Because they didn't make a runtime version until then
Also it turns out for no apparent reason you can't create a field that derives from the base like TextField does (or FloatField)
Do you mean they are in 2022?
To be clear in case you misinterpreted, yes
They also have vector fields, etc
Oh and they made the constructor protected instead of internal
Woot!
Thank you very much
It's still very early days which is sad seeing as it has been ages
Is it possible to delete a thread I may or may not have created on the forums by change...? lol
Early how?