godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
90.56k stars 21.09k forks source link

TextureButton texture_click_mask has no effect, is unset on project reload #87516

Open Qubus0 opened 9 months ago

Qubus0 commented 9 months ago

Tested versions

System information

macOS 12.6.6

Issue description

Adding textures to a TextureButton with a click mask does not work - there are several things going wrong:

All of these are probably related, but they could also be independent. To me, it seems that something is wrong either with the BitMap, TextureButton, or the way that it is applied

Steps to reproduce

  1. TextureButton
  2. Add a texture with alpha to normal, duplicate and recolour it slightly, apply to pressed (optionally also to hover)
  3. duplicate and import as BitMap, pretty sure from alpha and from black & white have the same issue
  4. apply to texture_click_mask
  5. run, see if the button is visible and the area is masked
  6. reload the project
  7. check if the masks are still applied
  8. run, check again

Minimal reproduction project (MRP)

ClickMaskMinimal.zip

note: click masks might not be applied, due to them being unset by on project open

christo8989 commented 8 months ago

I got the textured mask working during development by using create_from_image_alpha and applying it to texture_click_mask programmatically.

But I recently built the game for macOS, and this method is not working.

Calinou commented 8 months ago

I can confirm this on 4.2.1.stable (Windows 11). After reassigning click masks:

[gd_scene load_steps=10 format=3 uid="uid://cj0v4wvgvtjnq"]

[ext_resource type="Texture2D" uid="uid://50kldrri6dqd" path="res://pressed/area_buttons2.png" id="2_v4wan"]
[ext_resource type="Texture2D" uid="uid://cb1wt77c7oq8y" path="res://area_buttons2.png" id="3_df6ig"]
[ext_resource type="BitMap" uid="uid://cb1wt77c7oq8y" path="res://buttons_masks/area_buttons2.png" id="3_uv2wv"]
[ext_resource type="Texture2D" uid="uid://bt05g5lnutn74" path="res://pressed/area_buttons3.png" id="4_di6t1"]
[ext_resource type="BitMap" uid="uid://ht8tfvhflfny" path="res://buttons_masks/area_buttons3.png" id="6_5uti1"]
[ext_resource type="Texture2D" uid="uid://ht8tfvhflfny" path="res://area_buttons3.png" id="6_8kgun"]
[ext_resource type="Texture2D" uid="uid://cj5lu61sda2sy" path="res://pressed/area_buttons4.png" id="6_ww5d3"]
[ext_resource type="BitMap" uid="uid://df8w7xa8sjbsp" path="res://buttons_masks/area_buttons4.png" id="9_qmqgr"]
[ext_resource type="Texture2D" uid="uid://df8w7xa8sjbsp" path="res://area_buttons4.png" id="9_y4mrd"]

[node name="Control" type="Control"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2

[node name="TextureButton" type="TextureButton" parent="."]
layout_mode = 2
offset_right = 256.0
offset_bottom = 256.0
toggle_mode = true
texture_normal = ExtResource("3_df6ig")
texture_pressed = ExtResource("2_v4wan")
texture_click_mask = ExtResource("3_uv2wv")

[node name="TextureButton2" type="TextureButton" parent="."]
layout_mode = 2
offset_right = 256.0
offset_bottom = 256.0
toggle_mode = true
texture_normal = ExtResource("6_8kgun")
texture_pressed = ExtResource("4_di6t1")
texture_click_mask = ExtResource("6_5uti1")

[node name="TextureButton3" type="TextureButton" parent="."]
layout_mode = 2
offset_right = 256.0
offset_bottom = 256.0
toggle_mode = true
texture_normal = ExtResource("9_y4mrd")
texture_pressed = ExtResource("6_ww5d3")
texture_click_mask = ExtResource("9_qmqgr")

After saving the scene, reloading the scene and pressing Ctrl + S:

[gd_scene load_steps=7 format=3 uid="uid://cj0v4wvgvtjnq"]

[ext_resource type="Texture2D" uid="uid://50kldrri6dqd" path="res://pressed/area_buttons2.png" id="2_v4wan"]
[ext_resource type="Texture2D" uid="uid://cb1wt77c7oq8y" path="res://area_buttons2.png" id="3_uv2wv"]
[ext_resource type="Texture2D" uid="uid://bt05g5lnutn74" path="res://pressed/area_buttons3.png" id="4_di6t1"]
[ext_resource type="Texture2D" uid="uid://ht8tfvhflfny" path="res://area_buttons3.png" id="6_5uti1"]
[ext_resource type="Texture2D" uid="uid://cj5lu61sda2sy" path="res://pressed/area_buttons4.png" id="6_ww5d3"]
[ext_resource type="Texture2D" uid="uid://df8w7xa8sjbsp" path="res://area_buttons4.png" id="9_qmqgr"]

[node name="Control" type="Control"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2

[node name="TextureButton" type="TextureButton" parent="."]
layout_mode = 2
offset_right = 256.0
offset_bottom = 256.0
toggle_mode = true
texture_normal = ExtResource("3_uv2wv")
texture_pressed = ExtResource("2_v4wan")

[node name="TextureButton2" type="TextureButton" parent="."]
layout_mode = 2
offset_right = 256.0
offset_bottom = 256.0
toggle_mode = true
texture_normal = ExtResource("6_5uti1")
texture_pressed = ExtResource("4_di6t1")

[node name="TextureButton3" type="TextureButton" parent="."]
layout_mode = 2
offset_right = 256.0
offset_bottom = 256.0
toggle_mode = true
texture_normal = ExtResource("9_qmqgr")
texture_pressed = ExtResource("6_ww5d3")

Some properties incorrectly have PROPERTY_HINT_RESOURCE_TYPE, "bool" here, but removing these hints and recompiling doesn't resolve the issue: https://github.com/godotengine/godot/blob/87d40ba743ff3a3a484db051c11b16559604efa9/scene/gui/texture_button.cpp#L282-L285