Particle Systems with Sprites (Order In Layer)

Hi,

I have the following problem:

I’m using 2D sprites in a 3D environment with Sorting Layers and the Order In Layer to decide the order of the elements relative to the camera.

Since the release of Unity 5.6 I had been testing the new Sorting Group component and the new Transparency Sort Mode Custom Axis. And it works!

But neither of the options works with Particle Systems because the Order In Layer of each particle cannot be set and all particles share the same Order On Layer configured in the Particle System component.

With the release of Unity 5.5 I believe that a few new variables of the Particle class were exposed and I want to ask if there are plans to include the Order In Layer or if there is a workaround that I can use (or if this cannot be done… :frowning:

Thank you.

2 Likes

Hi. Its something we plan to look into in the near future.

2 Likes

Hey, can I confirm that you’re asking for the ability to set the Order in Layer of each individual particle within a system?

We already expose Order in Layer for the Particle System in the Renderer Module UI.

1 Like

We need

I think we need some method or scripts, made particles and 3d model used as normal sprites in UGUI, and could change their SiblingIndex to change depth , thanks!

Yes, I’m asking for the ability to set the Order in Layer of each individual particle within a system.

It would be great if we can do something like modifing a variable in the Particles (https://docs.unity3d.com/ScriptReference/ParticleSystem.Particle.html) and then doing SetParticles (https://docs.unity3d.com/ScriptReference/ParticleSystem.SetParticles.html).
Or something more automatic, exposed in a variable in the Particle System component, to set something like a SortingGroup (https://docs.unity3d.com/ScriptReference/Rendering.SortingGroup.html) for each Particle.

Thank you!

Particles are all drawn in one call, so it would be very difficult for us to split each particle into its own Draw Call, for sorting purposes. It also has some serious performance implications.

The only way I can think to achieve this currently, is to set the particle system Render Mode to None, and then use GetParticles in script, to position your own sprites at each particle location. These individual sprites can then use Order in Layer however you wish.

You can also use GetCustomParticleData and SetCustomParticleData, to store ordering information, or maintain your own data in the script, as you wish.

Right now we are using the new option Transparency Sort Mode Custom Axis to order all the sprites in the scene with this configuration:

3059800--229847--TransparencySortModeCustomAxis.PNG

With this option we set all the Sprites with the same Order in Layer (zero) and let the sort mode take care of the sorting.

I suppose drawing the particles in one draw call doesn’t work like this but we were wondering if setting the Order in Layer of all the Particles to 0 would do anything or if something can be achieved with this.

I hadn’t thought of this workaround, I will try to implement it and see if it work for us. Thank you for your answer!

1 Like

Hi, I know this thread is super old, but where you able to make this work somehow?
Thought about the same idea of rendering sprites from the particle data manually and not rendering, but can’t imagne that will perform well at all

Thanks for any information

Rubén

I implemented the solution with MeshRenderers instead of SpriteRenderers but the rest is the same as richardkettlewell suggested.

I have attached the the script that I use. (it can be optimized)

6094830–662349–ParticleSystemOrderInLayer.cs (8 KB)
6094830–662355–QuadMeshParticles.asset.txt (2.76 KB)

1 Like

Thanks a lot for sharing the code.

The most pressing problem we had right now was that when throwing a projectile that left world space particles, the order of each particle system in the projectile would change all the time as particles spawned and died because it gets rendered ordered by its bounds.
For now the change we made was, using a sorting group with default values in the root of the projectile and then use orderinlayer within so that each projectile gets rendered as a whole, this doesn’t fix the issue your code fixes, but at least it behaves consistently and a bit better than before.

Will try at some point your code for some particle systems but I fear a bit that the performance will suffer a lot since this is a mobile game.

Again, thanks a lot, for the code and the quick response.

Rubén