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 Eowyn27 · Jan 14, 2014 at 09:18 PM · cameraobjectssetactivefindfind-gameobject

How do I find my inactive objects and set them active again?

I inactivated my game objects by finding the objects with certain tags and inactivating them. Now, in my game, I want the camera to move back to the collection of objects but those objects when I move my camera are still inactive but I want them active when I move my camera back.

I realized that I can't find my game objects with their respective tags because that only works for active objects. I tried using GameObject.Find() But I get a nullreference exemption error and I think the way I'm doing it right now is too layman/hard-coded.

So, I'm kind of stuck and need suggestions. So,How do I find my inactive objects and set them active again?

What I did was create a list of all my objects and declared them publicly.

E.g.

 public GameObject Block; 

 Block =GameObject.Find("block");
 Block.SetActive(true); 

but I get a null reference error and besides, I don't think this is a good idea to do it for multiple 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

3 Replies

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

Answer by Eowyn27 · Jan 15, 2014 at 04:40 PM

What I did to solve this problem was publicly declare the objects and then take the name of the object and setactive to true.

So, e.g.

 public GameObject Block1;

 Block1.SetActive(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
1

Answer by chechoggomez · Jan 15, 2014 at 07:22 PM

You can use Resources.FindObjectsOfTypeAll

https://docs.unity3d.com/Documentation/ScriptReference/Resources.FindObjectsOfTypeAll.html

This function can return any type of Unity object that is loaded, including game objects, prefabs, materials, meshes, textures, etc. It will also list internal stuff, therefore please be extra careful the way you handle the returned objects. Contrary to Object.FindObjectsOfType this function will also list disabled objects.

Just make sure you are not using it intensively, since this operation can take long time.

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 Fabkins · Jan 14, 2014 at 09:21 PM

I answered your previous post. I tried the code before I sent it you and it was fine so not really sure the problem as long as you are setting the public declaration is done once and you are making the blocks active and deactive in the same file ( class).

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 Eowyn27 · Jan 14, 2014 at 09:25 PM 0
Share

no I have separate classes for making the objects active and deactive. Also, different scripts attached to different objects. I realized when I'm finding objects by tags, it doesn't work :( nor findobjectsbytype. They don't work on inactive objects in the scene.

avatar image Fabkins · Jan 14, 2014 at 09:28 PM 0
Share

I suggest you restructure your code so you have one static class for both making the objects active and inactive. That static class could then hold the single copy of the public block list.

avatar image Eowyn27 · Jan 14, 2014 at 10:35 PM 0
Share

Okay, just to see if things work, I did a horrible solution where I had publicly declared my objects and then I set e.g. block1.SetActive(true); I dragged my object to the block1 field in the inspector and it works. However, I noticed for one of my objects where I added an empty game object and that empty game object has children that I set initially inactive, turned active after navigating back to the complex of blocks view. I want those to be inactive.

avatar image Fabkins · Jan 14, 2014 at 10:42 PM 0
Share

Please read suggestion in other thread concerning using the camera culling masks.

I suggest you close this one, bad form having same subject in two threads.

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

20 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

Related Questions

Finding objects on scene 1 Answer

Setting inactive objects as active after click on gui button? 1 Answer

Use of unassigned local variable `closest' 1 Answer

How to make camera position relative to a specific target. 1 Answer

different game "scenes" and optimization? 2 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