- Home /
Particle System rendering behind Sprites
I'm trying to use a particle system with my 2d project.
I have it placed on a higher z-index and can see it when the particle systems materials shader is bumped diffuse, however when I change it to something like unlit/transparent it will always render behind the sprites regardless of what the z-index of the particle system is.
Since there isn't many resources on working with 2d in 4.3 is there something I don't know about particle systems or the new 2d stuff that is causing this issue?
I haven't played with the new 2d system yet, but it sounds like the order of the object in the render queue is different between the different shaders. You can either set the $$anonymous$$aterial.renderQueue via script or hard code it in the shader, if you create your own shader or downloaded the default shaders source. I can't guarantee it will fix the problem, but moving the renderQueue to say something like 4000 may work. The 2D sprites are probably drawn in the transparent queue range, same as particles, so that may solve the issue.
I tried changing the particle materials render queue to 4000 but it hasn't changed anything and I'm not sure I want to start digging into the shaders source.
Hi, I don't know if this thread is still open, but I am having the same issue with HALO effect. $$anonymous$$y halo effect is not visible when I have background game object, but if I dragged the background game object out of the view, the HALO effect is shown properly.
I tried different things suggested by answer.unity from adding new script to add sorting layer manager to adding codes as suggested here, but none of them are working. When using adds on for sorting layer manager, only game object shown on the list, but the halo effect is not shown as separate entries on sorting layer manager. When displaying in 3D, it shows correctly that the sprites and halo are located between camera and background texture, but it won't be shown at all on both game and scene windows. Any idea how to fix it?
The way I structured my game is one background game object, prefab containing 4 child game objects, and halo effect attached to all 4 child game objects. Because they are children, Unity won't allow me to add additional game object under the children for the halo. Any help is appreciated!
Thanks! Eric
Answer by Stone-Legion · Nov 23, 2013 at 10:09 AM
Figured it out. It seems odd you have to go this far but here's the solution.
On the Particle System object you've created, create a C# script and name it "ParticleSortLayerScript" or whatever else you want to call it. You can also add this into your code if you have a script attached but make sure it gets added to the Start() method.
Now you have to manually code in what layer you want the particle system to apply to. It seems that by default, the particle system gets sent behind every other layer, which is why you have to force it to be in a layer in front for the camera to see.
Code to do this is:
void Start ()
{
//Change Foreground to the layer you want it to display on
//You could prob. make a public variable for this
particleSystem.renderer.sortingLayerName = "Foreground";
}
Note that for my project Foreground is the name of the layer I want my particles to display, but yours may be different. If you dont know what I mean by Layer, I'm talking about sorting layers. On the Top right of the Unity Editor you should see a drop down called "Layers", click this to see the layers in your project. You can add additonal layers if you like as per http://docs.unity3d.com/Documentation/Components/Layers.html
You're right about sorting layers, I also use it to render various object properly in 4.3. However, for reasons unknown, I can't get this working with lights (halo, point, etc). I set the correct layer via script and it works with any object but lights seem to be rendered always "under" the texture (see attached screenshot).
Any idea how to fix it?
Thanks - this helped me. You can also do this @ instantiation time ins$$anonymous$$d of adding a script to the particile system.
if (deathAnimation!=null){
GameObject ps=(GameObject)GameObject.Instantiate(deathAnimation);
ps.transform.position=transform.position;
ps.renderer.sortingLayerName="Foreground";
}
I have been struggling with this problem for ages. Your fix wasn't working for me.
It turns out that if you have your particleSystem component on an object that also has a sriteRender component then particleSystem.renderer will actually return the render for the sprite, rather than for the particleSystem.
I was able to work around the issue by creating a separate object for the particleSystem and making it a child of the original object.
In order to stay away from hardcoding layers I did this:
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(SpriteRenderer))]
[RequireComponent(typeof(ParticleSystem))]
public class SetParticleRenderLayerScript : $$anonymous$$onoBehaviour {
// Use this for initialization
void Start () {
SpriteRenderer spriteRenderer = GetComponent<SpriteRenderer>();
particleSystem.renderer.sortingLayerID = spriteRenderer.sortingLayerID;
particleSystem.renderer.sortingOrder = spriteRenderer.sortingOrder;
}
}
This allows me to add a spriterenderer to the particle system prefab and set the layers in that ins$$anonymous$$d.
Answer by KonkyBean · Mar 10, 2015 at 09:47 AM
Not sure if this was in Unity 4.6, but in Unity 5, go to your particle's Inspector, expand "Renderer" and you should see the fields "Sorting Layer" and "Order in Layer" (close to the bottom). Select the sorting layer that you wish the particles to appear on.
This fixed my issue (particles appearing behind background) and hopefully it'll fix yours.
O good, glad to hear they added this, Thanks $$anonymous$$onky!
I was having the same problem and this solution worked for me. No script writing needed. Thank you friend!
This feature isn't available in Unity 4.6, let alone 4.3
Answer by KarmaAdjuster · Apr 16, 2017 at 08:46 AM
I encountered a similar problem but for seemingly entirely different reasons. The problem was made clearer when I switched from viewing the scene in 2D to 3D. The issue was that that particle system was emitting the particles AWAY from the camera, and thus behind all of the other sprites in the scene.
My solution was to set either the X or Y rotation to 180 degrees.
Edit: Oops. I replied twice. I couldn't see that I had replied, and just assumed the website ate my comment.
Answer by Panx · Jan 22, 2014 at 06:25 AM
I just ran into this same issue, and swore up and down it was sprite-related, since that was the last thing I added to my project.
However, I just realized I'd been calling Play() and Stop() on every Update() cycle, rather than just once and letting them do their thing.
This was also causing my particle system to fail to start (unless it started pre-warmed for some reason).
Just a thought, if someone else stumbles into this thread and can't get the above green-answer to work for them.
Answer by ManiacPyro101 · Aug 19, 2014 at 07:34 AM
It seems that particles like to be seen in the 0 sorting layer, so what i have done is put my 2D content in -1,-2 layers, this should fix your problem