0 votes

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 ??????
in Engine by (79 points)

1 Answer

+3 votes
Best answer

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:


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()

by (100 points)
selected by

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.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.