Search Unity

Unity UI Toolkit 1.0-preview available

Discussion in 'UI Toolkit' started by benoitd_unity, Jul 8, 2020.

  1. Chris-Trueman

    Chris-Trueman

    Joined:
    Oct 10, 2014
    Posts:
    1,006
    I really like the new UI for its separation from the MonoBehaviour eco system, give us more flexibility.

    Using UIBuilder to build your UI de-clutters the heirarchy for complex UI's. I have a UI heavy game that would have been easier to create with a hell of a lot less clutter.

    I've already got a working solitaire game that is completely done with UITK, even with the minimal drag and drop functionality at runtime.

    One thing I don't like is the fact that I can change parents but I cannot keep the current root/world position of an element, all positioning is relative to the parent. Which is something I find a bit confusing. Position can be relative or absolute. Both of which are relative to the parent. Which means both are relative, absolute merely removes that element from being included in the layout. There is no way to set an actual absolute position that would be local to the root/world and not the parent.

    I think you guys are headed in the right direction. Waiting on Input System support so I can replace uGUI in another project I have.

    Some questions in regards to complexity. How well does uxml handle nesting? If I create the entire UI in one uxml file showing and hiding each part, how well will it perform? Is it better to use separate UIDocuments for each part?
     
    Tanner555 likes this.
  2. benoitd_unity

    benoitd_unity

    Unity Technologies

    Joined:
    Jan 2, 2018
    Posts:
    262
    Could you describe the scenario in which you are changing the parents and would like the behaviour to be different? Is it when you are authoring and you're re-parenting?

    We recommend having as much of your UI defined in UXML/VisualTree to fully benefit of the system and workflow optimizations of UI Toolkit. That being said, if your project has lot of UI, having all of it into one single UXML might not be optimal. It might take a longer time to instantiate, it will be complex to work with it in the UI Builder and you'll miss opportunities to make reusable parts.

    You could still break it down into logical UXML parts and use a single UIDocument in the scene, but load them and attach them under it, at different points in your game. You have some flexibility.
     
  3. benoitd_unity

    benoitd_unity

    Unity Technologies

    Joined:
    Jan 2, 2018
    Posts:
    262
    Hey Baste. You're referring to Unity Feedback I believe. Issue Tracker is still operational.
    So good to hear. Let us know how that goes.
    I hear you. Collaboration is an area in which we are investing and should receive significant improvements in the future, for both small teams (Collaborate), as well as larger ones. Stay tuned!
     
    GliderGuy likes this.
  4. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    5,453
    I think you should shut it down, not improve it.

    One of absolutely vital features a VCS must have when working with Unity is to be a different process than the Unity process, in an independent window. You have to have that to recover from the project being in a broken state that prevents Unity from opening. Having the VCS embedded in the Unity process is suicide for your project.

    So even if you fix it being bad (no features, randomly lose file changes every time I've tested it in a game jam), it's still fundamentally a bad idea as the core selling point is a negative.

    Yup!
     
    loptrinho likes this.
  5. Chris-Trueman

    Chris-Trueman

    Joined:
    Oct 10, 2014
    Posts:
    1,006
    In my solitaire game, I am parenting the cards to position on the play area during game play. Since the cards can be moved around and put in different positions they change parents often. When I start to drag the card(s) the parent changes to the drag area, this is where it may shift its initial position and be relative to the drag area using the previous parents position putting it in the top left corner of the screen. A frame later and it moves back where it should be with the mouse. If I did a drag and drop inventory this is the same type of behavior I would use. Maybe this is the wrong approach with UITK? t's a minor bug that might have to do with how I am moving the card(s).

    I was going to have each component its own separate uxml so it was easier to work on them. Then add them to the main uxml file in UIBuilder. I think it would be better to load them in individually and then add them under the singular UIDocument, this way it could instantiate the main uxml faster and then load in each part as needed.
     
  6. benoitd_unity

    benoitd_unity

    Unity Technologies

    Joined:
    Jan 2, 2018
    Posts:
    262
    I'll make sure the team is aware of it.
     
  7. MousePods

    MousePods

    Joined:
    Jul 19, 2012
    Posts:
    283
    Even if this one user dislikes the feature, there are many others who love it. Please don’t take this one experience as the only experience.

    Collab is an amazing feature and has allowed me to work with an artist who would have a hard time otherwise.

    There have been some issues, but for us, collab has been amazing and I hope it will stay apart of Unity!
     
    Last edited: Jul 23, 2020
    adammpolak likes this.
  8. benoitd_unity

    benoitd_unity

    Unity Technologies

    Joined:
    Jan 2, 2018
    Posts:
    262
    Hey thanks for the feedback, I'll make sure they're aware of it as well :)

    We have no plans to kill the feature, only to improve it. I'm sure there's ways to make it run out of process.
     
    Tanner555 and MousePods like this.
  9. uDamian

    uDamian

    Unity Technologies

    Joined:
    Dec 11, 2017
    Posts:
    1,062
    For dragging elements around with the mouse, I generally have a "layer" element that I overlay on top of the screen using Absolute positioning and left/top/right/bottom set to 0. This becomes your dragging "screen root" where a top/left coordinate on an element should be equal to the y/x coordinate in (screen) world space. This might be what your drag area is and if so, great! Now when you start the drag and capture the mouse, you should:
    1. reparent the card into the drag area or layer
    2. set the card to be Absolute (assuming it was Relative while in its original parent)
    3. set the card top/left to match the mouse position from the mouse event
    If you do all 3 above in the same frame, there should be no "jitters" where the card goes to the top left corner of the screen.

    To go back to your original question, about updating the absolute position of an element when changing parents: we have no plans to "fix" this behavior. Relative positioning is what most UI elements should be using and therefore, have no manually entered coordinates of any kind. Absolute positioning is only available for very specific use cases - like the one I describe above.
     
  10. Chris-Trueman

    Chris-Trueman

    Joined:
    Oct 10, 2014
    Posts:
    1,006
    3 is where I had the issue. Changing it from using localMousePosition and the layout rect to using mousePosition instead fixed the issue. I was using the texture dragging example, which I thought was the problem with how it was dragging. Thanks for breaking it down like that, sometimes the brain just doesn't see it until someone points it out.

    How you explained above made sense and really helps me grasp the system. Absolute should only be used in certain situations. With uGUI I have layouts on most of the UI, disabled yes, but used to position everything without the need to position it. Now I don't need to worry about disabling layouts, I just need to learn how flex works to get it to work how I want it.

    As a side note, I now have the game working with addressables and I can change the deck images on the fly.
     
    uDamian and benoitd_unity like this.
  11. benoitd_unity

    benoitd_unity

    Unity Technologies

    Joined:
    Jan 2, 2018
    Posts:
    262
    We've setup a Git repo to host the Unity Royale demo project. It will be much easier for us to maintain and update in order to showcase the latest changes to UI Toolkit.

    It's also a new version which better implements best practices around styling architecture and UIDocument usage. It should also fix some of the scaling issues. Let us know what you think.

    Cheers,
     
  12. labandunga

    labandunga

    Joined:
    Aug 1, 2012
    Posts:
    29
    nice! I've been waiting for this release for a long time, very good job to everyone involved. Looks leaps and bounds better than Unity UI so far.
     
  13. chris-z562

    chris-z562

    Joined:
    Jul 11, 2012
    Posts:
    41
    The demo project has a bug when the screen is not the right resolution/ratio. If I run it in fullscreen (in 5K) the dragging of the cards is really choppy.
     
  14. Digika

    Digika

    Joined:
    Jan 7, 2018
    Posts:
    184
    Has nothing to do with your screen, same happens on 1080p
     
  15. chris-z562

    chris-z562

    Joined:
    Jul 11, 2012
    Posts:
    41
    It works well when it's set to a vertical ratio (like on a mobile phone)
     
  16. uDamian

    uDamian

    Unity Technologies

    Joined:
    Dec 11, 2017
    Posts:
    1,062
    We are actively working on the current UI scaling workflows. The demo has been adjusted to look "ok" on most users' machines and in the Editor, instead of looking good on some but completely broken on others.

    Scaling was mostly adopted from uGUI but uGUI did not have to also work nicely in the Editor context (and its own DPI setting) as all editing was done in the Scene view. UI Toolkit needs to work both in Editor (when being edited in UI Builder) and at runtime in the player. Expect improvements in the next few releases of both the package and the demo project.

    As for the cards not dragging properly, that looks like an actual bug with the project. We'll look into fixing that in future drops.
     
    chris-z562 likes this.
  17. Fuduin

    Fuduin

    Joined:
    Feb 7, 2020
    Posts:
    7
    Is UIToolkit working with a new input system? I tried to install the Input System package into the Unity Royale demo project and got some errors.
     

    Attached Files:

    lclemens likes this.
  18. JuliaP_Unity

    JuliaP_Unity

    Unity Technologies

    Joined:
    Mar 26, 2020
    Posts:
    289
    Not yet, but soon!
     
    lclemens likes this.
  19. chris-z562

    chris-z562

    Joined:
    Jul 11, 2012
    Posts:
    41
    Regarding runtime: It's not possible to be notified of a change in value from say a text field or a slider yet, right? That's part of the 'data binding' future features?

    For now, this seems to work well for TextFields:
    Code (CSharp):
    1. textfield.RegisterCallback<KeyDownEvent>(
    2.     evt => Debug.Log(textfield.text));
    It's only called when the KeyDown happens while the text field is selected, but it's called once for every letter you write.

    For Sliders MouseMoveEvent might work, and Buttons there's MouseUpEvent.

    Is this the best way to do it for now?
     
  20. Chris-Trueman

    Chris-Trueman

    Joined:
    Oct 10, 2014
    Posts:
    1,006
    For TextFields you can use RegisterValueChangedCallback.

    Code (CSharp):
    1. TextField text = new TextField();
    2. text.RegisterValueChangedCallback(TextChanged);
    3.  
    4. protected void TextChanged(ChangeEvent<string> value)
    5. {
    6. }
    7.  
    You do the same for sliders
    Code (CSharp):
    1. Slider slider = new Slider();
    2. slider.RegisterValueChangedCallback(SliderValueChanged);
    3.  
    4. protected void SliderValueChanged(ChangeEvent<float> value)
    5. {
    6. }
    7.  
    For buttons
    Code (CSharp):
    1. Button btn = new Button();
    2. btn.clicked += Btn_Clicked;
    3.  
    4. protected void Btn_Clicked()
    5. {
    6. }
    It should be a little more consistent and more like how the Button works using delegates, but it works.
     
    JohnBernardsson and chris-z562 like this.
  21. transat

    transat

    Joined:
    May 5, 2018
    Posts:
    772
    As an inexperienced dev making their first game (for the past 2 years) I regret not having followed that advice when I got started. The new UI system no doubt will be great but play it safe @Refeas because switching to the a new system to avoid learning a "soon-to-be-deprecated" one will quite possibly cost you time. In my case switching to URP/LWRP early meant I've spent the past year and half improving my debugging skills rather than advancing my game or learning new concepts.
     
    lclemens, Havokki and Tanner555 like this.
  22. polypilots

    polypilots

    Joined:
    Dec 8, 2018
    Posts:
    10
    Last edited: Jul 31, 2020
  23. uDamian

    uDamian

    Unity Technologies

    Joined:
    Dec 11, 2017
    Posts:
    1,062
    Please start a thread with your issue so we can keep on topic. Some more information would also help, like how you applied the styles in the Builder that don't work (inline in the UXML or via a StyleSheet with a selector). We've had issues with inline styles before.
     
  24. lclemens

    lclemens

    Joined:
    Feb 15, 2020
    Posts:
    262
    (Vote for Input System support)++;
     
    bashis likes this.
  25. MousePods

    MousePods

    Joined:
    Jul 19, 2012
    Posts:
    283
    Hi!

    I didn’t see anything about these features mentioned in the first post. Just curious if these features where coming out in 1.1 or beyond?

    1. 2D GameObjects With SpriteRenderers in UI and maskable.
    2. Particle systems in UI and maskable. (These could also be attached to a GO)

    For both of these features, I am curious about their combination. I have in-game items with particles you can buy as an IAP. Right now they have to be made twice, one for UI and one for in-game. I just want to verify a GO with sprite renderers and particle systems can be added to the UI.

    3. Trail renderer added to moving UI and maskable.

    For this feature, right now I have a UI that is moved with a trail renderer. It only works because the UI, atm, is based on Gameobjects. Will this be possible with UIToolkit? If not, would using the first listed feature, a GO in UI, work with the trail renderer attached?

    Thanks!
     
  26. lclemens

    lclemens

    Joined:
    Feb 15, 2020
    Posts:
    262
    Thank you so much for that example!!
     
  27. uDamian

    uDamian

    Unity Technologies

    Joined:
    Dec 11, 2017
    Posts:
    1,062
    I can't say if it's going to be something we'll have in 1.1, but all of this is on our roadmap to work on next year. The "maskable" variants of these features might come a bit after the features themselves though.
     
    MousePods likes this.
  28. Grimreaper358

    Grimreaper358

    Joined:
    Apr 8, 2013
    Posts:
    756
    How do you unlink Sliders, Foldouts, Toggle, etc from the unity theme template? Currently, you can't change anything related to them other than the names of labels, font-weight, etc. They are tied to editor themes but I want to use them at runtime with my own theming.
     
  29. JuliaP_Unity

    JuliaP_Unity

    Unity Technologies

    Joined:
    Mar 26, 2020
    Posts:
    289
    I suggest you start your own thread about this, or even take a look if this other thread has the answers you need: https://forum.unity.com/threads/uielements-text-field-changing-child-elements.789656/

    You need the default styles applied so that each element shows up as intended, but you can still style it your own way.
     
    Grimreaper358 and uDamian like this.
  30. Chris-Trueman

    Chris-Trueman

    Joined:
    Oct 10, 2014
    Posts:
    1,006
    After messing with the slider for a few hours, I am at a loss for how to really style it. The long winded class names, the inability to double click them to add them to my uss, coupled with my own lack of knowledge of css/uss has me baffled as to how to style a slider easily. I got one to somewhat look how I want, but because I am a absolute noob at using this type of system all my scroll bars got the same styling which I didn't want. I got it separated, but it wasn't an easy thing to do.

    UIBuilder is a great tool to make it easier to use the system. Its frustrating not being able to add the class names to my uss from the children that need the styling to be modified without typing in a very long name that I may have gotten wrong. USS is great, something uGUI was missing and it makes styling a breeze once you get it right. Want a your buttons to look a certain way, uss it and apply that style to all your uxml's and no need to set anything else. But the built in controls need a better way to style them without typing in the horrendously long class names and also have it easier to know which ones you need to override. I didn't even mention that you need to override hover, active, focus, etc for each of the controls and their children. It would probably be easier to hand code the uss, but I don't know what I'm doing in there.
     
  31. benoitd_unity

    benoitd_unity

    Unity Technologies

    Joined:
    Jan 2, 2018
    Posts:
    262
    Thanks for the feedback Chris. You're quite right, Slider is probably the trickiest to customize. We definitely want to address that in a future release but meanwhile, we're improving the documentation to help with that kind of task.

    Cheers
     
  32. Grimreaper358

    Grimreaper358

    Joined:
    Apr 8, 2013
    Posts:
    756
    The link in this post should help you. It's what I used. Well it helps a little you still have to define a lot of classes to style it

    https://forum.unity.com/threads/ui-toolkit-1-0-preview-available.927822/page-3#post-6187503

    This is a slider I styled - Only thing I haven't figured out is the input field background, seems it might be using an image or SVG not sure.

    You can see the selected classes also display the full names of the elements they are modifying in the USS at the bottom.
    upload_2020-8-11_20-59-25.png
     
  33. dotsquid

    dotsquid

    Joined:
    Aug 11, 2016
    Posts:
    207
    Hi there.
    Thanks for a new and highly awaited new solution for UI.
    I just started scratching the surface, but I've already have questions / concerns. For example, it was not so easy to use Particle Systems with uGUI, but it seems it's totally impossible with UI Toolkit? What about complex shader effects? E.g. with uGUI and custom materials I could make UI elements which blur the background behind them. At first glance UI Toolkit does not provide any solution to use materials.
     
  34. MousePods

    MousePods

    Joined:
    Jul 19, 2012
    Posts:
    283
    dotsquid likes this.
  35. dotsquid

    dotsquid

    Joined:
    Aug 11, 2016
    Posts:
    207
    MousePods likes this.
  36. DeanNorth

    DeanNorth

    Joined:
    May 15, 2015
    Posts:
    4
    Has the latest preview 6 package broken the VFX graph for anyone else?

    *EDIT* I was using 2020.1.2f1. I have upgraded to 2020.2.0a19 and the VFG graph now loads but its missing the group boxes that I had used to group the nodes
     
    Last edited: Aug 17, 2020
  37. lclemens

    lclemens

    Joined:
    Feb 15, 2020
    Posts:
    262
    Considering the new input system... Preview-4 came and went... Preview-6 is here... A month passed... So now we get to give you a hard time. ;)
     
  38. bhuvanesh_unity731

    bhuvanesh_unity731

    Joined:
    Aug 11, 2020
    Posts:
    1
    When I am importing the UIERuntime packages I am getting lot of errors(edited)
    that many functions doesn't exist
    Can anyone tell the solution for that


    Message #dots
     
  39. darthdeus

    darthdeus

    Joined:
    Oct 13, 2013
    Posts:
    48
    Too bad the worldspace runtime support is planned only for next year, I'd imagine most games wouldn't be able to switch to UI Toolkit before then :(
     
  40. Refeas

    Refeas

    Joined:
    Nov 8, 2016
    Posts:
    186
    Well I suppose you could still combine them until a worldspace is supported in UITK.
     
  41. lclemens

    lclemens

    Joined:
    Feb 15, 2020
    Posts:
    262
    Can you give a couple of examples of a few of the errors? I know that if you have only "New Input System" selected in Player Options you'll get a whole bunch of errors.
     
  42. R0man

    R0man

    Joined:
    Jul 10, 2011
    Posts:
    88
    I noticed that the documentation is missing the section on how to create a runtime UI that shows up in the Game window. Is there a technical reason for this?
     
  43. uDamian

    uDamian

    Unity Technologies

    Joined:
    Dec 11, 2017
    Posts:
    1,062
    You can still do world-space UI by using render-to-texture option in the PanelSettings asset. The main problem is performance. This will improve once we have native support for world space.
     
    darthdeus likes this.
  44. uDamian

    uDamian

    Unity Technologies

    Joined:
    Dec 11, 2017
    Posts:
    1,062
    It's because the runtime part is very new and not even part of core Unity yet. It only exists in the package (unlike the rest of the UI Toolkit framework, which exists in both package and core). It's a temporary situation.

    You can find the WIP docs here:
    https://docs.google.com/document/d/1C_c5hrqOrkgYjmD3s04vcKfk-aQ8n007Ti7vUR51SeQ/edit

    This will make it's way to the official documentation as we get closer to release.
     
    R0man, Jes28 and mk0a1a like this.
  45. Alaiing

    Alaiing

    Joined:
    Nov 17, 2012
    Posts:
    15
    Hi!

    Apparently, preview.6 doesn't work so well with Unity versions 2020.1.2f1 and 2020.1.3f1.
    In any graph view (Shader Graph, VFX Graph or custom graph) the edges connecting 2 ports are not renderered. Ex. in Shader Graph :
    upload_2020-8-24_15-38-34.png
    ("RGBA(4)" on the left is supposed to be connected to "Base Color(3)" on the right)

    It should be easy to reproduce but I do use many preview packages in my project. In any case if a bug has to be reported I can provide a sample project.

    It worked fine with Unity 2020.1.1f1.

    Cheers.
     
    Xenerade likes this.
  46. Xenerade

    Xenerade

    Joined:
    Dec 10, 2017
    Posts:
    182
    I got the same issue. Completely new project, 2020.1.2 & 2020.1.3, only added the runtime package to the manifest, then everything based on visual elements in the editor broke. It disappeared once I removed the package, but reappeared if I tried to reinstall it.
     
    MostHated likes this.
  47. uDamian

    uDamian

    Unity Technologies

    Joined:
    Dec 11, 2017
    Posts:
    1,062
    There are some incompatibilities between the UI Toolkit package (com.unity.ui) and newer builds of Unity 2020.1 and 2020.2. We are about to release a new version of com.unity.ui that fixes these issues. Until then, you need to use older builds of 2020.1 and 2020.2.
     
    JohngUK and Xenerade like this.
  48. Alaiing

    Alaiing

    Joined:
    Nov 17, 2012
    Posts:
    15
    Ok, thanks for the heads up!
     
  49. MostHated

    MostHated

    Joined:
    Nov 29, 2015
    Posts:
    1,089
    Just had this happen to me as well, a few moments before I came across this thread. Glad to see that a fix is coming, it looks like.
     
  50. Alaiing

    Alaiing

    Joined:
    Nov 17, 2012
    Posts:
    15
    It's indeed fixed as of preview.7!
     
    Xenerade likes this.
unityunity