Tweening a Gradient's Offsets Property

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By TheNewGrant

Hey there!

I’m trying to tween the offsets property of a gradient but am having trouble doing so. I have two main problems.
1: The offsets property of a gradient texture is a PoolFloatArray and I can’t seem to be able to put arrays into the start and end value parameters of the interpolate_property method and a Vector2() doesn’t work either.
2: I can’t go further into the property to change only a single index of the array (From the data found in the inspector it looks like I should be able to do offsets:indices/0 but an error is thrown instead)

I can use the AnimationPlayer node to animate the offsets property of a gradient, of which the path is texture:gradient:offsets (texture is the texture property of the textureRect I’m using, gradient is the gradient resource I’m using). I notice that the AnimationPlayer node can animate an array without any problems, is there a trick I’m missing to make this work in the Tween node?

I would settle with using the Animation Player node but I can’t seem to be able to make the animation line up with the other tweening animations I have already set up (I dunno how to make an EASE_IN_OUT, TRANS_BACK animation in the Animation Player node work).

If you know how to make a tweening animation work with the offsets property of a gradient, or if you know how to make an EASE_IN_OUT, TRANS_BACK animation work in an AnimationPlayer I would love to hear it.

The two parameters I am having the most trouble with are supposed to be filled with Variants.

Looking at the docs about variants
Variant — Godot Engine (stable) documentation in English
I found that Variants can be arrays (found at bottom of page).

However, whenever I use an array (or a PoolFloatArray which is what the property uses) I get this error:

_calc_delta_val: Invalid parameter type. Supported types are: bool, int, float, Vector2, Rect2, Vector3, Transform2D, Quat, AABB, Basis, Transform, Color.

Why is this working differently than what the docs details? What am I missing?

Also, I learned that I can replace the initial_value parameter in interpolate_property with null which makes this a little bit easier.

TheNewGrant | 2021-04-02 01:03

:bust_in_silhouette: Reply From: exuin

It is not possible to animate a gradient with Tween at this time. It’s also not possible to make a EASE_IN_OUT, TRANS_BACK animation with an AnimationPlayer with just two keyframes since the value exceeds the keyframe values. You’ll need four keyframe values and you’ll have to play with the easing as well.

Thanks for the quick reply!

I did some more research after posting this and came to the same conclusion with tweening. I’ve mentioned that issue on Github as well.

Your response about AnimationPlayer is really helpful and will definitely help me in accomplishing what I want with my game at this time.

Again, thank you.

TheNewGrant | 2021-04-02 02:37

Alternatively, you create a variable that represents the offset value, tween that property, and then in the _process() function you can call the set_offset() method of the gradient with that property to set the offset manually.

exuin | 2021-04-02 03:01