How can I set VBoxContainer separation through script?

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

I am working on a 2D game. For my main menu UI, I have a margin container, and inside that I have a VBoxContainer. In my margin container script, I have following line -

$VBoxContainer.separation = 10

However on running game, I get following error -

Invalid set index ‘separation’ (on base: ‘VBoxContainer’) with value of type ‘int’.

Hence my question - how can I set separation on a VBoxContainer using script?

:bust_in_silhouette: Reply From: jandrewlong

separation is a theme property, so you need to use add_constant_override(), like this:

$VBoxContainer.add_constant_override("separation", 10)
$VBoxContainer.add_constant_override("separation", 10)

is changed to

$VBoxContainer.add_theme_constant_override("separation", 10)