Activate GameObject from script

Hello friend :smile:

What I’d like to do is to GET an inactive GameObject from another GameObject BY SCRIPT (no drag n’ drop in the inspector). And set it to active.
But with GameObject.Find() I cannot find inactive Objects.
Do you know how to find/get inactive Objects?

Transform.Find will return inactive GameObjects, so if you know the parent you could try that.

Otherwise, some script needs to know where it is and you can take the reference from that script to activate it. For example, have a script find it with GameObject.Find, store the reference, and disable it in the Awake function.

1 Like

http://docs.unity3d.com/ScriptReference/GameObject.Find.html
The docs say inactive Objects cannot be found using GO.Find and it’s true, I always got null from the function.

But the second approach is pretty damn good. I think I am going to create a static class wich will hold the reference :slight_smile: Thank you!

BTW, can you tell me how to mark a response as the answer, because there is no button. Or I don’t see it?!

My post mentioned Transform.Find, not GameObject.Find.

There is no button like that, the best you can do is like my post :slight_smile: