How to change the color of styleboxflat?

Godot Version



Hello. In my game there’s the panel, and the panel has the StyleBoxFlat property. How to change the bg_color in the StyleBoxFlat property via script?

You need to change the StyleBoxFlat.bg_color property.

You can get the StyleBoxFlat by using Control.get_theme_stylebox() like var stylebox = panel.get_theme_stylebox('panel')

Remember that StyleBoxFlat is a Resource and it’s shared between objects that use it and any modification to it will affect them all. You’ll need to make it unique with Resource.duplicate() and assigning it back with Control.set_theme_stylebox_override() for example.

1 Like