#Make a mod with a UITK GUI
1 messages ยท Page 4 of 1
"com.unity.addressables": {
"version": "1.18.19",
"depth": 0,
"source": "registry",
"dependencies": {
"com.unity.scriptablebuildpipeline": "1.19.2",
"com.unity.modules.assetbundle": "1.0.0",
"com.unity.modules.imageconversion": "1.0.0",
"com.unity.modules.jsonserialize": "1.0.0",
"com.unity.modules.unitywebrequest": "1.0.0",
"com.unity.modules.unitywebrequestassetbundle": "1.0.0"
},
"url": "https://packages.unity.com"
},
this is how ti works
close and reopen the ui builder
How do you re open that?
nvm, double click uxml
Except that gives the same fubar result
for future reference is Window>UITK iirc
Oh thats wierd
do you have errors on the console?
your uxml might be faulty
it already is
Touched some of the code, closed and reopened, but still get the damn dialog warning me
Now have the UI Builder back up though
I found the check box to toggle the full log, but see nothing I'm able to click on to copy/paste.
May have found it?
Hey, I need to scoot. I'll check back later. No real losses here as I still have the old project.
that was not it unfortunatelly, but ok! i hope that we have a fix for this soon :D
Hey Lux, I'm back from work and thinking about this problem again. Would it help to do a WinMerge compare on the two projects to see what might be different?
go for it!
tho i think it will be a ton of unity stuff
that we wont make sense of xD
One diff is that the old project has a UI Toolkit folder and the new one doesn't. Am I maybe missing that or is it not necessary?
what does it contain?
The new one is deceptively named MNC-UI
couldnt be that
can you send me the whole log line?
if you go onto the unity's console
and click on the error line
it will show below a selectable text
The UI Toolkit folder gets created automatically if you add a UI Document object to the scene
Then why don't I have one?
Well have you added a UI Document object to the scene?
And it should work without it, because the only stuff it contains is PanelSettings and related stuff, and those shouldn't be used anyway, the ones in the UitkForKsp2 package should be used
I'm pretty sure I was building AppBar assets fine without the folder
It shouldn't have anything to do with Unity not being able to find some classes, since it doesn't contain any code, just some default auto-created assets that we don't need
I mean sure, you can try it
But I'd be really surprised if it was the root cause of the issue
Which log line? There are like 12 errors.
Here's one: Library\PackageCache\uitkforksp2.controls@d8cc3fd6bc\Runtime\ExposedControls.cs(57,26): error CS0311: The type 'UitkForKsp2.Controls.RadioButtonGroupControl.UxmlTraits' cannot be used as type parameter 'TTraits' in the generic type or method 'UxmlFactory<TCreatedType, TTraits>'. There is no implicit reference conversion from 'UitkForKsp2.Controls.RadioButtonGroupControl.UxmlTraits' to 'UnityEngine.UIElements.UxmlTraits'.
Theres no conversion from the same type 
Here's another Library\PackageCache\uitkforksp2.controls@d8cc3fd6bc\Runtime\ExposedControls.cs(9,26): error CS0311: The type 'UitkForKsp2.Controls.Dropdown' cannot be used as type parameter 'TCreatedType' in the generic type or method 'UxmlFactory<TCreatedType, TTraits>'. There is no implicit reference conversion from 'UitkForKsp2.Controls.Dropdown' to 'UnityEngine.UIElements.VisualElement'.
OK done. close and reload?
yup!
it will redownload it
if that doesnt work
just remove the package and i'll send you the file, will work too
Yes, the warning popped up first, followed by the errors'
1 warning, 12 errors
really just two errors multiple times each
I think the warning was simply that I'd deleted the cache, no?
wait
before u do that
let me check smth
Another interesting difference...
In package-lock.json the package versions are fairly different
what uitk version
Yeah, because I went and manually updated them to the latest versions
is on the package-lock?
The new project has older packages...
Yep
Since you're in old Unity 2020, the default project template has old package versions by default
So if you want the default packages to be the newest versions, you have to go and update them manually in the Package Manager
But it doesn't really matter since you don't use any of them
OK, and presumably these are unlikely to be the source of the issue
And since UITK and the UI Builder are listed as dependencies in UitkForKsp2, you won't see them in your own packages manifest file
They're installed, but through UitkForKsp2
could that be it?
I can't see how, if you look into the Packages view in Unity, or in the cache folder on the actual filesystem, both UITK and UI Builder are installed the exact same way as for a project that directly lists them as dependencies
Could it be as dumb as my project is MNC-UI but my uxml is MNC_UI?
Nope
can confirm
adding it via the Git bugs things
@shadow tree
shouldnt uitkforksp2 be here too?
well if you installed it, then it should
i did, via the link
this is wierd
munix
shouldnt the asmdef have uitk has a reference? @shadow tree
well i cant seem to find the GUID reference to the UITK
guid reference?
Oh xD, honestly not sure
but i got this i think it works
[
"GUID:023ac9b81facd43ebbb2a6f1c6252835"
]
idk if it forces to use GUID instead of package references
or what
the errors disaperad after i added this to the packagecache
lets see if it works
isn't this all we need to do?
seems like it
if the reference is the issue
yip, i was not sure
because i didnt know
that was UITK stuff
though it was ugui
thats all you need im pretty sure
@marble shale
well, you'll have to wait for munix to updat eit, but as soon as it does just update the package on the package manager
Awesome! thanks!
pushed
Not sure if I did it right. I deleted the cach and reloaded. Got the same error. What should I do? remove and re add the package?
Or do I need to download something?
you should just be able to go to the package manager and click update on the package
or maybe not lmao
since I can't seem to be able to do that in my project either
since its from Git i think you have to paste the git link again
Works ! I'm building now!
great, glad that's solved
Thanks you guys! I'd never have been able to figure this out on my own.
And now we've got a process for making a fresh clean UITK UI project!
I'm still planning to make the template for it
Though it's taking for ever to build...
It seems to be stuck on RecompileBeforeBuild
hm, I do not have that
However, all the errors are gone and there was just the normal warning for the package cache being invalidated
I'd try just closing and reopening the project
It's really stuck. I may have to kill it hard
yeah probably you have to kill it
It opened fine without warnings...
unity doesnt like updates like that
Twice now.
yup! same for me
Buyt each time the canvas is shrunken
Is there a way to permafix the canvas size? It always wakes up with 350 x 450
I want 350 x 750
that's definitely weird
Or better yet screen size of 1920 x 1080
Got a successful build!
Also got a couple errors and warnings
Unexpected recursive transfer of scripted class. 'BuilderDocument' is being transferred while trying to transfer 'LiberationSans-Regular SDF'
UnityEditor.EditorJsonUtility:FromJsonOverwrite (string,object)
Unity.UI.Builder.BuilderDocument:LoadFromDisk () (at Library/PackageCache/[email protected]/Editor/Builder/Document/BuilderDocument.cs:440)
Unity.UI.Builder.BuilderDocument:CreateInstance () (at Library/PackageCache/[email protected]/Editor/Builder/Document/BuilderDocument.cs:204)
Unity.UI.Builder.BuilderPaneWindow:get_document () (at Library/PackageCache/[email protected]/Editor/Builder/BuilderPaneWindow.cs:24)
Unity.UI.Builder.BuilderViewport:.ctor (Unity.UI.Builder.BuilderPaneWindow,Unity.UI.Builder.BuilderSelection,Unity.UI.Builder.BuilderElementContextMenu) (at Library/PackageCache/[email protected]/Editor/Builder/Viewport/BuilderViewport.cs:153)
Unity.UI.Builder.Builder:CreateUI () (at Library/PackageCache/[email protected]/Editor/Builder/Builder.cs:115)
Unity.UI.Builder.BuilderPaneWindow:CreateUIInternal () (at Library/PackageCache/[email protected]/Editor/Builder/BuilderPaneWindow.cs:150)
Unity.UI.Builder.BuilderPaneWindow:OnEnable () (at Library/PackageCache/[email protected]/Editor/Builder/BuilderPaneWindow.cs:135)
Unity.UI.Builder.Builder:OnEnable () (at Library/PackageCache/[email protected]/Editor/Builder/Builder.cs:239)
UnityEditor.WindowLayout:LoadDefaultWindowPreferences ()
UnityEditor.EditorJsonUtility:FromJsonOverwrite(String, Object)
Unity.UI.Builder.BuilderDocument:LoadFromDisk() (at Library/PackageCache/[email protected]/Editor/Builder/Document/BuilderDocument.cs:440)
Unity.UI.Builder.BuilderDocument:CreateInstance() (at Library/PackageCache/[email protected]/Editor/Builder/Document/BuilderDocument.cs:204)
Unity.UI.Builder.BuilderPaneWindow:get_document() (at Library/PackageCache/[email protected]/Editor/Builder/BuilderPaneWindow.cs:24)
Unity.UI.Builder.BuilderViewport:.ctor(BuilderPaneWindow, BuilderSelection, BuilderElementContextMenu) (at Library/PackageCache/[email protected]/Editor/Builder/Viewport/BuilderViewport.cs:153)
Unity.UI.Builder.Builder:CreateUI() (at Library/PackageCache/[email protected]/Editor/Builder/Builder.cs:115)
Unity.UI.Builder.BuilderPaneWindow:CreateUIInternal() (at Library/PackageCache/[email protected]/Editor/Builder/BuilderPaneWindow.cs:150)
Unity.UI.Builder.BuilderPaneWindow:OnEnable() (at Library/PackageCache/[email protected]/Editor/Builder/BuilderPaneWindow.cs:135)
Unity.UI.Builder.Builder:OnEnable() (at Library/PackageCache/[email protected]/Editor/Builder/Builder.cs:239)
UnityEditorInternal.InternalEditorUtility:LoadSerializedFileAndForget(String)
UnityEditor.WindowLayout:LoadDefaultWindowPreferences()
yeah you'll usually always get some
as long as they disappear when you clear the console, you should be fine
The font one I know will mean I'll get some log spammage.
I get that one twice for some reason
No, the second one is diff
Invalid value for font Keyword
UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)
They do disappear when clearing the console
that i know of no!
Well, the errors did, the shorter font one came back natch
I know that in my other project it remembers a different size, much bigger. There must be some way to set it...
That's only temporary. it will be good for as long as you have it open, and no longer.
"In the same section, you can also lock the Canvas size to the size of the Unity Game Window using the Match Game View checkbox to better match a runtime UI environment:"
That worked!
I don't know how to set the runtime UI environment, but it's big enough that I can see my UI un-scrunched, and it sticks so it's that way when I reopen it too
its not hard
just set up a UI Document on your scene
and some sort of script that instantiates your window
but its not really needed
since you can preview your ui on the ui builder
don't need that afaik
all you need is to add the UI Document game object and set it to use the correct asset
FYI, I rebuilt the MNC UI using the super simple guidance Munix and Cheese first gave above. It really was super easy with just a few steps. I did this simply because I wanted it to be in a particular folder (MNC_UI), and simply changing the folder name didn't work. I'll do this with the FP UI as well, though it will be even easier now.
Do I need these kerbalui files in my AssetBundles folder?
I don't think so, certainly not as an asset bundle. I also have them in my project as I didn't bother removing their asset bundle creation, but I don't use them. I only copy bundles I've created. BTW you can safely delete everything that's inside this folder as it gets recreated when you "Build AssetBundles"
I deleted them and rebuilt the UI. They're back, so building the UI creates them. Weird, as I'm not using them for wanything so far as I know
Yes, they're rebuild every time cause they have an asset bundle attached to them. You can set the bundle to none to stop generating it:
That's odd. When I look in the Theme folder I don't see a KerbalUI.
I've got UITK for KSP 2 in packages, but I don't think I've got KerbalUI anywhere in this project.
Ahhh! I found it! It's in the package cache
But is it spuppoed to be there?
And it's here, too, in the UITK for KSP 2 package
๐
@shadow tree , I'm getting this warning
[WRN 07:00:35.548] DontDestroyOnLoad only works for root GameObjects or components on root GameObjects.
for this code in FP's OnInitialized()
// Load UITK GUI
var fpUxml = AssetManager.GetAsset<VisualTreeAsset>($"{Info.Metadata.GUID}/fp_ui/fp_ui.uxml");
var fpWindow = Window.CreateFromUxml(fpUxml, "Flight Plan Main Window", transform, true);
UnityEngine.Object.DontDestroyOnLoad(fpWindow);
fpWindow.hideFlags |= HideFlags.HideAndDontSave;```
Safe to remove the UnityEngine.Object.DontDestroyOnLoad(fpWindow);? What effect is that supposed to have?
I'm getting the same thing for MNC, naturally. Also both of these tend to spam my logs with
[WRN 07:00:35.610] Font not found for path:
and
[WRN 07:00:35.778] Invalid value for font Keyword
The spamming is not contiunuous, but happens initially when they first load and then whenever you interact with them.
Yes, you can (and should) remove that
UITK for KSP 2 already persists the objects with the UI
You're trying to call it on the component that's on the game object, not on the game object itself, so it's complaining
Done. I also found this which might be a clue on the stupid font warnings
Got an issue persuading the UI to actually have and use a wider text input field. In the Unity editor it looks like this
Which is, in fact, what I'm intending for the Max Arrival Time text input field. This is controlled by .unity-text-field > .unity-base-text-field__input which set it this way
I know this is applied to the text field input as I can see it applied right here
And it looks fine in the editor with Preview turned on like so
Notice how the text input box starts just under the 'p' in the "Advanced Interplanetary Transfer" button right above it. But here's what the stinking thing does in game
Setting aside the red formatting, the text input box now begins just under the 'n' in the "Advanced Interplanetary Transfer" button above it.
What the actual fuck?
I've tried adding a Flex Grow 1 to .unity-text-field > .unity-base-text-field__input, but that had no effect whatsoever
Since the stupid thing I want to affect is a grayed out sub component of a UITK TextField object, it's not possible for me to flat out tell the stupid thing what it's stupid width is other than to use a uss AFAIK. But nothing I've done has come even close to persuading this thing to be the siaze I want it to be in game. It looks fine in the editor, but in game it's the same size (100px wide) that it was before I began fiddling with it to make it biggger.
@dusty berry, @shadow tree help?
im guessing this is the same issue that you had with the other inputs
hmm
if you click on the text input
and check its classes
you can see the hierarchy
the lower one is the more iumportant
if you override that one it should apply correctly
So I need to do this to .unity-base-field?
.unity-text-field has this, but it's applied to the whole enchilada
And I'm making the effect I want by setting the Min width to 150
.unity-base-field also has nothing set for Min Width
I'm looking at how I have textfields set up and it's pretty basic. VisualElement that holds the row of controls has flex-direction: row; width: 100%; height: 20px; justify-content: space-between; , the "<" and ">" controls have a fixed width defined and to the textfield itself I've attached a new class that has flex-grow: 1;. And that should be it.
This whole thread is a how to... ๐
Exactly. Initial idea was for people to read it as a tutorial, but spam is overwhelming at this point ๐ . Luckily search works well ๐
I think theres a fair few thousand messages in this thread
All usefull information
Right, it's true that at this point UitkForKsp2 is relatively stable (though I've experimenting with some new stuff, but I don't think anything will come out of it), so I should probably put together some docs
What new stuff?
I was trying to see if I could backport some stuff from newer Unity versions
because the built-in version of UITK is just so much better than our shitty prerelease package
๐ญ
it actually feels stable and good to use lmao
but no luck
Theres a lot of internal classes and things that they use roght?
I was trying to see if I use an asset bundle with UXML/USS from Unity 2021-2023 (and inject the UIElementModule DLL from a newer version to match it)
it was a dumb idea but I wanted to try anyway lmao
turns out the asset bundle format is different and 2020 can't read those new bundles at all, and also the shaders seem to be compiled differently
I can't even see what shaders are in a bundle using Asset Studio/Asset Ripper with the newer bundles
Try addressables
it just throws errors
hm I could try that
but afaik it's basically the same format as a regular bundle, just with a catalog, no?
Yeah afaik asset bundles are just easier addressables in newer versions
The diffrence is that addressables also pack all dependecies
I'll take a look at addressables as well, then, we'll see
I think the biggest issue will be shaders, since in the UITK preview package, the shaders were simply included in the asset bundle, but not so in the built-in UITK versions
the whole architecture of the system seems to have changed
I found some of the UIR (UI Toolkit Runtime) shaders in a 2021.3 bundle which the editor builds when you build the full game, it was in like one of the sharedassets bundles or something like that
but the bundle format seems to be different so I don't think we could load it
Is there a good/easy way to change the color of the white hover/inactive hover items? Preferably in C# alone.
Usually this stuff is done with USS (where you just add ":hover" to your selector), but you could just register event handlers for the list items and change the colors manually
There's MouseOverEvent and MouseOutEvent
That should be what you need for the hover
Hmm, I was having some trouble with the event approach, but I can give it another shot. My main problem is list and tree view items don't show up in the editor, so it's hard to preview changes.
Also, is there a way to have my window always draw on top of game windows?
it doesn't do that?
No, it's drawing underneath some, but not all windows in the VAB and KSC
that's really interesting, must be something new in Unity 2022
it used to be that the UITK panels were always rendered at the very top, above all camera layers, and UGUI (which also means the game UI) was rendered using cameras
that's something we'll have to investigate, then
I wonder if when it's created has somethign to do with it
we had the opposite problem before, there was no way to put UITK elements into the background ๐
but I guess now that it's built in, they updated the system so that it can interact with the UGUI elements
Ha, this is why I hate UI work. Always some weird quirks
honestly it doesn't matter too much if it's UI or something else, there are always weird quirks and bugs when it comes to Unity
Yeah, I guess that's reverse engineering in general
for UITK elements, their visual order is determined by the hierarchy, maybe it's the same for the order between UGUI and UITK windows?
you could try to create a new game object, place it in the hierarchy below the object that contains the stock save dialog, and render the UI in it
Possibly. I noticed that the elements drawing on top are part of the Main canvas, not the VAB canvas, located in the DontDestroy scene, not the f scene
interesting
Is this thread where I should post UITK questions? I tried to scroll to the top to read the initial message but it's soooooooo faaaaaarrrrrrrrrrrrrrrrrrrrr
Mkay. I have a UITK window that consists of four VisualElements that I'm using as containers. I have a bunch of buttons to swap between them. When I open my mod, I correctly see only the first container, which I refer to as the Alarms List Container. In this container is a button, "New Alarm" that should make only the second container visible.
The way I am trying to accomplish this is by having a windowState integer that I can set, alongside a function to use that integer to set the visibility of the various containers. So, to go from the first to the second state, I have:
Where RefreshVisibility() sets the visibility based on my selection
(I'm going to make an enum for this please don't murder me)
Anyways, this doesn't seem to work, and I'm not sure why
Are you sure the callback is being calledM
Nope, should probably check that yeah
A thermonuclear bomb is already being delivered to your house sorry
nuuuuuuuuuuuuu
It would appear the callback is not actually being called
so
I probably made a typo somewhere
aaa
Okay
Where did you register it?
I have a method to link all my button handelers
Which is being called where?
Hmm
This is how it's named in unity
Instead of clicked
Do
.RegisterCallback<ClickedEvent>(_ => NewAlarmButtonClicked())
Try that @somber hawk
sure thing
Still nope
Yeah nothing happens still
@shadow tree im confused here
I dont understand
How is this class being added to the window @somber hawk
Is there any errors in the log?
hmm, I can check
Check both ksp2.log and logoutput.log
This looks potentially relevant!
Lol
Happens to the best of us
Is there a styling class I should use for the "header" of a window (idk what to call it, like the bar that says the name of the mod and has a close button at the top)
oh yeah, it needs to have the name "title-bar"
not class
and it should automatically style both the button and the label inside
the UI builder sometimes likes to set some random height values when creating new empty VisualElements
check if that is the case in your UXML
I don't think so?
you should be able to just delete the while style attribute there
and it should work fine
also maybe try to replace the X with ร
it might look better
Will try that later, also maybe want to add a bit of horizontal padding
sadly have to do other stuff for a while now, but I feel like I'm getting somewhere with this
tyyyy for your help
glad to help
it should be possible to just put either an Image or a VisualElement with a background as the content of the button
If I want to dynamically change the background of a VisualElement in my code, how do I reference the image I want to set it to? I assume I need to get it with AssetManager.GetAsset(), but what type am I looking for?
seems like Texture2D
but another way you could do this is to have the images in your Unity project, and define a class that has the different background image set, and just toggle the class at runtime
or analogously for more than 2 states
yeahhhhh I probably should do that
generally it's better to put images into addressables or asset bundles if you can, for load times


