Hello guys, I’ve been trining to add Button (with a Layout Element component) to a Vertical Layout Group (with a Content Size filter with spacing between elements added). If I manually drag them into the Grid they appear with the correct format, spacing and text layout. But if I add them as a prefab from script they get added into the grid with wrong sizes, no spacing and wrong text format. Am I doing it wrong from the code part? This is what I have:
public void fillLayoutData()
{
for (int i = 0; i < module_descs.Count; i++)
{
Button btn = Instantiate(detailsButton);
btn.GetComponentInChildren<Text>().text = module_descs[i];
btn.transform.SetParent(layout_group.transform);
//.transform.parent = details_panel.transform;
}
}
Where “module_descs” is a List of strings to add as label for the buttons (I would LOVE if I could use TMpro_Text instead as the default text is very bad), “detailsButton” is the button prefab with the componnents specified above and “layout_group” is the grid GameObject where I want to add these elements.
Do you know why the buttons are not fitting in with the format I want? Thank you so much for taking the time to read this and help me out, I trully appreciate it!