WARNING : This site is outdated and the PopcornFX team will no longer answer your questions here.
For all support questions please go to our Discord server
0 like 0 dislike
Hey guys!
I wonder if there is a convinient way to control particles spawn process from the unity/ue4 game engine.
I want to spawn the particles precisely when a certain event happen in the engine.
Since my effect consists of several layers, I want to spawn different layers on different events.

I have looked through some audio-related examples provided with PopcornFx, and I tried simulating "spawn on event" behavior in similar to the examples way: via infinite spawner and "killer" variable controlled via passed attribute, but I can clearly see that I have a noticable reaction latency most of the times. To reduce the latency I tried increasing the spawn ratio of the infinite spawner, but in such case I end up with having too much particles when the "killer" is not zero.

So my requirements are:
- to be able to spawn the certain amount of particles
- to be able to do it precisely in a certain time point
- all controlled from the game engine (unity or ue4)

I guess it have to do something with
But there is no information on invoking the events from the game engine.

Thanks in advance
by leavittx (220 points)

2 Answers

0 like 0 dislike
Best answer

Ah ok sorry for my misunderstanding.

Here is a better solution:

-Like before create an attribute sampler "ParticlesCountLayer0".
-Bind it with the FluxFactorExpression.
Set the DurationInSeconds at 0
-SpawnCountMode to TotalParticleCount
to 1

-Repeat those operations on each layer.

Now in the engine each time you want to spawn particles on a layer, set the corresponding attribute to N, and restart the FX. This will spawn instantly the right number of particles of each layer.


by Romeo (2k points)
Hi Romeo!

So it's not possible without restarting the FX?
I assume this is costly operation...
Moreover, I have some layers in the FX which I want to be persistant.

Yes indeed, there is an other workaround.

Another time with the Layer scripts, just write => Flux = ParticlesCountLayer0 / dt;
Always with :
    -SpawnCount to 1
    -DurationInSeconds to 0
But with the SpawnCountMode set to ParticlesPerSecond.

This will spawn each frame the amount of particles in your attribute ParticlesCountLayer0, so don't forget to reset it to zero at the next frame.

Hope i finally answer correctly! Cheers!
Looks like what I needed!

However the two parameters you've mentioned (DurationInSeconds and SpawnCountMode) are only available for the non-infinite spawners:
and not available for the infinite ones:

I guess I should use an infinite spawner in my case, right? If I use non-infinite, the particles are not being emitted no matter what value I assign to Flux.

Great to hear !!
Oh yeah if your FX doesn't stop, infinite spawner is made for it. DurationInSeconds and SpawnCountMode will be set by default correctly in your case. ;)
Cheers Leavittx!
That's really amazing!!
Actually this is a question I was asking myself ever since I've opened PopcornFx for the first time. Maybe it could be useful to have this workflow description in tutorials or on the wiki? I think this is quite common use case for particle system!
0 like 0 dislike

Hi Leavittx!

To control the spawn rate of your layers, you have to deal with the Layer scripts. 

You can use an attribute sampler "SpawnRateAttribute" as your input to spawn a precise amount of particles at each time.

To do so, just add => Flux = SpawnRateAttribute;
Just repeat those spets on each layers.

Their is an example in the ReleaseHighlights package, the FX is LayerScript_Flux.

Hope this helps!


by Romeo (2k points)
Hi Romeo!

I tried to to it in the way you've suggested.
Please see the following screenshot: https://www.dropbox.com/s/6ghsdisrn7i5xhq/popcornfx_flux.png?dl=0

On the screenshot I tried to emit 5 particles by setting the SpawnRateAttribute to 5.

The problem is that the reaction isn't immediate, i.e. each next particle is being emitted after some time period from time point when the previous particle was emitted. It can be clearly seen on the screenshot above.

What I need is to emit exact number of particles within the layer in exact point in time, and it should be controlled by the game engine (unity).

Looking forward to your answer,