Disappointed with New GUI System

I’ve just recently finished making a GUI in Unity’s 5.0 new system for Creating GUIs and I’m conflicted with how I feel about the new system. I like the fact that the GUI is entirely driven by gameobjects. But the interface for plugging in values and functions is severely lacking. I can’t pass more than one variable per function and I can’t use arrays or lists. Which leads me having to type in the exact same function with multiple times but for different variables and the inability to recycle my functions really gets under my skin. The old GUI system didn’t have these issues. The fact that the old system has been relegated to legacy status really concerns me since that means the Unity team will not be updating it. I hope that the Unity team will be addressing these concerns with the new GUI system in later iterations of 5.0 .

You could probably create an editor script that does it. Just pass in a comma delimited string, and split it in your function.

You did notice the EventSystem right? You can do a custom component to trigger whatever functionality you like.

The UI system is VERY easy to extend. Simply make a MonoBehaviour script that implements IPointerClickHandler and implement the OnPointerClick method. You can either see this documentation for how Button does it: Unity - Scripting API: Button or you can go to their Bitbucket repo and see exactly how they did it. It’s all in C# and all open source (https://bitbucket.org/Unity-Technologies/ui or https://bitbucket.org/Unity-Technologies/ui/src/fd5d3578da8c33883b7c56dd2b2f4d4bbc87095b/UnityEngine.UI/UI/Core/Button.cs?at=4.6)

1 Like

Except nobody ever said that. The OnGUI system is used heavily for the editor; everyone who makes editor utilities uses it all the time. The newer system (from 4.6, it’s not new in Unity 5) is a visual system for in-game usage and can’t be used for making editor stuff.

–Eric

2 Likes

Can you give some examples? I’ve only used it in one project so far, but I’m not seeing how this is an issue. It’s object-oriented rather than immediate-mode functionally driven… is that where the issues are arising?

I don’t quite understand, how could I call multiple variables, arrays or lists with a string? Can you call variables by their name? Could you give an example of what you mean?

I’m not talking about how you trigger a function. I’m talking about the variables you can pass through a function that the triggers will accept. The triggers only accept functions with exactly one variable. Not multiple variables, arrays or lists.

Yes, in the previous GUI system you could use as many variables as you needed. Whereas with the triggers they only accept functions with one variable. They don’t accept functions with two or more variables, arrays or lists.

If the triggers don’t meet your needs, its absolutely trivial to roll your own. I would tell you how, but I’ll just quote this guy instead.

1 Like

Ok so I could go over to their Github page, fork say the button’s script for example, implement my features in the button’s script and bring it back into Unity? Is that correct?

Can you give some code of what you want to do? You can still use as many variables as you want, you just use them differently.

No, look at it, understand it, and do something equivalent in your own code. Don’t just copy-paste stuff.

In its most primative you could go something like 1|Red|Blue

Then when you get the parameter you would just do a string split using the “|” symbol, so you got 3 values, 1 red and blue

Or just make a dictionary of arrays, or custom objects, or string/int/key references to other objects, or wrap the event, or extend it, or replace it, overload it, or add a listener, or use delegates, or stick a value in a variable that other some other class checks on Update() and executes a different method based on that string, or use Text to output to an element offscreen with a camera using rendertexture to convert it to a texture2d, which through either a third party or plugin you can OCR back into text in another method, or convert the string to a binary value of some sort, have it flash the screen black and white based on that value, then have arduino with a light sensor taped to the monitor that can read the flashes, convert it into json/xml and then use a predefined twitter account which it is posted to, and monitored by another class in your app that uses that twitter account to receive instructions.

Basically, as @Aiursrage2k and @angrypenguin were getting at, be creative and find or ask for a solution. There are a hundreds of ways to do what you want. You can write it off as a disappointment, or you can build a game. Also consider looking into design patterns and or looking how others attempt to do the same things. Passing arrays and/or multiple values via buttons probably can be done in a cleaner way.

4 Likes

Most optimum solution ever!

That said I am currently designing a solution that takes a mV electrical signal, converts it to a fibre optic pulse, converts it to a 4-20 mA electric current, converts it to a bit, copies that bit to another bit, converts the bit back to a 4-20 mV electric, converts that to a pneumatic signal, which finally actuates a valve stopping the flow of liquids that I actually care about.

No jokes, this is an actual live project for work.

It gets even more complex as soon as I call safety. Then each part of the loop is self checking, basically sending a signal back to itself at a regular frequency to make sure nothing has broken. And the whole thing is only allowed to experience a fault once in one hundred years.

I’ve been using the new UI same as the old UI. The only difference is that now the class of menu functions is sitting on the parent of the GUI system in game rather than running in a main script’s OnGUI function. Every single button in my game calls buttonPressed and passes it an int from 0 to the number of buttons on the page. There are 2 switch statements. 1 in buttonPressed to determine which menu is open (switch over menuState) and then another in a function that has a switch to determine which button was pressed and what that button does for that menu.

menuState 0, buttonPressed(0). This is my play button. MenuState 1, buttonPressed(1). This is my exit button. menuState 3, buttonPressed(4). The 4th button on my 3rd menu is usually the exit button on a pause menu :smile:

It’s a small set of numbers to keep track of and the code is easily reusable. My only issue with the system during 4.6 was dynamically adding content to the GUI because the scaling would be out of control and there would be endless error messages. But I found that if you just make a prefab of a RectTransform / Transform out of an object that had the GUI as a parent, you can instantiate that at runtime without errors. You might need to set the scaling, still, but it works.

Ok initially when I started this thread I thought I was confined doing things in one particular way with the new GUI system. Glad to see that’s not the case. Also where is Unity’s Github GUI page?. I tried searching unity3d github ui and I found projects for Unity but not anything pointing to Unity Technologies specifically. I want to see what they did with their code so that I may be able to build my own.

https://bitbucket.org/Unity-Technologies/ui

Sorry, forgot it was on Bitbucket because almost everyone uses Github!

The point is its pretty trivial to figure out a solution for it.