how can I change the properties of a buttons style box through code? I have a few different buttons and I want them all to look and behave the same except with different colored borders. I cannot manually set their style boxes in the scene because the color they are using is going to be changing.

I got this code to work as long as the stylebox was set to sylebox flat. This was in the ready function of the button, so you could set a function that takes the border color with this code:

	var stylebox_flat := StyleBoxFlat.new()
	stylebox_flat.border_width_left = 10
	stylebox_flat.border_color = Color(0,0,0,1)
	add_stylebox_override("normal", stylebox_flat)

Got the code from this page, if it will help: https://stackoverflow.com/questions/69869553/how-to-set-borders-on-buttons-in-gdscript

There is a way to alter the style properties without overriding the style box. I think it's like this:

your_button.normal.border_color = Color(1,0, 0.0, 0.0, 1)

@cybereality said: There is a way to alter the style properties without overriding the style box. I think it's like this:

your_button.normal.border_color = Color(1,0, 0.0, 0.0, 1)

There is no normal property for a button. I tried a lot of things like that and couldn't get any to work. Not saying it isn't possible, but I don't think that code will work, unless it's in version 4 or something.

@cybereality said: I got that from the docs. But I do recall there is another function to get the style. I don't recall off the top of my head, but it does work in Godot 3.x.

https://docs.godotengine.org/en/stable/classes/class_button.html

There is a get_stylebox function, but I can't get it to work. I think it works basically like the override so the first entry is "normal" and the second is what? The docs don't even show it. If I type normal in a button script it says it's not identified. StyleBox has the normal property as far as I can tell. I don't know why you would need two entries in get_stylebox. It seems like "normal" would be enough.

Sorry, the documentation is wrong. Maybe they updated it to Godot 4.0 or there is a bug. Because I've definitely done it before without creating a new style. But it looks like the functions are gone and the new ones I tried don't work. This is what it shows in the docs as an example, but clearly doesn't work. Maybe for Godot 3.5 or 4.0?

# The snippet below assumes the child node MyButton has a StyleBoxFlat assigned.
# Resources are shared across instances, so we need to duplicate it
# to avoid modifying the appearance of all other buttons.
var new_stylebox_normal = $MyButton.get_stylebox("normal").duplicate()
new_stylebox_normal.border_width_top = 3
new_stylebox_normal.border_color = Color(0, 1, 0.5)
$MyButton.add_stylebox_override("normal", new_stylebox_normal)
# Remove the stylebox override.
$MyButton.add_stylebox_override("normal", null)

https://docs.godotengine.org/en/stable/classes/class_control.html#class-control-method-add-stylebox-override

6 months later