Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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
0
Question by gustavopinent · Jun 03, 2019 at 09:00 PM · uicanvasvisibility

How to show and hide an ui canvas element in 2019?

I am now using Unity3D 2019, and I was already new in 2018... The task of hide and show elements of the game is tricky to me, depends on what is understood by "hide". I have a playable character that I change the layer to an invisible layer to hide it, and it works fine (I mask the layer 31 in the camera for this purposes). But I have a dialog balloon that is inside Canvas, that got it's own layer already, to hide all canvas is not an option so I will have to hide my text by other methods.

I did this research several times and there is a discussion about what is the best method to do so. Though changing alpha to 0 might work but might be not the best practice because it will be still processed every frame. Also there is some new features about it in 2019 version, but in the blog it is only related, there is not much of details...

So what is the best way of to show and to hide an ui element inside a canvas, by the perspective of 2019 version?

Comment
Add comment · Show 4
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 Hellium · Jun 03, 2019 at 09:10 PM 0
Share

What the problem with simply disabling the gameObject?

avatar image gustavopinent Hellium · Jun 04, 2019 at 02:24 AM 0
Share

If you disable the GameObject it won't be found anymore. You will have to use a special procedure to find it again and be able to manipulate it. It is possible but not practical, it was my first attempt.

avatar image Hellium gustavopinent · Jun 04, 2019 at 06:26 AM 1
Share

Since I've started Unity (about 5 years ago), I may have used the Find functions less than 5 or 6 time. There are a lot of workarounds to avoid using those functions. The simplest one is to declare a serialized reference to the gameObject and drag & drop the desired GO in the inspector. Then, no matter the GO is enabled or not, you have a reference to it.

Show more comments

3 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by SirPaddow · Jun 04, 2019 at 06:44 AM

I didn't hear of new ways to show/hide gameObjects in Unity2019. Basically, your objects are invisible as long as their Renderer / Graphics MonoBehaviour is disabled. For instance, you could do something like that:

 myDialogBalloon.GetComponent<Image>().enabled = false;

But it will only disable the background of your UI balloon. If what you want is to completely disable the UI element, you should consider deactivating the gameObject (which will disable all MonoBehaviours on it and on its children)

 myDialogBalloon.gameObject.SetActive(false);
Comment
Add comment · Show 1 · 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 gustavopinent · Jun 04, 2019 at 09:49 AM 0
Share

In my tests it works fine! I just ask you to add a warning in your answer that myDialogBalloon must be declared at the beginning or as public var and linked in editor in order to work with SetActive. $$anonymous$$any people I see to declare it only just before SetActive (as inside the Update), and in this case, myDialogBalloon won't be found if it was previously disabled (set as false).

avatar image
0

Answer by SirQuaid · Apr 14, 2020 at 09:51 AM

It's easy! Go to your Hierarchy and use the eye icons, which were previously in the Layers dropdown. Toggle the eye icons next to relevant GameObject(s) to hide them in the Scene but preserve them in the game.

Comment
Add comment · Show 1 · 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 gustavopinent · Apr 14, 2020 at 05:19 PM 0
Share

The point is to hide/show by script at runtime, not during edition.

avatar image
0

Answer by JayFiraja · Oct 14, 2020 at 07:44 PM

I suggest disabling the Canvas in some situations like the following...

Coroutines cannot start on disabled GameObject so if the canvas GameObejct is disabled then all its children will be as well.

So how about canvas.enabled = false; when hiding that canvas.

Setting alphas to 0 might "hide" a graphic but if it's an interactive button it's a hidden interactive element you might not want to be active for clicking on it.

Comment
Add comment · Show 1 · 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 jordancarey · May 03, 2021 at 06:26 PM 0
Share

Tried the canvas.enabled thing, it didn't work unfortunately.

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

188 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 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 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 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 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 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

4.6 UI Canvas is smaller than normal 1 Answer

Can't click or highlight a button. 0 Answers

[CANVAS] Coordinate transfer with scaling (pictures+details) 2 Answers

Select material of Canvas Renderer 0 Answers

camera space performance/ aligncanvasrecttransformwithcamera 0 Answers


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