How to get GridContainer to sort its children into a nice grid when they are added via script?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By AgeOfAsparagus

I have a GridContainer that gets nodes added to it:


And this node appears nicely in the center. However, if I try to add another node:


It also appears right in the center, on top of the first node. If I try to force the container to sort:


Nothing happens.

How can I get my nodes to show up nicely in a grid container like they do if I put them in there with the editor?



If I add a Button node this way it seems to work as expected, but if I add a Sprite node, for example, it doesn’t work. Maybe it only works with control nodes?

:bust_in_silhouette: Reply From: njamster

Maybe it only works with control nodes?