Correct way to render particles behind in game objects (SOLVED)



I was wondering what the correct way to render particles behind game objects. Looks like by using the default particlefx material, particles are rendered on top regardless of z position.

By setting the material of the particles to the sprite material the z positioning is respected. Is there a better way to all particles to be render behind game objects? I didn’t see anything in the manual about this but might have read over it.


You must modify your render script.

The material of the particles (and others) has a tag. This is what defines when it is rendered. Read the manual on rendering if you have not already. You could create a second material for particles, and then have one set of particles which you render below game objects, and another above, but you won’t be able to mix them. Or if you don’t care to have any above just move the position of the rendering of the particles to be before game objects.

If you don’t have a modified render script you’ll need to copy and paste the files from the built ins and then define the copies which you edit in the project.


Ah, so custom rendering is required I haven’t read all the way through that manual yet. Thanks for pointing me in the right direction!


So got it working without any trouble. Here’s what I ended up doing:

Copy these render files and rename to custom:
builtins > render > default.render && default.render_script

Copy the particle material and renamed to particlefx_behind:
builtins > materials > particlefx.material

In the new particle fx settings, set the name and tags:

In the custom render, select the custom render script:

In the custom render script, define the new tag predicate and also call render where you would like the new tag to show up. Earlier calls are drawn before later calls to render.draw. All the details are in the render manual:

init function add:

self.particle_behind_pred= render.predicate({"particle_behind"})

update function add:


And finally, in the project settings in the bootstrap settings, add your custom render script instead of the default one.

And it was as simple as that! Now my clouds and speed streaks are rendered behind the game objects no problem



I’m buuuuuumping this way back up to the top because i’ve just made a real working jet pack and it looks really great, but i’d like it to render behind my main character (and in front of everything else). Is there any way of getting this to work

TL,DR: How can I set the Z layer of particles in front of some game objects, and behind others?


Basically you need to create more render predicates. As is the Game Objects and ParticleFX are rendered on unique render predicates. Instead of co-mingling particles with GOs it would be better to have all ParticleFX on its own layer only, and then you can have multiple GO layers. Then order each layer of game objects / particles / game objects based on render predicates. Read up on the render documentation, modifying your render script, making new render predicates. If you have questions about it after reading ask here or your other thread.