Enabling an object that is disabled from the start?

If I create an object in the scene editor and set it to be disabled from there, is it possible to activate it from a script? It doesn’t seem possible to find game objects that are already disabled as far as I can see.

Running GameObject.Find("MyDisabledObject") returns null for disabled objects when I try it. So it’s not possible to run SetActive(true) on it afterwards.

Do all objects placed in the scene from the editor simply have to be enabled from the start?

Inactive objects can only be “detected” in the scene through colliders.

My suggestion is to change your design so that you don’t deactivate the object itself, but the components that make it visible or interactive. Disable its script if you don’t want it to interact with anything, and disable its renderer if you don’t want it to be visible. Also disable the collider if you don’t want that to affect anything.

You can parent the object and run SetActive on its child.

The part of finding a disabled object i don’t know, just do a public variable.
And to activate the object you need to do YourObject.SetActive(true); or false if you wand to unable;

One way is to have a reference to it in the inspector before the game is started. Then you have access to it regardless whether it’s disabled.

Other way is to place the deactivated object as a child of another parent (active) object, and traverse the hierarchy of that parent object with parent.GetComponentsInChildren<MyDisabledObjectScript>(true). Note the boolean argument, this has to be true to get deactivated objects as well.

If you don’t have your own custom script on that disabled object, you can search for any component that your disabled object has like so: parent.GetComponentsInChildren<Rigidbody>(true), and then do a foreach loop on the returned collection to find the disabled object , like so:

   Transform[] childrenComponents = parent.GetComponentsInChildren<Transform>(true);
   foreach (Transform child in childrenComponents) {
        if (child.name == "DisabledObject") {
            // we found the desired object
           return child.gameObject;

And yet another way is to use the Resources.FindObjectsOfTypeAll() function. This function will find all objects of a specified type, even deactivated ones. After you get the objects of the desired type, you can then search the collection for the desired object. WARNING: this function also gets assets from the Asset folder (meaning all assets), so beware if you manipulate the returned results during runtime, you might modify an asset.

are you disabling a collider, or deactivating an object? ActiveInHierarchy sounds like what you are looking for, but you’re using the word disabled, which is for making a collider unusable, or turning off physics at some point in time.

if (MyDisabledObject.ActiveInHierarchy == false)
MyDisabledObject.SetActive (true);

if your “disabled” object’s name is MyDisabledObject, it’s going to look for it by it’s name, then turn it active, Write a coroutine if you need the inactive object to wait a while until it becomes visible in the scene.