Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
6
Question by wijesijp · Apr 23, 2014 at 11:30 AM · linerenderer

LineRenderer appear behind sprites

I am making a 2D game.

I have my back ground created with sprites. The material of the sprites is Sprites-Default. The sprites have a sorting layer and order in layer.

I have a LineRenderer in the scene and it is appearing behind the sprites. LineRenderer material is using Particales/ Additive. I want the LineRenderer to appear over the sprites.

Any advice on how to fix this?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

6 Replies

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by komodor · Apr 23, 2014 at 11:41 AM

stop using sorting order, use z

sprite os for 2d and linerenderer is for 3d these two systems aren't fully compatible, we solved all problems we had with sprites by setting layer order to 0 and we use z as z-index and it works well for us

Comment
Add comment · Show 7 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image wijesijp · Apr 23, 2014 at 11:54 AM 0
Share

I tried it and it seems to be working ...

if i move the background forward (z to 10) keeping LineRenderer at z 0 I get the behavior i need.

But if I move the LineRenderer backward (z to -10) keeping the background at z 0 I don't get the same behavior.

Any idea why?

avatar image komodor · Apr 23, 2014 at 12:03 PM 0
Share

i am not sure what you mean

camera shows closer objects over the distant objects so if linerenderer is closer then background, then you should see it over the background

avatar image wijesijp · Apr 23, 2014 at 12:19 PM 1
Share

The problem was the points I add to the LineRenderer had the z value 0 even though the LineRenderer was at -10. I moved them backward to -10 and it is working now

avatar image cboxgo · Oct 21, 2014 at 04:18 PM 0
Share

You should be able to set all of your z values to 0, and use layers to keep game objects on top that need to be rendered on top. This is discussed in the 2D tutorials.

Like Joe Van Richter said, set the sortingLayerName in the line renderer. Do this in your Start() method:

line.sortingLayerName = "Your layer where it should go";

avatar image ProgOrion cboxgo · Aug 28, 2018 at 10:20 AM 0
Share

I've tried to use the solution of Joe van Richter, but somehow it doesn't work. I also changed the material and the shader, but it didn't help. What I noticed although that it doesn't matter what I set in the Start() method, the sorting layer always gets back to "Default". This is a test scene particularly for that problem so I don't know what's going on. Do you have any idea maybe?

But the solution suggested by @komodor works.

avatar image redhotchilialex · Dec 17, 2014 at 06:13 PM 0
Share

When I change the z of the positions of linerenderer to -1, it just disappears.

Show more comments
avatar image
15

Answer by Joe van Richter · Aug 19, 2014 at 05:14 PM

You could also set the LineRender to a "higher" sorting layer.

line.sortingLayerName = "Foreground";

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image AceDBA44 · Mar 18, 2016 at 08:19 AM 0
Share

That's the right way to do it. I had to set the line's material as well, otherwise it didn't have any effect.

avatar image motion art game · Apr 08, 2016 at 02:38 PM 0
Share

works for me,thanks a lot

avatar image Tzelon · Nov 17, 2016 at 06:08 PM 0
Share

This is the correct answer and the right way to do it

avatar image ZachariBarnes · Jun 01, 2018 at 04:52 PM 0
Share

This worked for me also. As AceDBA44 mentioned, have to set the line material. "Default Line" worked just fine. Thanks Joe van Richter

avatar image
14

Answer by fabien0102 · Apr 15, 2016 at 09:04 AM

Hello,

To use the property "sortingLayerName" and "sortingOrder", your line must have a material with a shader "Sprite/*" ;)

Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image tanoshimi · Apr 15, 2016 at 10:27 AM 0
Share

That's not true. They're only exposed in the inspector by default for sprites, but you can use them via script on any renderers.

avatar image Jardich · Apr 16, 2016 at 06:12 PM 1
Share

It actually fix my problem, when using the standard shader I coudn't get the lines to show on top of the other sorting layers. Thanks!

avatar image chris44000 · Sep 03, 2016 at 06:12 PM 0
Share

Thank you, it worked for me

avatar image Maras · Aug 24, 2017 at 11:42 AM 0
Share

Sorting layer / order was first thing which came to my $$anonymous$$d, but my material was using standard shader. This fixed my problem. Thanks!

avatar image yukunlinykl · Jan 10 at 08:08 AM 0
Share

It works. Thank you

avatar image
1

Answer by Mikael-H · Aug 03, 2014 at 08:11 PM

Or try this (you need a SpriteRenderer component in the same GameObject)

     LineRenderer line;
     // Use this for initialization
     void Start () {
         line = GetComponent<LineRenderer>();
         SpriteRenderer spriteRenderer = GetComponent<SpriteRenderer>();
         line.sortingLayerID = spriteRenderer.sortingLayerID;
         line.sortingOrder = spriteRenderer.sortingOrder;
     }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by DukeW · Sep 01, 2015 at 11:07 AM

Hey,

Here are my scripts that solve this issue:

 using UnityEngine;
 
 [RequireComponent (typeof (LineRenderer))]
 [ExecuteInEditMode]
 
 public class LineRendererLayer : MonoBehaviour
 {
     public string sortingLayer;
 
     private Renderer getMeshRenderer()
     {
         return gameObject.GetComponent<Renderer>();
     }
     
     void Update()
     {
         if(getMeshRenderer().sortingLayerName != sortingLayer && sortingLayer != ""){
             //Debug.Log("Forcing sorting layer: "+sortingLayer);
             getMeshRenderer().sortingLayerName = sortingLayer;
         }
     }
 }
 

And here is My Editor script to make it easier:

 using UnityEditor;
 using System.Reflection;
 using System;
 using UnityEditorInternal;
 
 [CustomEditor (typeof(LineRendererLayer))]
 public class LineRendererLayerEditor : Editor 
 {
     string[] layers;
     public LineRendererLayerEditor()
     {
         Type internalEditorUtilityType = typeof(InternalEditorUtility);
         PropertyInfo sortingLayersProperty = internalEditorUtilityType.GetProperty("sortingLayerNames", BindingFlags.Static | BindingFlags.NonPublic);
         layers=(string[])sortingLayersProperty.GetValue(null, new object[0]);
     }
 
 
     public override void OnInspectorGUI() 
     {
         LineRendererLayer myTarget=(LineRendererLayer)target;
         //EditorGUI.EnumPopup(new Rect(0,0,100,50),layers);
         int selectedIndex;
         if(myTarget.sortingLayer=="")
         {
             myTarget.sortingLayer=layers[0];
             selectedIndex=0;
         }
         else
         {
             selectedIndex=Array.IndexOf<string>(layers,myTarget.sortingLayer);
             if(selectedIndex==-1)
             {
                 myTarget.sortingLayer=layers[0];
                 selectedIndex=0;
             }
         }
         myTarget.sortingLayer=layers[EditorGUILayout.Popup(selectedIndex,layers)];
         myTarget.enabled = false;
         myTarget.enabled = true;
     }
 }
 

Hope these will help somebody :-)

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
  • 1
  • 2
  • ›

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

34 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Line Renderer bounce 1 Answer

Serialize a LineRenderer 2 Answers

Rendering a smooth polygon like a vector drawing (antialias maybe?) 0 Answers

Avoiding Stiches in Line Render 0 Answers

Making a lineRenderer end 10 units in front of a gameObject. 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges