When I try to enable a GameObject that's already disabled, the GameObject is null and can't be enabled via C# code

Hello community.

When I try to search a disabled GameObject the same is null with the method

GameObject.Find("GameObjectNameToFind");

But if I make a public property of GameObject and I assign it via the editor, then the GameObject isn’t null.

Public GameObject gameObjectToBeAssigned;

It’s a bug or there’s a different way to work with disabled GameObject via code?

I’m working with .NET 4.6 experimental and C# as you can see.

Regards.

This function only returns active GameObjects. If no GameObject with name can be found, null is returned. If name contains a ‘/’ character, it traverses the hierarchy like a path name.

This is not a bug but by design.

https://docs.unity3d.com/ScriptReference/GameObject.Find.html

GameObject.Find only returns enabled objects. establish a reference to the object, then enable it. As a general rule, never use GameObject.Find. it is slow and processer intensive.