Skip to main content

Horizontal Layout Group aligned incorrectly in Luna

Possible solution:

  • Alter the width of the parent object (parent of the object that contains the Horizontal Layout Group component) at runtime. This can be a simple addition of 1, and then subtract that off a frame or so later.
CLICK HERE for an example (would need to be attached to the parent object).

private int frameCount = 0;
private int step = 0;
private RectTransform rt;

private void Start()
{
rt = gameObject.GetComponent<RectTransform>();

if (gameObject == null)
{
Debug.LogWarning("Object to re-align not found");
}

StartCoroutine(Wait1Frame());
if (step < 1)
{
rt.sizeDelta = new Vector2(rt.sizeDelta.x - 1, rt.sizeDelta.y);
step = 1;
}
}

private void Update()
{
if (step < 2)
{
if (frameCount < 5)
{
frameCount++;
}
else
{
rt.sizeDelta = new Vector2(rt.sizeDelta.x + 1, rt.sizeDelta.y);

step = 2;
}
}
}

IEnumerator Wait1Frame()
{
yield return 0;
}