Create var color that updates another var of the same color but with zero alpha

Godot Version

4.5

Question

I wonder if it's possible to create @export var color_1: Color that updates another var color_2's color but with zero alpha.

for example:

@export color_1 = Red

var color_2 = ???

result : if I change color_1 to red then color_2 becomes red with zero alpha.

I’m using these vars for Gradients.


* Also is changing color by code heavier than using .png? I notice small stutter when color changes by code.

If you’re trying to fade from color 1 to transparent I think there is already Color.Transparent to pick from. Then your gradient texture can have the markers set to your solid color to transparent.

I do not know if doing it in code is more impactful than just uploading .pngs. I imagine it depends on how large the pngs are and how large the gradient is.

1 Like

Yes. If you want this to work in the editor, you have to make it a @tool script.

@export var color_1: Color = Color.RED:
	set(value):
		color_1 = value
		color_2 = value
		color_2.a = 0.0

var color_2: Color

As @Josh_W pointed out, there are other ways of doing this. Perhaps it might help if you told us the problem you’re trying to solve with this solution you’ve come up with.

2 Likes

Nothing complicated really. I’m faking a 3D orb by using billboard sprite3D with radial alpha gradient. I just want to have simple @export control over its color and the sharpness/blurriness of the gradient’s edge.

For the color control right now I have something like:

var start_gradient_marker_color = color(1.0,1.0,1.0,1.0)

var end_gradient_marker_color = color(1.0,1.0,1.0,0.0)

and if I wanna change the color of gradient I have to change both of them so I was wondering if I could just change “start_gradient” and “end_gradient” will automatically matched the change while keeping the alpha zero.

For the Edge control though I haven’t figure it out yet what to do but I’m thinking of tweening the markers’ values to make it sharper/blurrier.

*I know I’m doing it the hard way setting up by code but I’m using this project as a learning experience..as long as it doesn’t impact performance too much.

However, I’m open for any new way to try.

It’s a pretty good aporoach if you’re trying to learn. Just make it a @tool script.