- Home /
Trail renderer not rendering over sprite background
I'm working on a 2D game and I can't seem to get a trail renderer to appear over a sprite. I have a trail renderer attached to a parent game object (its a projectile). In play mode, I shoot the projectile and I can see the parent object but not the trail. I then disable the background sprite, and I can see both the projectile and the trail. I've tried messing with the transform values of the trail, nothing seems to work.
I've seen various questions related to this, such as this one: http://answers.unity3d.com/questions/593897/trailrenderer-coexisting-with-sprites.html
Most answers deal with attaching a script to the renderer or parent object and setting the sortingLayer and sortingLayerName manually. However, none of the proposed solutions so far have fixed my issue.
Answer by ksakins · Aug 08, 2016 at 01:09 PM
Well, I eventually found the issue to my particular situation, just in case someone has the same problem. So the problem was two things. First, I had to make sure that my trail renderer used particle shaders. Second, I did have to implement the script mentioned in the link above which sets the sorting layer of the trail renderer to above any other sprites that may overshadow it.
Answer by Gunorgunorg · May 12, 2017 at 05:28 PM
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 Background objects in the other layer. I use a trail renderer with the "sprites default" material.
PS This is the same way I solved text going behind sprites as well just in case that issue arises as well.
Answer by jpdodson42 · Feb 09, 2018 at 06:53 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. Then set the camera property to your main camera.
Adding this in case somebody else has the same issue I was having.
This ... dude i was playing around with the line renderer for 2 days couldn't find a way to fix it. thank you !
Answer by agrav0 · Feb 19, 2019 at 06:15 PM
My trail started to show above sprites when i assigned something to the material (default-diffuse) field in advanced section of the component. But then i found its drawing on everything. Then i changed the material to default particle then the sorting layers started to kick in. and everything was find. the trail renderer seems to just trail the material. so the properties of the material are what i think are causing the problems.
Your answer
Follow this Question
Related Questions
TrailRenderer coexisting with sprites 2 Answers
TrailRenderer sorting layer problem. 2 Answers
Sprite Shading 1 Answer
Adding a Sprite 1 Answer
Unity Adds Antialiasing to Texture 2 Answers