Hi! I'm just trying to set up some simple functionality in my project, where I can specify a colour to an export variable, and then that colour gets applied to a GradientTexture2D. I have a GradientTexture2D set up as a simple radial fill light-source style texture. I can't modify the modulate colour for shader reasons that I don't fully understand, so I need to edit the GradientTexture2D directly. I'm trying to simply set the two points of the gradient, at the start and the end, to the desired colour, and the desired colour at 0 Alpha. This is because even a 0-alpha entry in a gradient will still look wrong if the RGB values dont match the other colour.
Anyway I'm just trying to make this into a tool script to save time, so I only have to edit 1 colour value rather than two.
Here's my code that just isn't working. It's either the method of modifying the gradient that's wrong, or my use of the @tool functionality. I'm not sure which. Thanks for any help :)
@tool
class_name AddLight
extends Sprite2D
@export_color_no_alpha var light_color: Color:
set(val):
light_color = val
if texture is GradientTexture2D:
var clear_color: Color = light_color
clear_color.a = 0.0
texture.gradient.colors.clear()
texture.gradient.colors.append(light_color)
texture.gradient.colors.append(clear_color)