Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 noscoars · Jul 18, 2017 at 06:58 AM · toggle

SetActive(true) is working, SetActive(false) not

Hey there

I'm new in developing C#/Unity and I have to make an app prototype for school with Unity (5.6.2.1f2) for HoloLens. I've completed the Gaze tutorial and this works well: holoacademy/holograms-210

So there's a assigned object in GameObject "ObjectToTagAlong" and the code in line 28 instantiatedObjectToTagAlong.SetActive(true); works fine: When an object is deactivated in Unity, this function shows the assigned object when I click on the "main object".

Now I have to not just do activate it, it also should be possible to hide it when clicked on the same "main object" or the assigned object itself -> like a "toggle". So I've tried instantiatedObjectToTagAlong.SetActive(false); which is not working to an object which has been set to visible in Unity before (the opposite procedure like the working one).

Can somebody explain me why SetActive(true) is working and SetActive(false) not? Or do you have a better solution to toggle game objects?

Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by tanoshimi · Jul 18, 2017 at 07:03 AM

If you just want to make the object invisible, you might want to disable its renderer rather than set the entire object unactive: https://docs.unity3d.com/ScriptReference/Renderer-enabled.html

However, there's nothing obviously wrong with your approach - when you say it is "not working", do you get any error in the console? Are you sure that section of code is even being called? You can toggle an object active/not with the following:

 object.SetActive (!object.activeInHierarchy);
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 AurimasBlazulionis · Jul 18, 2017 at 09:16 AM 1
Share

Wrong a bit, should be object.SetActive (!object.activeSelf);

avatar image noscoars · Jul 19, 2017 at 11:21 AM 0
Share

Thank you for your replies!

I didn't know this renderer. Disabling itself is working now, thank you.

Do you know how I can enable/disable another object like a 3D-Text with this renderer? I couldn't find a suitable solution, things like instantiatedObjectToTagAlong.GetComponent().enabled = true; did'nt work.

avatar image
0

Answer by noscoars · Jul 19, 2017 at 12:10 PM

So I've found a solution which works for me:

ObjectToTagAlong.gameObject.GetComponent().enabled

Thank you very much for your supply and I hope this works for other with the same problem.

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

68 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

Related Questions

Toggle button help 1 Answer

Aimdown Sights Toggle 1 Answer

Can't Get my 2nd Window to Open.. 3 Answers

Toggling multiple button states 2 Answers

Combine actions in if statement 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