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
0
Question by d112570 · Nov 02, 2013 at 06:05 PM · setactivetrue

SetActive(true); not working

Hi, I used this code to disable the child Star from the Parent Galaxy, but when I want to visit this star, I am unable to enable it. I have 10 Galaxy folders, each have 9 star folders, each star has 9 Planet folders, and each has 9 Satellite folders. If I don't disable each Star folder when I don't need them I will have a maximum of 7290 visible objects, slowing down the program.

The code I use to disable and also works is; p = 0 to 9

 starFolder= GameObject.Find("Galaxies" + p + "/Stars");
 if (starFolder) starFolder.SetActive(false);

The code I use to enable and does not work is; p = 0 to 9

 starFolder= GameObject.Find("Galaxies" + p + "/Stars");
 if (starFolder) starFolder.SetActive(true);

I can render the Mesh to false, but too much work for 7290 objects. Easier letting the folder Star and its children be disabled.

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 Zaeran · Nov 02, 2013 at 06:22 PM 0
Share

Is it possible that by setting SetActive to false, if(starfolder) is now returning false, as it's now inactive?

avatar image Cornotiberious · Nov 02, 2013 at 06:31 PM 0
Share

I'm not exactly certain how you're doing this but here is a basic rundown of how SetActive() works http://docs.unity3d.com/Documentation/ScriptReference/GameObject.SetActive.html Im guessing it has something to do with a parent not being active and so the child does not appear active. does that help?

avatar image d112570 · Nov 02, 2013 at 06:46 PM 0
Share

The parent (Galaxy) is active, and will always be. I just don't need to see all the stars with its children when I don't need them.

avatar image sethuraj · Nov 02, 2013 at 07:21 PM 1
Share

You cannot find Inactive objects using GameObject.Find(string);.This is the problem here.... Once you set an object to SetActive(false); you cannot find using GameObject.Find(""); . Enable/Disable meshrenderer of the objects ins$$anonymous$$d of Active/Inactive.

4 Replies

· Add your reply
  • Sort: 
avatar image
4

Answer by Bunny83 · Nov 02, 2013 at 06:36 PM

GameObject.Find - "This function only returns active gameobjects."

Comment
Add comment · Show 5 · 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 d112570 · Nov 02, 2013 at 06:44 PM 0
Share

O$$anonymous$$, anyway around that. That is what I was thinking too.

avatar image tw1st3d · Nov 02, 2013 at 06:46 PM 0
Share

Find it before you set it inactive, then set it active again later.

avatar image d112570 · Nov 02, 2013 at 07:01 PM 0
Share

Can you get game object without find? Otherwise I will have to find each game object on start and store them in a variable.

avatar image Zaeran · Nov 02, 2013 at 07:06 PM 0
Share

It'd end up a lot easier if you just disable the renderer on each object

 starFolder= GameObject.Find("Galaxies" + p + "/Stars");
 if (starFolder) starFolder.renderer.enabled = false;

edit: Never$$anonymous$$d, just realised that would only disable the star, and not any of the children

You'll have to do this to disable:

 $$anonymous$$eshRenderer[] childRenderers = GetComponentsInChildren<$$anonymous$$eshRenderer>();
 
 foreach($$anonymous$$eshRenderer m in childRenderers){
     m.enabled = false;
 }

and this to enable:

 $$anonymous$$eshRenderer[] childRenderers = GetComponentsInChildren<$$anonymous$$eshRenderer>();
 foreach($$anonymous$$eshRenderer m in childRenderers){
     m.enabled = true;
 }
avatar image d112570 · Nov 02, 2013 at 07:31 PM 0
Share

thx, but the problem would be I have halo, flares, and particles that would still render and would make my other objects like lightning and rings be active which I have currently inactive. Also the scripts would also be active.

avatar image
0

Answer by j-p-e-g · Nov 02, 2013 at 07:45 PM

Couldn't you tag all your stars e.g. "stars", and then use

 GameObject[] starFolders = GameObject.FindGameObjectsWithTag("stars")


to store them in an array at game start?

No idea how the order of the list is determined but if that can be controlled somehow, you could use the index to access the folder you need.

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
0

Answer by adreamvoyager · Dec 01, 2013 at 06:52 AM

I believe the issue is that some of the game objects are not loaded at the start up. I get around this issue by creating a startup function that fires on the first update.

     bool startUp = false;
     
     
     Update() {
     
       if (!statUp) onStartUP();
     
     
     }
 
     void onStartUp() {
       someObject.SetActive(true);
       startUp = true;
     }
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
0

Answer by blenderblender · Oct 22, 2014 at 02:21 PM

It do not work because the objects is not Active

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

22 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

Related Questions

Array SetActive C# Unity 1 Answer

Set Bool in Inspector to true or False 2 Answers

Problems with save 1 Answer

Making coins reappear after a set time 1 Answer

physics.OverlapSphere colliders 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