Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
4
Question by HuskyPanda213 · Aug 27, 2014 at 04:20 PM · ui4.6

What is the "correct" way to switch UI panels - 4.6?

What is the correct way to switch between UI panels in the new UI system? For example: I have a menu, it has 4 sub-menus--the default one (play, options quit), the play menu (character/save selection), the options menu (graphics, etc.), and confirm quit menu. Now, what is the correct way to switch between these sub-menus? Should I just disable and enable the objects or do something else?

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Subzero619 · Aug 27, 2014 at 06:32 PM 0
Share

What I've seen is that the animation window is used for these and they fade them in and out. It's pretty cool and works pretty good as a "correct" way.

avatar image Bentoon · Aug 30, 2014 at 04:20 AM 0
Share

@Sub Can you explain further?

7 Replies

· Add your reply
  • Sort: 
avatar image
11

Answer by junglemason · Mar 17, 2015 at 11:07 PM

My preferred way is to assign a CanvasGroup component to anything I want to show/hide. I leave it in its position, and just set the alpha and can toggle whether it accepts user input. All the properties of a CanvasGroup are automatically applied to all of its children (unless the child is a CanvasGroup that is set to ignore its parent).

  • I don't have to worry about screen size when moving something off-screen to hide it.

  • I will always have access to its properties since the GameObject is never deactivated.

  • I can use the Alpha property of the CanvasGroup to fade the element in and out.

  • I can easily make that UI element and all of its descendants temporarily not receive input while still being visible.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image VipHaLongPro · May 12, 2015 at 12:37 PM 0
Share

I don't believe in performance of CanvasGroup. It must have something costly to do. Otherwise it should have been added by default. New UI System is terribly bad in performance. It's good in almost cases for interactive UI whereas we don't need really many panels. But in some cases when the number of panels is fairly large, the performance drops seriously. If you have 1000 of static panels, it's still O$$anonymous$$. But when any UI element (on the same Canvas) changes (position, scale, text, ...) it can drop the framerate from 60 to just about 20-30. Terrible design. Think about showing animated text (damage text) when enemy is hit by many bullets. I'm currently using panels to hold Texts (having an Animator). I spent a few hours finding out how it goes bad that way. I'm still trying to improve it but finally I would not use panels to wrap Texts (and won't be able to use Animator).

avatar image TheOz · Jun 18, 2017 at 01:37 PM 0
Share

Now that everyone is on 5.6. Is CanvasGroup still the way to go? Seems to work well for my puzzle game with simple ScrollList $$anonymous$$enu.

Anorak

avatar image amit-chai · Jan 17, 2018 at 11:16 PM 0
Share

Finally a good answer. Thanks!

avatar image
10

Answer by Kiwasi · Aug 27, 2014 at 07:50 PM

Multiple options exist. Each has its own benefits and drawbacks. As far as I can tell there is no definitive 'correct' way to accomplish this. If your menu is performance constrained then bench marking on your current device is required.

  • Enable and disable (this will cause OnEnable and OnDisable to run)

  • Instantiate and destroy (not recommended, will kill you on the GC)

  • Moving in the hierarchy so its rendered behind the current panel (causes an increase in draw calls)

  • Moving the inactive windows off screen, or disabling or modifying renderers (Good for animated effects)

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Razmot · Nov 20, 2014 at 03:08 AM 0
Share

$$anonymous$$oving inactive windows offscreen lets you see everything in editor, it's nice for designing a complex UI with tabs.

Problem is that unity ui doesnt'cull stuff out of canvas, see here http://forum.unity3d.com/threads/draw-call-not-reduced-when-ui-out-of-canvas.265170/

=> I'll just use a script to disable all the offscreen stuff on start!

avatar image Kiwasi · Nov 20, 2014 at 03:26 AM 0
Share

I tend to use the disable in start approach too. Sort of.

What I actually do is run a coroutine from Start to disable after one frame. That lets a bunch of scripts run GameObject.Find to grab the menu panels they are interested in before they get disabled.

avatar image
2

Answer by Bentoon · Aug 30, 2014 at 04:19 AM

Good Question. I am interested in BoredMormons 1st approach

I am not a C# person but it might look something like:

and then I think it could look like : void onSomeTrigger() { enable(panelOne); )

 void onEnable() {
 if(panelOne.Renderer.disabled) {
 panelOne.Renederer.enable;
 }
 
 }
 

(remember to instantiate the new UI in code)

EDIT: Thanks BoredMormon that would be great

here is another simple way:

 using UnityEngine;
 using UnityEngine.UI;
 using UnityEngine.EventSystems;
 using System.Collections;
 
 public class mouseUp2 : MonoBehaviour {
 
 
 
     public GameObject Panel2Disappear;
     public GameObject Panel2Appear;
     
 
 
     void OnMouseUp () {
         Debug.Log("MouseHit");
         Panel2Disappear.SetActive(false);
         Panel2Appear.SetActive(true);
     }
 
 }
 

Although I Love sub zeros idea of Animating the change... that would be brilliant!

best

~be

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Kiwasi · Aug 30, 2014 at 04:27 AM 0
Share

I'll post the actual code later on if you like. Not currently on my Unity computer.

avatar image Cal2 · Mar 05, 2015 at 11:38 PM 0
Share

So, I'm trying the same thing but am not getting it to work correctly. $$anonymous$$y UI buttons won't change in the game view, but will change in the scene view after I stop playing the game (or will show up changed when I start the game again).

The problem is on line 19 (the method $$anonymous$$enu$$anonymous$$enu). I have 1 canvas, with empties childed to it (what I'm turning on/off), and buttons childed to those empties.

 using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;
 using UnityEngine.EventSystems;
 
 public class UiButtons : $$anonymous$$onoBehaviour {
 
     public GameObject menu$$anonymous$$enu, start$$anonymous$$enu;
 
 
     public void Restart() {
         Application.LoadLevel ("$$anonymous$$all_And_Phone");
     }
     
     public void Quit() {
         Application.Quit();
     }
 
     public void $$anonymous$$enu$$anonymous$$enu(){
         print ("one");
         start$$anonymous$$enu.SetActive(false);
         print ("two");
         menu$$anonymous$$enu.SetActive (true);
         print ("three");
     }
 
     public void BackToStart(){
         start$$anonymous$$enu.SetActive(true);
         menu$$anonymous$$enu.SetActive (false);
     }
 
 }



avatar image
0

Answer by GXMark · Mar 28, 2015 at 01:31 PM

Canvas kills your performance if you have alot GUI controls. But ok for smaller GUI's

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by darshie1976 · Mar 19, 2016 at 05:02 PM

Keep in mind that hiding the panel changing the alpha of the canvasgroup is not deactivating the controls; you will discover that if you use the mouse while the panel is hidden, if you have controls on it, they will be reacting to mouse clicks for example.

So far the best way that I found to swap panels is to use both the alpha to make them hiddne, and at the same time, set to false the interactable to false, so even if you click on the screen you won't affect the controls.

I did not have luck with setActive(), but using this approach it works just fine

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
  • 1
  • 2
  • ›

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

32 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Showing text on top of a Slider, but not blocking Handler? 1 Answer

Android screen is small? 0 Answers

4.6 Button OnClick Super Sensitive to pointer movement. 1 Answer

How to change Normal color, Highlighted color etc. in 4.6 buttons with code 2 Answers

How to prevent raycast when clicking 4.6 UI? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges