- Home /
LineRenderer not Displaying in 2D
I'm trying to create a line when the player clicks, drags, and then releases the mouse. The object is created with all the right components, but nothing is displayed and isVisible is false. The collider does not show up in gizmo view either.
The components are visible and editable in the hierarchy, but not in the game. Here's my code: (m_barrierMaterial)is a public material that has worked in other instances)
barriers.Add( new GameObject( "Barrier" ) );
GameObject barrier = barriers[barriers.Count - 1];
LineRenderer line = barrier.AddComponent<LineRenderer>() as LineRenderer;
line.material = m_barrierMaterial;
line.SetVertexCount( 2 );
line.SetPosition( 0, startPoint );
line.SetPosition( 1, endPoint );
BoxCollider2D collider = barrier.AddComponent<BoxCollider2D>() as BoxCollider2D;
How/where are you setting start and end point? Are you making sure to convert screen space coordinates to world space coordinates before you instantiate your object?
Answer by hammad-zahid · Nov 09, 2015 at 01:08 PM
Here is simple solution:
set layers: verified solution:
lineRenderer.sortingOrder = 4; lineRenderer.sortingLayerName = "UI";
Your answer
![](https://koobas.hobune.stream/wayback/20220613151132im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Distribute terrain in zones 3 Answers
BoxCollider size 1 Answer
How to smoothly rotate an object through just one axis 1 Answer