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
2
Question by Tatanan · Apr 14, 2015 at 01:17 PM · gameobjecthide

Hide but no deactivate a gameobject

Is there any way to hide a GameObject without using setActive? I could disable the render component, but it has many children it's a bit complicated. Any idea?

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 TRG96 · Apr 14, 2015 at 01:19 PM 1
Share

set the position of the object very far away in the distance somewhere. where it cant be seen.

avatar image Owen-Reynolds · Apr 14, 2015 at 02:47 PM 1
Share

Changing all children is a "simple" recursive function. You should be able to find a written out example of SetActiveRecursively and modify it to check for and turn on/off a renderer. Unless you have some children who's renderer's should stay off (if you pre-loaded all optional parts.)

But yes, I also often just move them to Vector3.one*999.

3 Replies

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

Answer by Veldars · Apr 14, 2015 at 02:48 PM

For me the best way is to disable all renderer as you said but it's not really complicated ^^

 foreach (Transform child in transform) {
   child.gameObject.GetComponent< Renderer >().enabled = false;
 }
 GetComponent< Renderer >().enabled = false;

if it's really a huge object make a recurcive

 void Start() {
   recDisabler(transform);
 }
 
 private void recDisabler(Transform t) {
     if (t.childCount > 0) {
         foreach (Transform child in t) {
             recDisabler(child);
         }
     }
     t.gameObject.GetComponent< Renderer >().enabled = 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 Tatanan · Apr 14, 2015 at 03:06 PM 0
Share

Yes, I thought about this solution. The problem comes in the case I want to keep a child hiden. I'd have to keep a track of all the status of every children.

If this is the only solution, it's ok. I just wanted to be sure.

avatar image
0

Answer by SnStarr · Apr 14, 2015 at 01:42 PM

Change the Alpha Value on the Material its using to 0, this will make it invisible.

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 Owen-Reynolds · Apr 14, 2015 at 02:41 PM 0
Share

But you'd have to go through and do this for every renderer, which is more complicated than just going through and disabling them all.

Plus they need to have a transparent material (or switch to one,) and the system still draws the object each frame. And if some materials had different starting alphas, need to remember what they were in order to restore them.

avatar image
0

Answer by Peeling · Feb 10, 2021 at 11:02 PM

Just because I was looking for this and found what I think might be a useful alternative:

 public class ActiveButHidden : MonoBehaviour
 {
 
     public List<GameObject> targets;
 
     void Start()
     {
         StartCoroutine(ReEnable());
     }
 
     IEnumerator ReEnable()
     {
         while (true)
         {
             yield return new WaitForEndOfFrame();
             foreach (GameObject go in targets)
             {
                 go.SetActive(true);
             }
         }
     }
 
     private void LateUpdate()
     {
         foreach (GameObject go in targets)
         {
             go.SetActive(false);
         }
     }
 
 }

Drop this on a game object that's always active, and add any game object you want active but hidden into the list of targets. This script will turn them (and their children) off before they are gathered for rendering, and back on before they are gathered for the next round of fixedupdate/update.

CAVEAT:

Any coroutines running on an object are destroyed forever when you make that object inactive, so you can't use this method to hide objects that are running coroutines.

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

23 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

Related Questions

how to toggle on/off a gameobject with a GUI button ? 3 Answers

hide and show node for turret places 1 Answer

Hide/Show a game object and activate/deactivate a script of another game object with one script 1 Answer

How to hide 3D text behind other game objects. 0 Answers

Deactivating the hiding of objects that are out of camera view 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