- Home /
The question is answered, right answer was accepted
[SOLVED]Multiple Trail Renderers not sorting properly. Help ?
Hey guys, I was making an asssignment ( drawing game ) with Trail Renderers. I have a single script to generate it wherever the user touches the screen ( all this works well ), but I have a script that changes it's color ( Material - Sprite/Default) to either of 4 colors using butttons. However when I draw it, I get it like this example Actually in this, I drew the red line in the last but it's at the bottom. Is there a way I can make the Trail Renderer draw over the former one no matter what the color is ? I mean how do I overlap it ? Thanks .
Answer by Bunny83 · Sep 22, 2017 at 11:46 AM
Uhm at what "depth" do you draw your lines? Do you really use a TrailRenderer or a LineRenderer? TrailRenderers do disappear automatically.
If you use LineRenderers you can use localspace coordinates instead and then you can place the line renderers in the z position you like in case you want to reorder them. However simply moving each new line slightly closer to the camera will make it draw on top of all others.
If you want to use worldspace coordinates (which is the default) you would need to specify the depth directly in all the positions you generate.
I use Trail Renderers with infinite disappearance time, what do I do ?
Well, using a trail renderer that way is possible but may has some additional overhead as the trail renderer has to check every frame if it has to extend itself.
Though the same thing applies to the trail renderer. It's a 3d component. So just set an appropriate z value when you're moving it around. It wouldn't make much sense to post an example since it might be something completely different of what you're currently doing. Can you post your drawing code?
Here is the Update Function snippet https://hastebin.com/enidiyajaw.cs
Answer by hexagonius · Sep 22, 2017 at 08:50 AM
A linerenderer makes use of one or more materials. It uses a certain queue, most likely 3000 for transparency in your case. I guess you're using the same material despite the color change, which means its 3000 for all of them, and therefore in arbitrary order to be rendered. You can adjust the queue by changing the materials renderqueue to accending values (3001, 3002...)
https://docs.unity3d.com/ScriptReference/Material-renderQueue.html
That kinda fixed it, but now the ones with lower render queue values go under the higher ones, how do I fix it such that every line overlaps or crosses OVER the previous one no matter what it's material or render queue is ?
first of all, sorry, it wasn't 2000, it was 3000. Second, you mean like real painting? Why don't you texture paint then?