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.

You can use Resources.FindObjectsOfTypeAll

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.

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).

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);