[SOLVED] Blending particles of ParticleSystem during runtime dont work

Hi there,

does somebody know if its possible to change the opacity of a particle system during runtime? Ive played around with modifying the alphaGraph key values (in the console the values are correct, but it has no effect on the particle system).

Even when using the rebuild() method the particle system is just reseted, but nothing changes regarding the opacity (also a reset of the position should be avoided) - the intention is to blend the particle system in and out depending on a opacity value the user can set.

Any ideas or inputs would be very welcome - thx in advance!

The opacity of the particles is controlled by the opacity graph of the particle system component. The opacity graph is a simple curve (or two curves, if you use min-max randomized values). In order to change it, you must modify the curves. Refer to pc.Curve API for details:

For example, if you don’t use a random opacity (random from a min-max range), then you could do something like this:

// create a curve, that is just a straight line at value 1 (or use existing one):
const graph = new pc.Curve([0, 1]);

// curve values stored as [key:value] pairs, where the 
// key is time (normalized, [0, 1] range), value is value. 

// make the opacity value 0.1 everywhere along the curve:
const key = graph.keys[0];
key[1] = 0.1;

// assign the modified graph (assign every time you change the value)
this.entity.particlesystem.alphaGraph = graph;

// use a different curve for min-max random, or the same one for non-randomized values
this.entity.particlesystem.alphaGraph2 = graph;
1 Like

Hi LeXXik,

many thanks to you! It works! But may i can ask you a thing i cant figure out:

It works fine, when using just 1 pair, but when using 3 pairs of key, it doesnt work correctly. I just used your code and modified it like:

const graph = new pc.Curve([0, 0, 0.5, 1, 1, 0]);
const key = graph.keys[1];

var randomOpacity = Math.random() * 0.3;
key[1] = randomOpacity;

this.particleSystemEntity.particlesystem.alphaGraph = graph;

if i get it right, graph.keys just combines two values, so
key(0,0) 1 = graph.keys[0]
key(0.5,1) 2 = graph.keys[1]
key(1,0) 3 = graph.keys[2]

i just want to modify the middle key, which is variable and lerp it from 0 to 1 (or in this case up to 0.3) and vice versa. But in this case the opacity of the particle system isnt adjusted correctly - there some particles faded (once) and the others stay completly visible. So my suggestion is: Does this happens, because the particles are interpolating betwenn the three keys and maybe are only then affected, if there at 0,5 (timing)?

Or probably i did something wrong. But its very nice, i have a respond based on your answer, because i had several other trys which havent worked (the particles havent either changed)

Thanks for your help!

Did you apply this graph to the particlesystem.alphaGraph2 as well? If not, it will use the default one for the second graph, whatever was there when the system was created, and will make it to pick a random value between those graphs.

If you don’t want the system to pick a random value between 2 graphs, make sure both alphaGraph and alphaGraph2 are the same. Or make 2 different graphs, one with 0 and one with 0.3 for middle value, then the system will pick a random value between those graphs.

Nice - you where right! I forgot the alphaGraph2 :slight_smile:

But tbh i’m a bit confused about the logic behind why there are two different alphaGraph’s - but right now my question is perfectly answered!

Thank you again for your great input!

1 Like

The system uses the curves for range picks. It grabs a random value between the two graphs. If both graphs are same, the value will be the same, no randomness.

Say, you have two graphs [0, 0.5] and [0, 1.5]. The system will pick a random value from 0.5 to 1.5.
If you have [0, 0.5] and [0, 0.5] - the system will always return 0.5.

Ah okay now i think i got u - alphaGraph2 its basically active, if i enable the randomize toggle inside the opacity graph and place second graph values beside the “basic graph” right? If this is active the area between those two graph’s are the random area you mentioned. I havent seen this randomizing option before and was wondering why were talking about two graph’s :slight_smile:

Now it makes sense to me - thank you very much!

1 Like