How set StyleBoxEmpty to a Button by script?

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

I’ve created a new button by script, but i want it to be “invisible”. When it is created by UI, we have to set “Custom Styles” (Hover, Pressed, Focus, Disabled and Normal) to “new StyleBoxEmpty”, but how can I do it by script (for Hover, Pressed, Focus, Disabled and Normal)?
My code:

var btn = Button.new()
btn.rect_global_position = pos
btn.rect_size = size
#btn.stylebox = StyleBoxEmpty ??????
	
:bust_in_silhouette: Reply From: nonunknown

So, buttons has Hover,Pressed,Focus,Disabled and Normal as Custom Styles first you need to know which situation you want to set to StyleBoxEmpty.

  • I’ll show you a technique you’ll never forget for future development on the engine:

All Node inherited classes has a *.set() and a *.get() method, so in this example lets suppose you want to change the Normal state of the button to StyleBoxEmpty, first you click in the button node, and in the Inspector go to “Custom Styles” and hold with left button of the mouse over the name of the state and drag (in this case the “Normal”) when you drag you’ll see the path to that option in this case is custom_styles/normal knowing that just go to your script and type:

$Button.set("custom_styles/normal",StyleBoxEmpty.new())

here you are basically saying to godot: Hey at the button normal state I want to be this instance of StyleBoxEmpty. since its a class, you use the word .new()

Thank you. This solved the problem and you taught an awesome way to do by script things easily find in interface. Many future problems will be solved using this method.

Felipe | 2020-08-02 00:04