HierarchyPosition
It is used to save and restore the game object’s position in the hierarchy, for example when the object is moved to the bottom of the root canvas to display it on top of all other objects.
HierarchyPosition position;
void Show()
{
var canvas = UtilitiesUI.FindTopmostCanvas(transform);
if (canvas != null)
{
position = HierarchyPosition.SetParent(transform, canvas);
}
gameObject.SetActive(true);
}
void Hide()
{
Position.Restore();
gameObject.SetActive(false);
}