0 votes
$Particles2D.material.color = load(str("res://src/UI/Color/Red.tres"))

Throws an error because Red.tres is a Gradient. Is it possible to this property to a gradient from scripting?

asked Feb 17, 2018 in Engine by jarlowrey (611 points)

It looks like its something like $Particles2D.material.trail_color_modifier.gradient = load(str("res://src/UI/Color/Red.tres")), but I'm getting a material is null error...

This does not throw any errors, but the color is not changing

    var grad = GradientTexture.new()
    grad.gradient = load(str("res://src/UI/Color/Red.tres"))
    $Particles2D.process_material.trail_color_modifier = grad

1 Answer

0 votes
Best answer
var grad = GradientTexture.new()
grad.gradient = load(str("res://src/UI/Color/Red.tres"))
$Particles2D.process_material.color_ramp = grad

Or you can instead set the Particle's Color Ramp to an empty/new Gradient Texture in the editor and use this simpler code

$Particles2D.process_material.color_ramp.gradient = load(str("res://src/UI/Color/Red.tres"))
answered Feb 17, 2018 by jarlowrey (611 points)

Is it possible to open the Gradient Color Ramp window, the same way as $ColorPickerButton window ?

Particle2D -> ParticleMaterial -> Color -> Color Ramp -> Gradient

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.