ParticleEmitters are causing my game to have high "switching" value on the stats

I’m trying to incorporate the explosion effect in from TestExplosionEffect (in the jme tests project) into my project. I’ve pretty much copy and pasted the code straight from there… THis is what the code looks like from one of the particle emitters… (the entire “effect” is made up of about 5 emitters all added to the explosionEffect Node)

[java] private void createFlame(){
flame = new ParticleEmitter(“Flame”, EMITTER_TYPE, 32 * COUNT_FACTOR);
flame.setSelectRandomImage(true);
flame.setStartColor(new ColorRGBA(1f, 0.4f, 0.05f, (float) (1f / COUNT_FACTOR_F)));
flame.setEndColor(new ColorRGBA(.4f, .22f, .12f, 0f));
flame.setStartSize(1.3f);
flame.setEndSize(2f);
flame.setShape(new EmitterSphereShape(Vector3f.ZERO, 1f));
flame.setParticlesPerSec(0);
flame.setGravity(0, -5, 0);
flame.setLowLife(.4f);
flame.setHighLife(.5f);
flame.getParticleInfluencer().setInitialVelocity(new Vector3f(0, 7, 0));
flame.getParticleInfluencer().setVelocityVariation(1f);
flame.setImagesX(2);
flame.setImagesY(2);
Material mat = new Material(assetManager, “Common/MatDefs/Misc/Particle.j3md”);
mat.setTexture(“Texture”, assetManager.loadTexture(“Effects/Explosion/flame.png”));
mat.setBoolean(“PointSprite”, POINT_SPRITE);
flame.setMaterial(mat);
explosionEffect.attachChild(flame);
}[/java]

The way I want to use it is I want the emitter to give off a single “explosion” I’m using this together with a system of throwable objects, i want them to explode when they hit the ground.

I have the code working. but I noticed that my game’s stats were horrible after setting the scene up.Link to screen shot

The switching stat of the textures and the shaders are about 3 times the value of the frame stat. This also shows up in my FPS which is about 350. without the explosionEffect Node’s attached to the cans and cups the Switching value is the same as the Frame value. and my FPS is around 600-700. So I believe this tells me the issue is related to the particle emitters…

What I’ve tried so far is to have each particle emitter disabled at first. Then I would enable it before calling emitAllParticles(). This keeps the switching stat from being high before the explosion. However after the explosion it stays high. I’ve tried doing setEnabled(false) after the explosion is over, but the texture/shader switching stats are still high.

Does anyone have any solutions to this problem?

If you have them disable… note the object count. When you cause the explosion and then it goes back to disabled again is the object count the same or higher?

In the opaque bucket, JME sorts by shader to avoid switches. In the transparent bucket, it sorts by distance so that transparent objects are drawn properly. Maybe some objects are getting rendered for some reason and you just can’t see them… but they are not culled because they are clearly trying to be rendered.

I’m just guessing at things from the info provided.

If you have them disable… note the object count. When you cause the explosion and then it goes back to disabled again is the object count the same or higher?

The object count gets higher. and stays higher even after setting the emitters to disabled again…

The only thing I’ve found to this point that “works” is to do explosionEffect.removeFromParent() after the explosion is over. Which will return the switching stats to their normal numbers, (also the object count will go back down after the explosion)

Is this the intended method to be able to “clear” the particle emitter? I feel like I should be able to keep it attached in case I want the particle emitter to emit particles again.

I agree it’s strange. I don’t use the particle emitter at all so I don’t know how it is supposed to work. I was just trying to track down what was going on.

My guess is that even when there are no particles that there is a mesh (with 0 things in it) which is getting rendered… causing a material switch. Detaching them when not in use may be the best option and doesn’t have many down sides. If they were part of a control then you could still easily switch them on and off because the control could add/remove it as needed and save you trouble. It could even automatically remove them when the effect is finished I guess.