About Store Forum Documentation Contact



Post Reply 
Turning Particle Emitter On/Off
Author Message
fatcoder Offline
Member

Post: #1
Turning Particle Emitter On/Off
I can't find anything in the docs, headers or forums about this. It appears as though, you have to create and delete particle effects when you want to start and stop them... and if you want them to run for a certain amount of time, then you need to pre-set this too.

But what if you want to have a particle effect that is always there but you just want to turn the emitter on and off as needed. I can't pre-set the run time either as the user determines when the effect is switched on and off.

Clearly this is a very simple (and I would think, common) use case scenario for particle effects, but I just can't find a simple way to do this. It seems to be far more complicated than it should be having to create, fiddle with life and fading members and then delete. Surely I am missing some simple way just to turn the emitter on and off, or am I approaching particles the wrong way? Anyone?
04-15-2012 04:07 PM
Find all posts by this user Quote this message in a reply
Zervox Offline
Member

Post: #2
RE: Turning Particle Emitter On/Off
particle.reborn=true;
to let them spawn
particle.reborn=false;
to turn them off. : )
(This post was last modified: 04-16-2012 02:03 PM by Zervox.)
04-15-2012 05:59 PM
Find all posts by this user Quote this message in a reply
fatcoder Offline
Member

Post: #3
RE: Turning Particle Emitter On/Off
Hahaha! I knew it. I knew there had to be an easy way... cheers! smile

I didn't think I could change reborn on the fly like that. Oh well, should have experimented.
04-16-2012 01:46 AM
Find all posts by this user Quote this message in a reply
fatcoder Offline
Member

Post: #4
RE: Turning Particle Emitter On/Off
I noticed something interesting though. When reborn is false and all the particles stop (i.e. no longer visible), they must still be resulting in empty draw calls. As soon as I create the particle effect, I see the performance drop, even if reborn is false. Anyone know why this is? I don't understand why EE does stop drawing a particle effect if none of its particles are alive.

But it gets even stranger. Because when I change reborn to true so the particles start. The performance actually improves while the particles are alive and visible. Then when I turn reborn back to false so the particles stop, the preformance drops again even though nothing is visible. Really strange. It must be the way EE is handling it.

Any reason for this behaviour Esenthel? Is it not possible to stop rendering particle effects when none of their particles are alive?

I can't find an elegent way (without using timers and other strange things) to stop drawing a particle effect when its not on. The update() method always returns true becuase it relies on the life of the effect not whether or not all the particles are alive.

The only solution I could find was to start running a timer down from the life_avg of the effect when changing reborn to false. When it hits zero, I can stop drawing the effect as all particles are dead. I don't understand why EE isn't doing something like this internally though. It would save a huge amount of performance and saves us from have to set up this timer rig for every particle effect.

Doing this netted a 200% performance improvement in a particle heavy scene when most effects are not running. EE should be doing this automatically!?!?! Esenthel?
04-16-2012 03:15 AM
Find all posts by this user Quote this message in a reply
Zervox Offline
Member

Post: #5
RE: Turning Particle Emitter On/Off
Indeed it seems they are still being drawn, and they are still being updated, Alive is also always true regardless of reborn= false or not.

if reborn = false; alive should return false when all the particles are dead(sounds logical to me) but that doesn't seem to be the case.
(This post was last modified: 04-16-2012 02:13 PM by Zervox.)
04-16-2012 02:05 PM
Find all posts by this user Quote this message in a reply
fatcoder Offline
Member

Post: #6
RE: Turning Particle Emitter On/Off
@aceio76 - Not exactly what the issue is. The problem is that particle effects are still being "drawn" even when there are no particles alive (regardless of whether or not they are in the frustum). I already draw my particle effects along with parent objects, which are frustum culled, so the particles are automatically culled too for me. The real issue is when you have a dead particle effect (i.e. no particles being emitted) sitting inside the frustum. It is sucking down performance. If you have many of them in your scene... its game over!
04-17-2012 01:01 AM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #7
RE: Turning Particle Emitter On/Off
I can improve this to not draw transparent particles,
but you will still have better performance if you for example call draw with opacity parameter set to 0, so the drawing does not need to check every single particle if it's not transparent
04-22-2012 07:40 AM
Find all posts by this user Quote this message in a reply
fatcoder Offline
Member

Post: #8
RE: Turning Particle Emitter On/Off
The only problem is that you don't know when to start calling draw with opacity set to zero. There is nothing in Particles that we call to check if all particles have finished their life cycle so that we know to set the opacity to zero. We would have to check every single particle before calling draw???

Anyway, I found a very simple solution that seems to work well. When reborn is set to false, I set a timer to match life_avg. Then every frame the timer is run down by Time.d() (as long as reborn is still false). When it hits zero, then you know that all particles have run their life cycle. There will be no visible particles left. At that point, you can just stop calling draw all together. As I said earlier, by doing this to each of the particle effects in my scene, I got a 200% performance improvement when the particles are not running... seriously, my FPS doubled.

It would be great if EE could do this internally, then we don't need to do it for each particle effect added to the scene.
04-22-2012 08:49 AM
Find all posts by this user Quote this message in a reply
Post Reply