Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

[Questions/Thoughts] Unity 4.6, the new UI system

Discussion in 'UGUI & TextMesh Pro' started by Maisey, Aug 20, 2014.

  1. Maisey

    Maisey

    Joined:
    Feb 17, 2014
    Posts:
    302
    Well, for me personally I know it will be better since I've been working with constraints for >2 years, both Apples implementation and my own for Unity+NGUI (which of course is more limited than Apples). However since you misinterpreted my claim that it could be better for more people than just me (solely), I changed it to "maybe".

    About the first, no, this is not about me trying to look like a bigshot (which you somehow think), it's about me (and others) not having to add custom "haxx-code" to do such a trivial thing as setting the width & hight of a Rect, which is the core component for all new UI-elements.. The support is obviously there since we can do it through the inspector.
    So yes, it makes me slightly annoyed to say the least that someone internally said "No, they shouldn't be able to set width/height from code, because I say so" (this quote is fake and just an exaggeration to prove a point.).
     
    Last edited: Sep 2, 2014
  2. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,217
    Why not just write a helper / extension method for this that internally maps to sizedelta / anchored position?
     
  3. Maisey

    Maisey

    Joined:
    Feb 17, 2014
    Posts:
    302
    I did.
    The argument now is more around why you haven't implemented it already since it's extremely trivial but useful and what you expose in the inspector is usually what one expect to be exposed in code. And hopefully that you just implement it because... why not?

    Custom helpers/extensions relies on implementation details which (especially for a beta) may change or under certain circumstances behave differently than what you expected when you developed it "4 months ago".
     
  4. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,888
    All objects in Unity are anchored in some way, for regular Transforms there's just no control over how the anchoring works, so there's no setting for it. Things are always anchored to the origin of the parent.

    For RectTransforms you can specify which point inside the parent it's anchored to, but nobody are forcing you to change it away from the default. So just leave the anchors at their default and set the size (exactly!) with the sizeDelta property. If this is not satisfactory to you, then I'm afraid there's nothing we can do about that.
     
  5. Maisey

    Maisey

    Joined:
    Feb 17, 2014
    Posts:
    302
    As I stated before I've already gone for that implementation temporarily (I hoped), so now I'm just displaying my disappointment. :)
    The reason I'm nagging about this is that it limits the ability to extend. Sure, I can go around it, which would be expected if I did something very specific for only my needs. But being able to "disable" anchors (thus forcing them to be "default") and setting width & height is nothing you should have to trick around.

    Obviously I can't convince you, so all I can say now is: Please don't force anchors. You can't expect all users to rely on them, and therefore it should be optional in an easy "enable/disable"-matter (making it faded out in the inspector maybe?), and if disabled they behave just as the normal Transform. I can't see how this would cause issues on your end...

    Anyways, guess there is no need to continue this discussion. Thanks for your replies!
     
  6. techmage

    techmage

    Joined:
    Oct 31, 2009
    Posts:
    2,133
    So I am wanting to do something where I will have a UI in the scene. Then I will have a bunch of physics collider objects I want to tap and drag around. Is it ideal to use the event system for all of this? Can I stack ray casters in such a way that it will ray cast for GUI elements first, and then ray cast for collider objects in the 3D scene only if it doesn't hit a GUI element?

    Could I also dynamically rework this order? So that one moments its testing for GUI ray cast hits first, then another moment its testing for scene collider hits first?

    Also, how long till 4.6 is actually released? I am just starting on a new project due in maybe a month that could heavily benefit from all this and am debating if I should just run for it with the 4.6 and hope the final 4.6 is out in time... Can the current 4.6 build to iOS just fine?
     
  7. goat

    goat

    Joined:
    Aug 24, 2009
    Posts:
    5,182

    Well I for one would like Unity to use their art department to make out of the box Unity UI that look like:

    1) MS XBox
    2) Sony PS
    3) Nintendo
    4) MS 'Metro'
    5) Android 4.#
    6) iOS
    7) Unity Unifying Game UI

    & the game player / app user can change to their 'comfort' gui. Seems a trivial thing to ask for after 5 years of waiting and a headache remover.

    but really I've yet to see a gui better then the old TWM gui I copied off someone way back. I think it was wheat on sea green.
     
    yoonitee and Maisey like this.
  8. Danirey

    Danirey

    Joined:
    Apr 3, 2013
    Posts:
    548
    Hi,

    another question about the raycast physics. I've tested it using a cube with an event trigger. It works fine. Then i move the screen to place a 2d ui button over the box position, just for testing, and set to block 3d objects for the raycasting. And it works great. But the question is, how can i check, let's say the tag of the box raycasted? If i want to change the ui sprites according with the tag of the box clicked... is it possible using that, or should i make a raycast check through code as usual?

    Thanks!
     
  9. CelestinLoup

    CelestinLoup

    Joined:
    Aug 24, 2014
    Posts:
    3
    You don't have to make a new raycast check, there's a lot of data attached to the PointerEventData structure (no documentation on it yet I think, but using your code editor, you can find what is available), including all the classic raycast data.

    For instance eventData.pointerPress.tag will give you the tag of the object clicked.
     
  10. Danirey

    Danirey

    Joined:
    Apr 3, 2013
    Posts:
    548
    Ok!

    Maybe i was doing something wrong, but inside the event functions(onPointerEnter) if i try to get these data with eventdata.whatever, it throws me an error, i don't remember what exactly. I'll try again.

    Thanks!
     
  11. yoonitee

    yoonitee

    Joined:
    Jun 27, 2013
    Posts:
    2,363
    Perh
    Perhaps the various art departments of these companies would supply Unity with a GUI skin with their own style. That would be the best solution. It's win-win since it would keep the various companies happy and also keep the developers happy. Is this an option?

    You could make it so that the IOS skin, for example, would only be allowed in IOS apps. And you could set different skins for different builds. It would make all apps tailored to each market while also keeping the build-once deploy anywhere philosophy. Just an idea.
     
  12. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I'd almost like to see the default GUI skin be as bad as possible, so people are forced to make their own. Too many times I see otherwise nice Unity games that stick out like a sore thumb solely because they used the default GUISkin, which actually isn't a bad look for the most part, but it's just so...default.

    --Eric
     
  13. goat

    goat

    Joined:
    Aug 24, 2009
    Posts:
    5,182
    That's been done already. Haven't noticed?
     
  14. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Nah, it could still be made more bad. ;) Right now it's bland but serviceable.

    --Eric
     
  15. Maisey

    Maisey

    Joined:
    Feb 17, 2014
    Posts:
    302
    Looking at the tutorials I see handles for resizing the rects directly in the scene, but mine are not showing/disabled... Couldn't find a setting for it, anyone know?
     
  16. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Make sure the rect handles transform tool (in the toolbar) is selected.

    --Eric
     
  17. Maisey

    Maisey

    Joined:
    Feb 17, 2014
    Posts:
    302
    Haha, of course! The most obvious place is some times the last you look at, right? :D

    Thanks! :)
     
  18. yoonitee

    yoonitee

    Joined:
    Jun 27, 2013
    Posts:
    2,363
    no.

    All that would happen is there would be a lot of Unity Games out there with the Unity logo on the splash screen with really really bad looking GUI. Not a very good advert for Unity!

    Just make a default GUI that is very customisable i.e. different fonts for buttons, drop shadows, highlights, different size rounded corners, etc. So that every "default" GUI would look good but different.

    The thought of the human race wasting all those man hours designing 999,999 individual GUIs - which are essentially the same just with different gradients in the buttons - when those man hours could instead be used to find a cure for the common cold is depressing. Next time I get the flu, I'm blaming Unity.
     
  19. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    If all you're doing is changing the gradient, you're doing it very very wrong. Different GUIs do need to be created individually if you actually want them to have any character and to work visually with your game. Non-game apps may be a different matter.

    --Eric
     
    ortin likes this.
  20. Taschenschieber

    Taschenschieber

    Joined:
    Jun 8, 2014
    Posts:
    238
    Go play Civ V, or Deus Ex HR, or Thomas Was Alone, or Hearthstone, and imagine how those would look with Windows OS buttons. Bonus points for using the legacy theme (the one from Windows 95 upwards).

    (I wish I had actual photoshop skills just so I could shoop Hearthstone as it would have looked back in '95.)
     
  21. Maisey

    Maisey

    Joined:
    Feb 17, 2014
    Posts:
    302
    So just some quick clarification: I've made a custom PropertyDrawer, call it CustomDrawer, which if I understand the concept correctly will be instantiated and used as a sub-drawer when the inspector draws a specific type (in this case my custom class, serializeable). All fine and dandy, it instantiates the drawer and calls OnGUI. Now to the problem...

    When my CustomClass is used in a List "m_List" in a monobehaviour and that monobehaviour is drawn, it will again use my CustomDrawer but the SerializedProperty passed will on the first call (each time selected) be the actual list, thus property.name will print "m_List". This will give me issues using property.FindPropertyRelative since well, it is not my CustomClass being passed in the SerializedProperty, it is be the Collection holding my CustomClasses...

    Obviously (I sincerely hope) this is faulty behaviour, since I must be able to expect that the SerializedProperty being passed to my CustomDrawer contains the object of the actual type the PropertyDrawer was created for...

    Followup question: How do I access the actual object-reference for the property? I want the equivalent of serializedProperty.serializedObject.targetObject but instead of getting the monobehaviour the LIST belongs to, I want to get the object of my CustomClass that the PROPERTY belongs to... Reason being that I want to expose my properties (actual C# properties, not basic fields).

    Sorry for the wall of text, and hopefully I've just missed something obvious in the latter, and that this solution is not necessary. In that case I'll cry.

    Edit.
    Okey, I've found how to reproduce the issue in the first part. It has to do with using a custom editor for the monobehaviour that holds the list of "CustomClass", and then having a custom PropertyDrawer for "CustomClass". I've attached a repro. Add an element to the list and deselect/select the gameobject and you'll see the issue. My bug report from yesterday can be found HERE.
     

    Attached Files:

    Last edited: Sep 9, 2014
  22. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,888
    Great, can you please submit the bug through the bug reporting system. That's where we keep track of bugs; we don't keep track of bugs reported in forum threads. Thanks!
     
  23. Maisey

    Maisey

    Joined:
    Feb 17, 2014
    Posts:
    302
    Well I can't access the submitted bug report and add the repo (don't have the login), so my thought was that you'd do it, instead of me sending a duplicate submit! :)

    How about the latter part... Is there no way for me to access the actual object which was serialized? That is, the bottom most object which is the property the drawer was created for? I know this goes against the serialisation-logic, but I need to invoke setters/getters on REAL properties, not fields (get notified about changes etc.).
     
    Last edited: Sep 9, 2014
  24. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,642
    When you submitted the bug initially, you should have been sent an email with a bug number; you can reply to that mail and attach the package.
     
    Maisey likes this.
  25. Maisey

    Maisey

    Joined:
    Feb 17, 2014
    Posts:
    302
    Thanks! Will do that.
     
  26. Ramcat

    Ramcat

    Joined:
    Aug 16, 2014
    Posts:
    95
    Could we get a code example of that? I'm trying:

    Code (csharp):
    1.  
    2. public GameObject _Generator; // with this being set to my prefab in the editor
    3. GameObject aObject = (GameObject)Instantiate (_Generator, position, new Quaternion());
    4.  
    This would work in a game but does not in the new UI.
     
  27. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,888
    Have a look at these two pages:
    http://docs.unity3d.com/460/Documentation/Manual/UICanvas.html
    http://docs.unity3d.com/460/Documentation/Manual/HOWTO-UICreateFromScripting.html
     
  28. Ramcat

    Ramcat

    Joined:
    Aug 16, 2014
    Posts:
    95
    Thanks for those pages. I'm a little sad that Unity has no code examples. Is that reserved for paid accounts?

    Code (csharp):
    1.  
    2. using UnityEngine.UI;
    3. public Canvas _Canvas; // canvas reference set in editor
    4. public GameObject _Generator; // with this being set to my prefab in the editor
    5. GameObject aObject = (GameObject)Instantiate (_Generator, position, new Quaternion());
    6. aObject.transform.SetParent (_Canvas.transform, false);
    7.  
    Says more than both those pages put together.
     
  29. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,888
    No, absolutely not. :)

    But we have limited resources and at the moment we're spread thin between fixing bugs and issues, writing documentation, and answering forum posts. We haven't gotten around to much code examples yet, but hopefully we'll get there.

    There have however been plenty of code examples very similar to the one you just wrote in a lot of the threads here on the forum, many of them in threads with descriptive names containing words like Instantiate and Scripting, and similar. I would recommend searching a bit.
     
  30. Ramcat

    Ramcat

    Joined:
    Aug 16, 2014
    Posts:
    95
    The only reason I am responding is because I have an idea to improve your support and the forum, and because you helped me solve my problem.

    If a person adds the text 4.6 to the search text limit all search results to after the date of the 4.6 beta release. When 5.0 comes out do the same.

    If you *think* I have not been using every search tool I can find you are mistaken. The keywords you gave me return no 4.6 results for 3 pages of results. There are mountains of posts from older version and google and duck duck go do little better to filter the clutter. I have searched, read, and watched every video I can find studying the new UI to the tune of 50 hours over the last three weeks. I have little prior experience with Unity so I am learning it all in one shot.
     
  31. Abion

    Abion

    Joined:
    Sep 13, 2014
    Posts:
    2
    I'm having a difficult time trying to imagine how a UI with anchors disabled would be functionally different than one where a UI element is anchored to the parent's (or window's) origin. I mean, if I were to take some UI element in some UI framework and set it's position to (25, 25), that location would typically be relative to the window's "origin", generally being the top-left corner, and as such would behave as if the element were implicitly anchored to that origin point.

    And if the "fix" for being unable to set the width and height of a UI element is to set the right and bottom values to "left + width" and "top + height" respectively, then I don't see why this is such a deal-breaking "flaw" as to ditch the new UI's layout system altogether and make an in-house/third-party solution. It seems like a lot of work for little gain over something so trivial.
     
  32. Maisey

    Maisey

    Joined:
    Feb 17, 2014
    Posts:
    302
    I don't expect people to see the gain right away, but how this new anchor-system works it is ALOT more cumbersome than a constraint system, where you can easily setup UI-elements relative to parents, siblings & children. This is a deal-breaker for me, since for projects where the UI is a "work in progress", it takes to much time fine-tuning the layout with the current anchor system.

    If Unitys way works for others, great! But I've been working with constraint systems for different platforms for years and the difference in what and how easily you can do stuff is huge. So for me personally, it is definitely worth the extra initial development-time. :)
     
  33. rakkarage

    rakkarage

    Joined:
    Feb 3, 2014
    Posts:
    683
    if you click "search forums" link you can choose which sub forum to limit your search too
     
    Ramcat likes this.
  34. Maisey

    Maisey

    Joined:
    Feb 17, 2014
    Posts:
    302
    When rotating the device (iOS), there is now an option to "Use Animated Autorotation". I don't know how this works internally in the OS, but is there no way for you to make this option actually "animated" the screen-size?
    As of now, you just change the rendered texture instantly (but leave the animation to iOS) so during the animation all UI is all stretched out (since it's already its "correct" size before the animation starts, but fitted inside the screen-rect being animated).

    I'll turn this off for now but it would be nice if it worked the way one expect it to!

    Thanks!
     
  35. holyjewsus

    holyjewsus

    Joined:
    Mar 7, 2011
    Posts:
    624
    I'm having a tough time figuring out how to send selectable transition states to 3d Gameobjects, I seem to need a graphic object on the object as well as selectable, so this means I need to hide an image under my mesh to send it events? Is there no current or planned way to use 3d objects as UI elements?
     
  36. holyjewsus

    holyjewsus

    Joined:
    Mar 7, 2011
    Posts:
    624
    to answer my own question, you just need to add a physics ray caster to the camera, and then it seems that non graphic item objects will receive the appropriate events that selectable is looking for to drive an animation controller.
    nice.
     
    superpig likes this.
  37. FuzzyQuills

    FuzzyQuills

    Joined:
    Jun 8, 2013
    Posts:
    2,871
    I have just licked up 4.6 today, and I have to say, I am impressed!!! :D :) ;) :p

    NO MORE onGUI FOR ME!!! :D
     
  38. FuzzyQuills

    FuzzyQuills

    Joined:
    Jun 8, 2013
    Posts:
    2,871
    @goat: A Nintendo 3DS based UI would look awesome! :)
     
  39. FuzzyQuills

    FuzzyQuills

    Joined:
    Jun 8, 2013
    Posts:
    2,871
    ...and I might as well show this off:
    NewUIExample.png
    Will post a better-looking shot soon. Still have to get to grips with EventSystem... :D
     
  40. yoonitee

    yoonitee

    Joined:
    Jun 27, 2013
    Posts:
    2,363
    I've had a go with the anchor system. And to me it's still a dark art. I have no real clue what I'm doing. Except that if I want to anchor it to the top I drag the anchors to the top. That's about it. Then when I think I've got it just right, I stretch the window and it all goes haywire. A bit of experimentation and I can usually get it right.

    I don't really like the hollow "flower" icon for the anchor. It doesn't seem substantial enough.

    What if I want to position a box with margins 10px above and below the parent. Where do I put the anchors and will the anchors move if I stretch the parent window?

    Also, moving the anchors is very fiddly. Especially if they are over the rect transform box.

    I'm sure I'll get use to it. Is there a detailed instructions or PDF that outlines the equations used by the anchors?

    Another thing that I'd like is if you messed up your anchors and all your panels are misallgned to be able to rest them to a previous state.

    Things I CAN do quite easily is for example set the score to stay in the right top corner for all screen sizes which otherwise I would have to do with script. (The script for that is not rocket science but it is nice to see it in the editor).
     
  41. the_motionblur

    the_motionblur

    Joined:
    Mar 4, 2008
    Posts:
    1,774
    Rule of thumb - if you keep the flower together the thing you anchored will stay the same size you created it in and roughly relative to where you put it. The farther you stretch it the farther the thing will stretch if you blow it up in resolution.

    The more complicated you cascade stretchings to the child objects the faster you will probably lose overview over what is anchored where.
     
  42. asotelo94

    asotelo94

    Joined:
    Jan 26, 2013
    Posts:
    14
    Anyone knows what happened to the 'Reference Resolution' component of the beta version? where is it now, if there is any. It was really helpful
     
  43. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
  44. asotelo94

    asotelo94

    Joined:
    Jan 26, 2013
    Posts:
    14
  45. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,888
    Yeah, the second page in the UI Overview section of the manual has something like that.
    http://docs.unity3d.com/Manual/UIBasicLayout.html

    Doesn't include "equations" but that shouldn't be needed either.
     
  46. Rodolfo-Rubens

    Rodolfo-Rubens

    Joined:
    Nov 17, 2012
    Posts:
    1,197
    I'm wondering if there will be any support for multiple languages in the future, also, if there is any way to lock the anchor on the rect bounds..
     
  47. yoonitee

    yoonitee

    Joined:
    Jun 27, 2013
    Posts:
    2,363
    Thanks. I watched the Rect Transform UI video and it cleared things up. I think it would have been clearer with more visual clues in the UI when editing such as dotted lines between your rect transform and the anchors showing the margins in pixels. Like other layout systems have. |-----[ ]-----|
     
  48. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,888
    There is exactly that when you drag a UI element:

    DottedLines.png DottedLines2.png
     
    the_motionblur likes this.
  49. yoonitee

    yoonitee

    Joined:
    Jun 27, 2013
    Posts:
    2,363
    Oh yeah. So there is! But they should stay on screen when resizing the parent element so you can see which distances have been constrained. IDK. It just doesn't seem that clear as it stands. They disappear when you've finished dragging.

    Also, to be nit-picky, the numbers on the vertical lines don't need to be vertical. Are we supposed to turn our head sideways to read it? Perhaps also they should round off to the nearest whole number or 2 decimal places. I'm getting numbers like 74.499999. The lines don't show up that well on a white background too. Also maybe the lines could have little arrow heads at the ends. Just my humble opinions. :)
     
  50. NekitB

    NekitB

    Joined:
    Dec 19, 2014
    Posts:
    1
    Greetings everyone, I have a question on the 4.6 EventSystem performance. I really like the new UI namespace it's awesome in every aspect for designers, and coders.

    I'm trying to implement a simple page slider with a swipe/drag (like desktops in iPhone) using a ScrollRect with a HorizontalLayoutGroup as a content object.

    But I have encountered a little performance problem:
    A GameObject with a ScrollRect component is rendered at 1500 fps rate
    http://prntscr.com/5ipd9j
    Having mouse pointer on the screen drops frame rate to about 500 fps
    http://prntscr.com/5iper6
    When dragging it goes down all the way to about 100 fps
    http://prntscr.com/5ipfh6

    While this is sustainable on PC, there is a notable lag on a simple Android devices, and makes a ScrollRect unusable for a content slider.

    Are there any quirks or recommendations on correct usage of this EventSystem + ScrollRect + HorizontalLayoutGroup thing. How would you implement instead. Thanks.

    P.S. Please let me know shall I start a new thread on this matter