2
\$\begingroup\$

I am messing around with Godot, and I couldn't seem to find a way to set the texture of a Panel node in Godot. First I tried using the get_theme_stylebox() function, but I don't know how that works. I read the Godot documentation and didn't find anything there. How can I go about this?

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

You can set an StyleBoxTexture to the Panel either by:

  • Defining it in a Theme which you set in the theme property
  • Or by setting it in the theme_override_styles/panel property.

If this texture is intended for all (or at least most) panels, use a Theme. As you can set the Theme in the root Control and all children Control take it.


Alternatively, you can set a ShaderMaterial in the material property, and write a shader that lets you set a texture. For example:

shader_type canvas_item;

uniform sampler2D tex:source_color;

void fragment() {
    COLOR = texture(tex, UV);
}

Using a ShaderMaterial would give you more control over how the texture is used, but you need to write the shader code for that.


Also consider using a TextureRect instead of a Panel.

\$\endgroup\$
1
  • \$\begingroup\$ Thanks you. I may use a TextureRect instead, since there's no real reason for the Panel, but I will keep this in mind when I do use Panels! Thanks, this helped a lot. \$\endgroup\$ Dec 6, 2023 at 17:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .