TypeError: GradientRange is not a constructor

Hello,

Does somebody knows why a GradientColor property works fine in the editor but crash at runtime with this error : “TypeError: GradientRange is not a constructor”

    @property
    public outlineColor : GradientRange  = new GradientRange();

2022-07-26 13_55_36-Cocos Creator - label - db___assets_scenes_scene.scene_

I know this class is originally used in 3d particles, but I want to use it in a custom component.

The Particle System was disabled in the feature cropping of the project settings.

I no longer get errors, but whenever the editor recompile the project, the changes made to the gradient in the editor are lost.
It reverts back to plain white gradient.

Which version are you using

3.5.0
The reset of the gradient happened because i was editing it from a prefab instance.
When edited from the prefab itself or if the instance is unlinked from the prefab, the gradient stays persistent.

In case someone come across this and asks himself how to make use of the gradient property in a shader, I will finish this post by explain it.

In your component, extract gradient evaluations in an array of colors. The result of the evaluate method has to be cloned because it reuses its return reference. You would have an array full of the same color otherwise.

Set the property of your material with this array.

    @property(Gradient)
    public outlineColor : Gradient  = new Gradient();
            const gradientData = new Array<Color>(100);
            for(let i = 0; i < 100; i++) {
                gradientData[i] = this.outlineColor.evaluate(i / 100).clone();
            }
            this.customMaterial.setProperty('outlineColor', gradientData);

In your fragment shader, define a vec4 array uniform and use its values according to the uvs.

  uniform Constant {
    vec4 outlineColor[100];
};
    for(int i = 0; i < 100; i++) {
      if(i == int(uv0.y * 100.0)) {
        outline.rgb = outlineColor[i].rgb;
        break;
      }
    }

2022-07-27 09_10_30-Window

We will fix this bug in 3.6.0 release version.Thanks

Just to be clear, the modification over prefab instance should be saved, it’s a bug