I have a canvas with some nested layouts on it. When I SetActive(false)
the canvas GameObject, then SetActive(true)
it again, the layouts get completely messed up. Everything on the screen is in the wrong place.
I have tried
void OnEnable()
{
LayoutRebuilder.MarkLayoutForRebuild((RectTransform)transform);
foreach (RectTransform rect in
gameObject.GetComponentsInChildren<RectTransform>())
LayoutRebuilder.MarkLayoutForRebuild(rect);
}
I’ve even tried putting that in Update()
to no effect.
When I resize the window, the layouts fix themselves.
Again note that I am not doing anything at runtime to cause this problem other than disabling and re-enabling the (top level) canvas.