- Home /
Unity2D Sorting Layers with Particle Systems
Hey Everyone, I have a problem here that's very frustrating, and I'm thinking (hoping) it's because I'm doing missing something very obvious. I'm using Unity2D and I have a particle system. The problem is simple - The particle system runs and works, but the particle system displays behind every single gameobject. No matter what I do, I can't get it to display in front of any sprite. In fact, it is even hidden behind the background. In case you are saying to yourself, "This question looks familiar", you are right! It's been asked (and answered), but I have not been able to find a solution that works for me. The main solution I have found is to change the sorting layer name of the Particle System. I have done that, but it does not work. Here is my code:
this.GetComponent<ParticleSystem>().renderer.sortingLayerName = "Enemy";
Does anyone have any ideas?
Thanks!
NOTE: I am using a Shuruken Particle System
Answer by Kazenojin · Aug 05, 2015 at 07:57 AM
I think i got it. Go to renderer in your particle system and change Order in Layer to amount u need. Works for me perfectly.
Unfortunately, this doesn't work in my case. For some reason, it won't take on that sorting layer unless I remove the SpriteRenderer and add it back (as mentioned in my answer). In general, though, this solution is the correct way to sort a particle system.
lol im so blind i didnt see the there is order in layer there
Answer by Jonesy19 · Mar 31, 2015 at 04:22 PM
I finally debugged the issue and have come up with a workaround (though, I'm not really sure what the exact cause is. I think it might might actually be a bug in Unity.
Anyways, it deals with the SpriteRenderer and the order in which it is applied to the gameobject (relative to the Particle System)...In my case, I was trying to apply a particle system to a gameobject that already had a SpriteRenderer component attached to it. For some reason, this eliminates any possibility of putting that Particle System in any sorting layer other than the one that is furthest back. The workaround I found was to remove the SpriteRenderer, and then add it (or just create a whole new gameobject and add the Particle System first). After doing this, I was able to change the sorting layer of the particle system. Another workaround would be to create a separate particle system gameobject and attach it (as a child) to the main gameobject.
Yes, that solved my problem! Thank you very much!!
Answer by gkomaragunta · Oct 31, 2018 at 12:51 PM
I know this is an old thread, i'm putting a work around here:
Alternatively, you can specify when your particle system has to be rendered. You can check the particle systems rendering order in frame debugger and if you want to push it front, you can increase renderqueue value by increasing the Custom Render Queue value.
Answer by BomboBombom · Jul 06, 2016 at 02:26 PM
I had a similar issue with Canvas where particles would render above my UI, even if I put the particle system at a sorting layer that was under the UI. I solved this by changing the sorting order layer on the canvas to 1 instead of 0.
I'm not sure if a similar solution would work for Sprites.