How to fit elements inside a Horizontal Layout Group?

Here is part of a UI I’m working on:

alt text

The light blue strip at the bottom is a Horizontal Layout Group. The first icon was added via the editor and fits inside the layout group. The second two elements were added via script and do not.

In the inspector, the children are listed as having all the same size with the note that “Some values driven by HorizontalLayoutGroup”

Currently I have tried:

  • Using SetParent on the child objects, as recommended by the docs
  • Calling LayoutRebuilder.MarkLayoutForRebuild on the parent
  • Have “child force expand” set to off on the parent layout group

How do I tell the layout group to resize its children to fit after adding them?

Answering my own question, I had forgotten to set the second param of SetParent to false.