I am sorry for probably silly questions but I am having hard time trying to use the UI Toolkit together with UI Builder in order to create a runtime GUI for my game.
I am using UI Toolkit 1.0.0. Preview 8 and UI Builder 1.0.0. Preview 6.
My issues are:
In the demo video from Copenhagen and everywhere in the web I see that I should use PanelRenderer, however, my editor tells me that it is obsolete and I should use UIDocument instead. I am using it and I managed to get the UI to show on my screen:
However, I am not sure my setup is correct as I have in my scene a gameobject with the UIDocument, filled with PanelSettings and SourceAsset and I also added EventSystem. The problem is the UI is not reacting to clicking/hovering. In my UI Builder window, in preview mode it works, but in the running game it doesnāt.
Here is my prefab:
the Second issue is with binding, I do not understand how to bind data to my UI elements. For example, I have this Rage slider in the right corner and I want it to correspond to the integer public field of my PlayerController, which is named the same - Rage. How do I do it? I have this script attached to the prefab from my scene (from point 1), I managed to get the root element and query it for the visual elements, I do not know how to connect it to my PlayerControllerā¦
Is there in general any tutorial out there which would cover this use case ==> UI Toolkit + UI Builder + runtime + using UIObject and not obsolete PanelRenderer?
If Iām not mistaken you may be using the wrong Event System! Itās confusing because they have the same name but look for the āEvent System (UI Toolkit)ā entry on the add component menu. Alternatively, if you right click in the Hierarchy view and choose UI Toolkit > UI Document, if thereās no proper Event System in your scene, it will be added for you.
Sadly thereās no data binding capability for Runtime currently, so youāll have to bind the values yourself. Probably on the Update method of that same MonoBehaviour class, through setting the value on the slider to the one retrieved from your player.
Hey!
Wow, thanks so much! You were right, it was the other EventSystem - after adding the right one, it works
Thanks a lot also for the link to the code, I will check it out
When it comes to binding, yeah thanks for the suggestion, that is straightforward and easy! Will get into it right away
I have this exact same question. I actually built a complex Editor system using UI Elements about 6 months ago, and I thought I could jump right back in. Unfortunately, with the name changes and switching to a runtime UI, Iām having trouble getting started again. I learn best by examples, but the Unity Royale game is so much more complex than what I need I canāt grasp what is going on.
Typically, your C# documentation has a simple script example, which is pretty much all I need to get the concept. I would love to see a simple example of this:
Create a run-time slider like āspeedā and have it change the value of a GameObject during runtime in a C# script?
I was able to divine from the example that I needed to edit the UXML file to bind to a C# script, based on the Options speed screen. Some of the old examples mentioned a Resource folder, but then Iāve heard to avoid using a Resource folder, so it works without anything like that.
Using uGUI, I would then create 6 sliders and hook them up to 6 GameObjects with the targeted script. Iām now just worrking out the logic for how to do that using UIElements. I guess a Manager type of GameObject, with one script and an array of object to affect? Or, use the name of the slider to find and target an instance in the game?
A stretch-goal for my project would be another example to do this:
Create a run-time slider that matches an Editor slider, so changes in the editor set the defaults for the run-time
@Voronoi , if you are able to get something hooking up a slider to a game object, itād be great if youād push it to a github repo. I also found the Battle Royale game too complex, really Iām just looking to create a simple menu that includes āSettingsā, and then hook those settings up to GameObjects. I canāt wait to get all the layout GameObjects out of the hierarchy and replace them with the runtime ui.
I was planning to do this and your post prompted me to go ahead and get it up. This is as much for me to remember how to hook everything up!
The repo shows a few scenes, from simple runtime buttons and sliders to a complex editor interface for scriptable objects. In addition to showing some examples of the UI Toolkit runtime, I implemented [mention|0lDOuugxWKeU3CelW13Kjw==] 's suggestion for how to block raycasts for an AR project I was working on.