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?
1 Answer
You can set an StyleBoxTexture to the Panel either by:
- Defining it in a
Themewhich you set in thethemeproperty - Or by setting it in the
theme_override_styles/panelproperty.
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.
- \$\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\$TheJalfireKnight– TheJalfireKnight2023-12-06 17:02:45 +00:00Commented Dec 6, 2023 at 17:02