I am writing a script that allows us to write UI elements at runtime, however we have an issue where the anchorPosition isn’t positioning elements properly.
“My Button” is a child of SubGroup attached to Panel. When we test the code, everything generates fine, but the position of SubGroup isn’t at 0,0 relative to the panel.
public static RectTransform BeginSubControl(string name = “SubGroup”) {
GameObject go = new GameObject(name);
RectTransform t = go.AddComponent();
if (subControls.Count > 0)
{
t.parent = subControls.Peek();
}
subControls.Push(t);
t.anchoredPosition = new Vector2(0, 0);
return t;
}
If I manually go in and adjust anchorPosition from the inspector at runtime to 0,0 it positions dead center of the parent though.