0 votes

Basically, I'm making GUI for a game, and I want the panels to change textures. I'm using a spritesheet for those textures, so i need to use the Region Rect stuff for the custom styles. However, I have no idea how to do that during runtime with gdscript, so I need the help of those of you on this version of stack overflow whereas the community doesn't suck.

Godot version 3.3.4, unmodified
in Engine by (18 points)

1 Answer

+1 vote
Best answer

To change theming programatically, use the Control node's add_*_override methods.

For example, to change the texture on a Panel, you could update the theme property panel like this:

stylebox = get_stylebox("panel").duplicate()
stylebox.texture = load("res://my_img.png")
add_stylebox_override("panel", stylebox)

Reference: addstyleboxoverride

Godot version: 3.3

by (68 points)
selected by
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.