- Home /
How to force object selection to be the parent of a selected object, when the selected object has HideFlags.HideInHierarchy
The scenario can be minimised to be the following:
I have an empty GameObject which has a child object in the hierarchy. The child object has a SpriteRenderer component attached, as well as an actual sprite such that it is visible in the editor.
This child object has the HideFlag HideInHierarchy meaning that it is still visible in the editor, however not in the hierarchy. This also means that the child object is unselectable in the editor (i.e. when trying to select the child object in the editor, Unity acts as if the child object is not there at all and tries to select whatever is behind the child object, if anything).
I wish to enforce that while the HideInHierarchy flag is active on the child object, the empty GameObject (the parent object) is selected when I try to select the child object in the editor.
Is there any way to achieve this behaviour?
I have tried using SelectionBase on the empty GameObject (the parent object) with no luck.
Any help is appreciated.
This would be really useful for procedurally assembled composite objects. I want the hierarchy of objects to behave as a single object from the users point of view. Selection of any HideInHierardy child selects the parent so it can be moved/etc.
Just a guess, but maybe the UnityEditor.Selection
API can help you in this. Specifically, I was thinking of setting UnityEditor.Selection.activeTransform
to the object desired to be selected.
Also, this should be in an Editor script, or at least surrounded by #if UNITY_EDITOR
/ #endif