Particle stream with uncollected garbage

I’ve made a particle effect, and the particles are removed from parent after a few seconds. However, the number of objects keep growing.

I suspect that’s because I create a new Material instance for each Geometry, and I need to do this because each instance has random opacity…

How can I address this issue? Thanks!

I suspect that each particle is an instance of Geometry then? This is very costly.
What you could try instead: Batch all particles in a single Geometry/Mesh (like the build-in particle effect is doing it) and encode the opacity as a per-vertex color (add a new VertexBuffer to your Mesh). This will probably require a modification of the particle shader, but is much cheaper in memory and speed.

1 Like

I’ve tried with BatchNode, but don’t help much.

Am I supposed to also avoid new Material instances, and recycle them instead?

Which number of objects? The one in the stats display?

If that’s what’s growing then the geometry isn’t getting removed. That shows the number of Geometries drawn and it can’t really lie about it.

1 Like

If you look at JME’s particle emitter you will note that it can handle per particle opacity just fine by building it into the mesh.

A Geometry per particle is horribly inefficient… whether you shove them under a batch node or not. It’s going to be much better to manage your own Mesh and batch things yourself… like the JME ParticleEmitter does (or any of its offshoots).

What are your particles and why does the stock emitter not work for you?

1 Like

Didn’t think that I was running into trouble. I’ll look into this…

Does stock emitter work on the gui node?

I actually don’t know… but you could try it and then if it doesn’t you’d at least have a start for how to do your own more efficiently.

I’ve used this trick Bug: point-sprite particles in GUI - #4 by InShadow and it works! :slight_smile:

One more thing: the rendering is “AlphaAdditive”, but instead I’d like it to be “Alpha” mode… I’ve tried setting it with


But it doesn’t work. I’ve even changed these but didn’t help:

Alpha will generally look pretty bad unless you sort your particles. There should be a way to set it, though. Just have to look at the particle code.

Solved and committed! Thank everybody! :slight_smile:

monkeysheet is a funny name

That is the point, not to be confused with :monkey: :poop:

1 Like

VertexBuffer documentation is maybe not exaustive on the wiki?

I’ve tried with this:

        pEffect.getMesh().setBuffer(VertexBuffer.Type.Color, 4, new float[]{.5f,.6f,.8f,1f});

And got:

java.lang.UnsupportedOperationException: The buffer already set is incompatible with the given parameters
    at com.jme3.scene.Mesh.setBuffer(
    at com.jme3.scene.Mesh.setBuffer(
    at com.jme3.scene.Mesh.setBuffer(

Any tip welcome! :slight_smile:

Something already set the buffer… find out what it is and what it set it to (some things use color for other purposes since JME doesn’t let one define custom buffers).