How do you change a particle gradient in code

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

I’m trying to dynamically change a CPUPartucle2D’s color gradient but am not sure how
The closest I’ve gotten is this line.

$Smoke_Particle.set_color_ramp(“res://Assets/Objects/Player/Broken.tres”)

This gives me an error saying that it can’t convert the string to an object. Plus it would cause harsh transitions between gradients if it did work, is there a better way of doing this? I am using GLES2 for better performance on my crappy laptop and web compatibility.

:bust_in_silhouette: Reply From: Mrpaolosarino

It is because you load it improperly.
add this to your global code first:

export(PackedScene) var Broken

then drag the scene to the editor’s parameter

or

onready var Broken = load(“res://Assets/Objects/Player/Broken.tres”)

Though the first method is performant friendly.
After that, change the code to:

$SmokeParticle.process_material.set("color_ramp",Broken)