Changing the region_rect for a panel's custom style during runtime?

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

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.

:bust_in_silhouette: Reply From: pouing

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: add_stylebox_override

Godot version: 3.3