What's the deal with UnityEngine.UI?

So there’s IMGUI and UITK and then UGUI, those all make sense (sort of) to me.

But I can’t really understand why the UI GameObjects exist (the stuff in UnityEngine.UI, like right click → create → ui → Button, etc.).

When would I want to create, say, a UnityEngine.UI.Button instead of using one of the toolkits? Why did those components exist in the first place as opposed to, say, an IMGUI editor in the scene view (originally, I mean)?

Is there any reason to build a UI with those Components instead of using one of the toolkits? Especially when dynamically creating UIs in code.

Is there any difference between those components vs. one of the toolkits as far as input event handling or anything goes?

Thanks!

IMGUI is deprecated.

That is not part of Unity, AFAIK. (EDIT: I see you mean UI Toolkit, I thought you were talking about a TclTk port… disregard.)

This is usually what people mean when they refer to UnityEngine.UI.

Is that your confusion?

Because it’s the reference way to create UI today in Unity.

I would imagine that they are nearly 100% different, like every single possible thing about them.

1 Like

The bigger question is why ask here on the 2D forums? All the UI stuff is not a 2D feature.

The dedicated UI forums are here!

1 Like

I don’t know if that is “the bigger question” but: Because there’s no general UI forum; it’s all specific to one of the toolkits. I considered it, then figured, well the UIs are 2D so I guess 2D is where it goes.

Also, the reason I was looking for a general UI area is that I had no idea I was asking about UGUI, so from my POV there wasn’t a UI forum for it. I’m pretty sure I’ve never seen the term “UGUI” in Unity itself, anywhere, and I’m not sure where I could’ve come across that name.

If you have thread moving powers, though, you’re welcome to move this somewhere. That would be a generally helpful thing to do (well at least, helpful as long as it’s not to the trash bin).

Sorry about that! I’ll refer to it as the correct name, “UI Toolkit”. Thanks!

Yes! I had no idea that’s what UGUI was. I glanced at the post dates in the UI Toolkit and UGUI UI forums and mistakenly concluded that UGUI was something new (and also I didn’t know that’s what it was called). This clears a lot up, thank you.

Really? From what I’ve gathered over time, everybody seems to say “IMGUI is deprecated, use UI Toolkit instead”, but I’ve never really seen advice like “use UGUI instead”. Is UGUI the current reference because IMGUI is deprecated and UI Toolkit is… still in development?

But I can make a UGUI button, an IMGUI button, and a UI Toolkit button (in a UIDocument) and they all seem to respond to clicks without me having to do anything special … I think. They all have different callback mechanisms but those mechanisms are ultimately pretty similar (UGUI = unity event → execute your code, IMGUI = check a return value → execute your code, UI Toolkit = some delegate → execute your code).

One difference I spotted is, by default (?) UI Toolkit doesn’t map position-based input to the correct place if you’re using a UIDocument with a RenderTexture output; I didn’t dig into that much but I’m assuming there’s something extra I’d need to do there; so that’d be a difference.

UGUI seems a bit more cumbersome for quick setup of GUIs with non-trivial layouts (especially ones generated at runtime) or custom themes than IMGUI and UI Toolkit; although being able to use prefabs and having the GameObject + Component setup is pretty handy and if you put the time in to setting it up correctly, it seems like you’d end up with something a lot more reusable and scalable. IMGUI feels the most natural (subjectively of course; to me) and quickest to code up. But I checked out UI Builder and it really makes UI Toolkit very fast to put together, it’s pretty cool and when I discovered it (UI Builder), I stopped being sad about IMGUI being deprecated. That’s another difference I guess… which “paradigm” you use when you’re building the UIs.

I guess mostly my question there is, is there any, say, platform compatibility reason to use the GameObject / RectTransform-based UGUI over one of the other more uh … stylesheet and code-centered … toolkits (which I guess? Especially with things like say sharing the same setup code for some specific 2D UI between 2D apps, a desktop 3D app, a web app, and an XR app, etc.

(And I guess my other question is, before UI Toolkit, why did both UGUI and IMGUI exist, instead of just IMGUI?)

Way back when only nomadic gangs of primitive programmers like myself roamed the earth, and mobile devices were just crawling out of the primordial ooze to wrap around the brainstems of unsuspecting humans, Unity had immediate mode GUI, driving both games and the editor.

Lo, it was glorious and the God of Programming did look down upon our projects and our repositories and our simple text editors and smile. One could do everything with a few lines of code: make a rect, set a style, call an API, draw a texture, some text… done.

Some of us less-evolved primitive programmers dubbed this the “Golden Era of Actually Shipping The Game.”

But the God of Art and the God of Design looked down with dismay and said 'We do not want to make rects and call APIs, we don’t have that kind of desire to inflict self torture… SAVE OUR PEOPLE!"

“And besides, you programmers make TERRIBLE-LOOKING UI/UX!!”

And the God of Unity did spake, and around about the Year 2014 of our Unity, in Chapters 4 dot 6, did the waters part and forth came the all-new UnityEngine.UI module.

And yea did the primitive types like myself gnash their teeth and rend their keyboards asunder! Their cries rose up through the heavens, beseeching the Gods… “Why must we touch our mouse? Surely we have not been so wicked in thine eyes?”

After four score and twenty patches and hacks and tutorials and teeth gnashing, we primitive programmers came to learn and grudgingly tolerate the UGUI.

But no matter how much we adapted to UGUI, 100% of the Unity Editor (scripts, windows, inspectors) and everything still uses the IMGUI system, with good old GUI and GUILayout still powering every single millisecond, every click, every graphic, every button, every piece of text in the ENTIRE UNITY EDITOR.

If you want to be a serious Unity programmer, you MUST write editor scripts… so you must remember how to use IMGUI/OnGUI anyway.

Now this is where my history gets a bit fuzzy, but I think UIToolkit is an attempt to unify all this into a single web-friendly designer-friendly system, able to power your game AND write editor tools.

Well, not sure where it is at… but it still has a ways to go! Even their own site says to use UGUI:

I quote:

“Although Unity recommends using UI Toolkit for some new UI development projects, it’s still missing features found in Unity UI (uGUI) and IMGUI. These older systems are more appropriate for certain use cases, and are required to support deprecated projects.”

5 Likes

The UIs are not limited to 2D, quite the opposite. If in doubt, go use the main one here which is where 99% of UI posts are.

I’ll move your post for you.