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 azin_psp · May 20, 2015 at 09:43 PM · renderer.enabled

Make UI elements invisible

I need to make a UI button invisible, but not by the command SetActive(false) because I need a script on it to run. I tried below commands but none of them works, seems they are obsolete or wrong

 UIButton.renderer.enabled=false;
 UIButton.CanvasRenderer.enabled=false;
 UIButton.GetComponent(CanvasRenderer).enabled=false;
 UIButton.GetComponent(Renderer).enabled=false;

It seems there is no enabled property for renderer or canvasRenderer in Unity 5. any solutions?

Comment
Add comment · Show 1
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 Fattie · Jan 31, 2016 at 04:49 PM 0
Share

BTW if you want an "invisible (working) button" .. here:

http://answers.unity3d.com/answers/851816/view.html

4 Replies

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

Answer by DiegoSLTS · May 21, 2015 at 12:46 AM

I usually do this to hide UI stuff:

Add a Canvas Group component to the root object you want to hide (just the root, the childs don't need the component)

Setup a reference to that Canvas Group on the script that should hide the UI element.

Say you named "canvasGroup" the reference to the Canvas Group component, then call this code whenever you want to hide it.

 void Hide() {
     canvasGroup.alpha = 0f; //this makes everything transparent
     canvasGroup.blocksRaycasts = false; //this prevents the UI element to receive input events
 }

Do the opposite to show it again

 void Show() {
     canvasGroup.alpha = 1f;
     canvasGroup.blocksRaycasts = true;
 }
Comment
Add comment · Show 4 · 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 Miguel_Mateus · Apr 10, 2016 at 05:53 PM 0
Share

How do you make a reference on the script? @DiegoSLTS,How do you set a reference?

avatar image DiegoSLTS Miguel_Mateus · Apr 10, 2016 at 06:06 PM 1
Share

There are multiple ways to do this. The easiest is to have a public or serialized member on your script (in my example, a member called "canvasGroup" of type CanvasGroup) and drag and drop a game object from the editor with a CanvasGroup component on the field you see in the inspector. Another common approach is using the "Find" or a similar method to get the game object you want from the scene and assign it to the "canvasGroup" member.

avatar image Mazer83 · Jul 17, 2017 at 09:08 PM 0
Share

Adding a CanvasGroup to an InputField object makes it uninteractable. I tried it, and I can no longer enter any values.

avatar image Gloryiam · Apr 19, 2019 at 03:39 PM 0
Share

Very helpful - exactly what I needed since I have UI windows with scripts attached that need to be active at all times. Thank You!

avatar image
6

Answer by jrjr · May 21, 2015 at 01:01 AM

Set scale to 0,0,0 also works in most circumstances (can cause some issues if you've got complex 3d objects in a world camera usage though). You just set it back to its live scale whenever you want it 'enabled'.

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 Will_Croxford · Jun 01, 2018 at 08:38 PM 0
Share

I think this is a neat, clever and super simple solution, I'm fairly new Unity but imagine this very low performance impact, I'm using it for a points display which I want to hide at certain times. For newbies, possible code like: Vector3 blessScale = blessingPoints.GetComponent().localScale; blessScale = new Vector3(1,1,1); blessingPoints.GetComponent().localScale = blessScale;

then to hide it, same as above with (0,0,0) ins$$anonymous$$d. if a solution this simple will do, no need to create extra methods or object holders.

avatar image
2

Answer by DarthHawk13 · Dec 26, 2016 at 09:46 PM

I created a Youtube video which answers this question

https://www.youtube.com/watch?v=iwxWrx98RfI

Essentially you add a Canvas Group component to the Canvas with the controls you want to make invisible and access the Canvas Group in code and make it invisible and/or not interactive.

     CanvasGroup.alpha = 0f;
     CanvasGrouop.interactable = false;
     CanvasGroup.blocksRaycasts = false;

You can have multiple Canvas objects with different controls occupy the same area on the screen.

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
1

Answer by cjdev · May 20, 2015 at 10:45 PM

You could try making a new tag assigned to the buttons you want to be invisible and excluding them in a custom layer. If you use that layer on your camera it should render everything but the UI elements with the new tag.

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

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

10 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

Related Questions

Renderer.enable for GameObject[]? 3 Answers

animation.speed does not work when disabling/enabling renderer 1 Answer

Gameobject with many child objects disable mesh not working. 0 Answers

Keypress.ismine? 0 Answers

Cannot select Animation Event 3 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