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
3
Question by Gumpert · Jan 01, 2013 at 05:34 PM · gameobjectdisableactiveactivate

How to disable gameobjects in code?

Hello there, my friends! I was having a bit of trouble deactivating gameobjects, which really was rather inconvenient! In the Unity scripting reference page, they claimed that this piece of code would deactivate a gameobject as soon as the scene was loaded:

gameObject.SetActive (false);

However, I was rather disappointed when I discovered that the code was completely ineffective! What a shame! Well, I looked all over the place, and simply couldn't find out how to do it! How silly! So if anyone knows how I can create a boolean variable, which controls another different gameobject from being activated, please tell me, it would be greatly appreciated!

Many thanks indeed, and may you all have a jolly spiffing day!

Taliho!

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 Gumpert · Jan 01, 2013 at 04:35 PM 0
Share

Also, I forgot to mention - assu$$anonymous$$g that I fix this problem, would it deactivate the gameobject and its children, or just the object itself?

avatar image Fattie · Jan 01, 2013 at 05:42 PM 0
Share

Tally ho!

Are you using Unity 3 or the new Unity 4 ?

It's a tad different in each ...

avatar image Graham-Dunnett ♦♦ · Jan 01, 2013 at 05:58 PM 0
Share

gameObject.SetActive() works for me completely as expected. Want to share your code?

avatar image markzareal · Oct 24, 2014 at 11:39 AM 0
Share

For some reason gameObject.SetActive works fine for me. Try gameObject.active = false (it is the old way of doing it even though you get a warning saying it is obsolete but just try it anyway) Hope it helps you in someway ;)

4 Replies

· Add your reply
  • Sort: 
avatar image
8

Answer by brimby · Aug 27, 2014 at 05:53 PM

I think things have changed since the original question was asked, because SetActive() works fine for me. And conversely, the enabled property and the function SetActiveRecursively() do not exist on GameObject anymore.

Comment
Add comment · Show 6 · 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 DZapdos · Oct 23, 2014 at 05:10 AM 0
Share

I have also had the same issue. The enabled property no longer exists and SetActive() should be used ins$$anonymous$$d.

avatar image brimby · Oct 23, 2014 at 04:23 PM 0
Share

@DZapdos then you should up my answer so people see that the other answers here are out of date.

avatar image DZapdos · Oct 24, 2014 at 10:54 AM 0
Share

@brimby I tried, but I don't have enough rep

avatar image brimby · Oct 24, 2014 at 04:49 PM 0
Share

@DZapdos $$anonymous$$e too haha. Sad.

avatar image markzareal · Oct 24, 2014 at 10:37 PM 0
Share

I did it for you guys :D

Show more comments
avatar image
1

Answer by Theacesofspades · Jan 02, 2013 at 01:17 AM

use

 enabled = false;

or

 SetActiveRecursivly (false);
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 Hank Moody · Aug 14, 2014 at 07:30 PM

gameObject.renderer.enabled = false;

Should do it

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 FirePlantGames · Oct 24, 2014 at 11:43 PM

This should work...

 function Start()
 {
     gameObject.SetActive(false);
 }
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

14 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

Related Questions

How do I set a reference in the inspector 1 Answer

How to active/deactive gameobject? 1 Answer

how to make my gameobjects disable and enable? 2 Answers

How to make an open and close box?,How to make open and close a box? 0 Answers

If you disable a gameobject, does an InvokeRepeating loop end or pause? 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