I have two CanvasLayer and in the first one I have a ColorRect, below is my scene tree

The ColorRect(Overlay) inside CanvasLayer(CanvasLayer2) has Color property which I am trying to change by writing below code in a script attached to mainscreen node

var tween = get_tree().create_tween()
tween.tween_property($Control/CanvasLayer2/Overlay, "modulate", Color(0, 0, 1, 1), 2).set_trans(Tween.TRANS_LINEAR)

where the default value of ColorRect is (0, 0, 1, 0) , Now this doesn't work and no error is shown but if change the code to

tween.tween_property($Control/CanvasLayer2/Overlay, "modulate", Color(0, 0, 1, 0), 2).set_trans(Tween.TRANS_LINEAR)

and default value of ColorRect to (0, 0, 1, 1) then the ColorRect will slowly fade away as intended, in general I can decrease the value from current value but I cannot increase it, am I using tween incorrectly ? If so is there a better way to do it ? Also please let me the correct way to do it using tween if possible.

Code looks correct. Only thing I would change is to use floats, eg. Color(0.0, 0.0, 1.0, 1.0) but otherwise it seems right. Could be a bug.

    cybereality
    I tried with Float now and it didn't increase but I could decrease like earlier with Int.

    The documentation suggest you can use any colour like this, or this one.
    It's even written:

    The color applied to textures on this CanvasItem.

    BUT, my experience shows the modulate goes only from 0 to the base colour of the texture, for instance value (1,1,1,1) will not make it white but the full original colour whatever it was. Still, it is possible to taint to another colour (except white/whitish maybe). This with Godot 4 various releases since beta 7.

    I guess there is some documentation issue and looking at the actual code behind may give better understanding of what it actually is instead of what it is supposed to be from the documentation author(s) perspective.

    • xyz replied to this.

      JusTiCe8 Can you reproduce the problem in a fresh minimal project? Check if there's no another tween animating the same property somewhere else.

        Are you setting the color property of ColorRect in the inspector and not modulate? Try switching "modulate" to "color" in your code:

        var tween = get_tree().create_tween()
        tween.tween_property($Control/CanvasLayer2/Overlay, "color", Color(0, 0, 1, 1), 2).set_trans(Tween.TRANS_LINEAR)

        xyz Can you reproduce the problem in a fresh minimal project? Check if there's no another tween animating the same property somewhere else.

        I don't use Tween, just modulate on a Sprite2D texture.

        base texture:

        modulate tests:



        @JusTiCe8 Sorry I accidentally replied to your post instead of OP. If I got it correctly they try to animate the alpha and it appears that it can be animated one way (fade in) but not the other (fade out).