Search Unity

Particle Systems with Sprites (Order In Layer)

Discussion in 'General Graphics' started by Ukitakemalcom, Apr 4, 2017.

  1. Ukitakemalcom

    Ukitakemalcom

    Joined:
    Nov 10, 2015
    Posts:
    19
    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.

    Captura.PNG

    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... :(

    Thank you.
     
    Storm4_ and angelonit like this.
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,282
    Hi. Its something we plan to look into in the near future.
     
  3. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,285
    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.
     
    Ukitakemalcom likes this.
  4. change

    change

    Joined:
    Jul 12, 2014
    Posts:
    12
    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!
     
  5. Ukitakemalcom

    Ukitakemalcom

    Joined:
    Nov 10, 2015
    Posts:
    19
    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!
     
  6. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,285
    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.

    https://docs.unity3d.com/ScriptReference/ParticleSystem.GetParticles.html
    https://docs.unity3d.com/ScriptReference/ParticleSystem.GetCustomParticleData.html
    https://docs.unity3d.com/ScriptReference/ParticleSystem.SetCustomParticleData.html
     
  7. Ukitakemalcom

    Ukitakemalcom

    Joined:
    Nov 10, 2015
    Posts:
    19
    Right now we are using the new option Transparency Sort Mode Custom Axis to order all the sprites in the scene with this configuration:

    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!
     
    richardkettlewell likes this.
  8. rubeng

    rubeng

    Joined:
    Apr 20, 2013
    Posts:
    60
    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
     
  9. Ukitakemalcom

    Ukitakemalcom

    Joined:
    Nov 10, 2015
    Posts:
    19
    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)
     

    Attached Files:

    richardkettlewell likes this.
  10. rubeng

    rubeng

    Joined:
    Apr 20, 2013
    Posts:
    60
    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