- Home /
Trail Renderer and Sorting Layer problem
It's a 2D game. I have a bullet with a trail renderer and the trail renderer is visible in the #Scene but it isn't visible in the Game screen of the Unity. When I remove background of the game, it shows the trail renderer. So I figured out it's sorting layer problem with trail renderer.
I tried renderer.sortingLayerName and renderer.sortingOrder, but no effect. (It worked on particle system).
How to set sorting layer to trail renderer ? or Is there any alternative way to render trail of the bullet? Thank you.
Thank you. I ran into the exact same issue today and your script has sorted it out for me.
Answer by saruul34 · Jan 03, 2014 at 05:28 AM
Finally I have sorted it out. (Trail renderer has own renderer, I put there sortingLayerName.) I attached following new script to bullet's parent. And it works as I expected. Whoever has a same problem, try it.
public TrailRenderer trail;
// Use this for initialization
void Start () {
trail.sortingLayerName = "Background";
trail.sortingOrder = 2;
}
I have tried this but I can't able to get success!!! Here is a picture for this...
Here is my code for this purpose:
private TrailRenderer my$$anonymous$$eshRenderer;
//
public string layerName;
public int sortOrder;
void Start ()
{
my$$anonymous$$eshRenderer = GetComponent<TrailRenderer> ();
my$$anonymous$$eshRenderer.sortingLayerName = layerName;
my$$anonymous$$eshRenderer.sortingOrder = sortOrder;
}
You can change sortingOrder and sortingLayer in the trailRenderer component from the inspector too.
yes you are right but this kind of feature become available later on before this kind of functionality not exist in Trail Renderer component.
Also trail renderer shader type also important, all shaders are not compatible with trail renderer.
Answer by LocalNoob · Jul 14, 2018 at 02:35 PM
Make sure the material of your trail renderer has a shader of type Sprites/Default, otherwise sorting layers wont work
Answer by jpdodson42 · Feb 09, 2018 at 06:54 AM
Just to add onto this thread in case somebody else comes across it. It seems like there are a number of problems you can encounter when adding a trail renderer to a sprite and not having it display.
Eventually I found out what was going on in my case. I was adding a trail renderer to a sprite that was (obviously) on a canvas. The canvas property "Render Mode" is by default set to "Screen Space - Overlay", but if you want to display a trail renderer, the canvas needs to be able to see it. Having the canvas set to this mode "blocks" it. You can change the canvas "Render Mode" to "Screen Space - Camera" instead, and that should do the trick.
Adding this in case somebody else has the same issue I was having.
Answer by Gunorgunorg · May 12, 2017 at 05:28 PM
I don't know if this still matters because the question was 2 years ago, but it was the top spot when I googled this issue before finding a solution on my own in Untiy 5.
When changing the order in layer you can change the sorting layer as well. So make a new layer and put it above the "Default" layer on the list. Then mark any objects you want the trail renderer(and object creating the trail) on the "Default" Layer and other objects in the other layer.
PS This is the same way I solved text going behind sprites as well just in case that issue arises as well.
I did the same but no luck. $$anonymous$$ine always renders on top of everything. What material are you using with your trail renderer?
Your answer
Follow this Question
Related Questions
Black Trail Rendering in 2D game 1 Answer
Use trail renderer for path following? 2 Answers
Trail Renderer Fade Out on Button Press 0 Answers
Fixed size trail renderer 1 Answer