godot
godot copied to clipboard
Color wrapper for alpha values does not work
Tested versions
Reproducible in 4.1.1 and 4.3
System information
Godot v4.3.stable - Windows 10.0.22631 - GLES3 (Compatibility) - NVIDIA GeForce RTX 4070 Ti (NVIDIA; 32.0.15.6109) - AMD Ryzen 9 7950X 16-Core Processor (32 Threads)
Issue description
On the docs for Color, there are wrappers for RGBA to use 0-255 instead of 0-1 values. https://docs.godotengine.org/en/stable/classes/class_color.html#class-color-property-a
However, the wrapper for alpha (a) value does not work. The docs should explain this or the engine should give a warning if values outside the expected range are used. (Alternatively--the wrapper should behave as expected.)
Instead of using the wrapper, Color8 can also be used to strictly specify the 0-255 range.
Steps to reproduce
Open the MRP below. Run the root scene and observe the color behavior. The lines are generated from left to right, from i=0 to i=num_lines.
We expect the first two lines to have the same color, but they do not: line.default_color = Color(1, 1, 1, 51.0/255.0) line.default_color = Color(255, 255, 255, 51)
The third and fourth lines show the expected behavior, demonstrated using Color8 (both lines should be the same color.) line.default_color = Color(1, 1, 1, 51.0/255.0) line.default_color = Color8(255, 255, 255, 51)
Minimal reproduction project (MRP)
It appears to me now that there is no constructor in Color utilizing the wrappers for r8, g8, b8, and a8. They are properties that can be accessed after the color is created. But not in the constructor.
I guess you must use Color8 to achieve this, or divide everything by 255. It was not clear to me from the documentation. A warning in the editor would be nice.
A warning in the editor would be nice.
Color values above 100% are perfectly valid, they're used for HDR colors (they will glow brighter in this case). So the engine can not detect and warn you if you enter too big numbers in the Color(...) constructor.
I think the same goes for alpha, but not sure what it exactly means.
I think the expected way to use them is construct a Color and set the properties individually property by property.
Used the wrappers to get the right colour for the second line, so wrappers are clearly working:
It's already been discussed that the code is behaving as it should.
I recommend this bug be closed. Any other issues (changes in documentation, editor warnings, etc.) should be filed as a separate bug report.