Impossible to set visibility for GameObjects with hideFlags.HideInHierarchy

I want to have an object visible in the hierarchy, but hide its children. This is easily doable. But then, if I set the visibility (aka, the little eye icon), its children don’t disappear.

So I tried code. But it seems like it’s impossible to set the visibility via code for objects that are hidden in the hierarchy.

In other words, this code doesn’t work:

gameObject.hideFlags = HideFlags.HideInHierarchy;
SceneVisibilityManager.instance.Hide(gameObject, false);

As in, the object is hidden in the hierarchy but still visible in the scene.

Is there a way to do what I’m thinking?

2 Answers

2

Normally yes, and I expected it to work that way.
But apparently the hideFlags make it impossible for the children to disappear.

Oh sorry, it was unclear to me that you were trying to do it to something with that flag, I thought you were trying to use the flag as a later attempt to hide it in the scene. Sounds like a bug that it cares about hideflags and skips the children. Interesting that you need this though, I wonder what you're making haha

Yeah either a bug, or an incompatibility of some sort. I might file it as an issue actually. I'm making a tool to hide the children of a Prefab. It all works fine, but at the moment it's incompatible with scene visibility options for this reason. You would hide the root, but would have no way to hide the children...

Hiding a parent using the eye icon hides its children for me, is this option not enabled for you?
image
(the eye icon in this image)