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();
I know this class is originally used in 3d particles, but I want to use it in a custom component.
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.
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.