ParticleSystem change color on runtime

Hello,

I am doing something like this to change in code the color of a ParticleSystem.

this.entityParticleEngine.particlesystem.colorGraph.curves[0].keys[0][1] = 0.2;
this.entityParticleEngine.particlesystem.colorGraph.curves[1].keys[0][1] = 0.2;
this.entityParticleEngine.particlesystem.colorGraph.curves[2].keys[0][1] = 0.85;

It works correctly if I do this during initialization. But on runtime, in the update(dt) function, it doesn’t affect the color. Do we have do some sort of update on the ParticleSystem, like what we do when we modify a material?

Thanks,

Yeah, I think all the graphs are converted into textures to use in the shader.

I don’t think there is an “API” way to update the graphs at runtime. If you call the internal methods entity.particlesystem.rebuild() or entity.particlesystem.rebuildGraphs()` that should work, though I can’t guarantee those methods will remain in the future…

1 Like

Thanks Dave,

rebuildGraphs() returns undefined, but rebuild() works fine and does the job. For the moment :wink:

1 Like

Hello @Leonidas
This rebuild() restarts the particle effect animation…

Is there any way to smoothly change particle color without restarting particle animation?

I don’t think there is any other way, latest time I tried it required calling rebuild().

Try posting a feature request in the engine repo about it: