Unity - Scripting API: LineRenderer

class in UnityEngine

/

Inherits from:Renderer

/

Implemented in:UnityEngine.CoreModule

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Switch to Manual

Description

The line renderer is used to draw free-floating lines in 3D space.

This class is a script interface for a line renderer component.

// Programatically add a LineRenderer component and draw a 3D line.
using UnityEngine;

public class LineRendererExample : MonoBehaviour { void Start() { // Add a LineRenderer component LineRenderer lineRenderer = gameObject.AddComponent<LineRenderer>();

// Set the material lineRenderer.material = new Material(Shader.Find("Sprites/Default"));

// Set the color lineRenderer.startColor = Color.red; lineRenderer.endColor = Color.green;

// Set the width lineRenderer.startWidth = 0.2f; lineRenderer.endWidth = 0.2f;

// Set the number of vertices lineRenderer.positionCount = 3;

// Set the positions of the vertices lineRenderer.SetPosition(0, new Vector3(0, 0, 0)); lineRenderer.SetPosition(1, new Vector3(1, 1, 0)); lineRenderer.SetPosition(2, new Vector3(2, 0, 0)); } }

Properties

Property Description
alignmentSelect whether the line will face the camera, or the orientation of the Transform Component.
applyActiveColorSpaceSet whether colors will be converted appropriately before being passed to the GPU when using Linear Rendering.
colorGradientSet the color gradient describing the color of the line at various points along its length.
endColorSet the color at the end of the line.
endWidthSet the width at the end of the line.
generateLightingDataConfigures a line to generate Normals and Tangents. With this data, Scene lighting can affect the line via Normal Maps and the Unity Standard Shader, or your own custom-built Shaders.
loopConnect the start and end positions of the line together to form a continuous loop.
maskInteractionSpecifies how the LineRenderer interacts with SpriteMask.
numCapVerticesSet this to a value greater than 0, to get rounded corners on each end of the line. The default is 0.
numCornerVerticesSet this to a value greater than 0, to get rounded corners between each segment of the line.
positionCountSet/get the number of vertices.
shadowBiasApply a shadow bias to prevent self-shadowing artifacts. The specified value is the proportion of the line width at each segment.
startColorSet the color at the start of the line.
startWidthSet the width at the start of the line.
textureModeChoose whether the U coordinate of the line texture is tiled or stretched.
textureScaleA multiplier for the UV coordinates of the line texture.
useWorldSpaceIf enabled, the lines are defined in world space.
widthCurveSet the curve describing the width of the line at various points along its length.
widthMultiplierSet an overall multiplier that is applied to the LineRenderer.widthCurve to get the final width of the line.

Constructors

Constructor Description
LineRendererInstead of using this constructor, either use GameObject.AddComponent<LineRenderer>(), or if you have an existing LineRenderer component on a GameObject, use GameObject.GetComponent<LineRenderer>().

Public Methods

Method Description
BakeMeshCreates a snapshot of LineRenderer and stores it in mesh.
GetPositionGet the position of a vertex in the line.
GetPositionsGet the positions of all vertices in the line.
SetPositionSet the position of a vertex in the line.
SetPositionsSet the positions of all vertices in the line.
SimplifyGenerates a simplified version of the original line by removing points that fall within the specified tolerance.

Inherited Members

Public Methods

MethodDescription
BroadcastMessageCalls the method named methodName on every MonoBehaviour in this game object or any of its children.
CompareTagChecks the GameObject's tag against the defined tag.
GetComponentGets a reference to a component of type T on the same GameObject as the component specified.
GetComponentInChildrenGets a reference to a component of type T on the same GameObject as the component specified, or any child of the GameObject.
GetComponentIndexGets the index of the component on its parent GameObject.
GetComponentInParentGets a reference to a component of type T on the same GameObject as the component specified, or any parent of the GameObject.
GetComponentsGets references to all components of type T on the same GameObject as the component specified.
GetComponentsInChildrenGets references to all components of type T on the same GameObject as the component specified, and any child of the GameObject.
GetComponentsInParentGets references to all components of type T on the same GameObject as the component specified, and any parent of the GameObject.
SendMessageCalls the method named methodName on every MonoBehaviour in this game object.
SendMessageUpwardsCalls the method named methodName on every MonoBehaviour in this game object and on every ancestor of the behaviour.
TryGetComponentGets the component of the specified type, if it exists.
GetInstanceIDGets the instance ID of the object.
ToStringReturns the name of the object.
GetClosestReflectionProbesReturns an array of closest reflection probes with weights, weight shows how much influence the probe has on the renderer, this value is also used when blending between reflection probes occur.
GetMaterialsReturns all the instantiated materials of this object.
GetPropertyBlockGet per-Renderer or per-Material property block.
GetSharedMaterialsReturns all the shared materials of this object.
HasPropertyBlockReturns true if the Renderer has a material property block attached via SetPropertyBlock.
ResetBoundsReset custom world space bounds.
ResetLocalBoundsReset custom local space bounds.
SetMaterialsAssigns the shared materials of this renderer using the list of materials provided.
SetPropertyBlockLets you set or clear per-renderer or per-material parameter overrides.
SetSharedMaterialsAssigns the shared materials of this renderer using the list of materials provided.

Static Methods

MethodDescription
DestroyRemoves a GameObject, component, or asset.
DestroyImmediateDestroys the specified object immediately. Use with caution and in Edit mode only.
DontDestroyOnLoadDo not destroy the target Object when loading a new Scene.
FindAnyObjectByTypeRetrieves any active loaded object of Type type.
FindFirstObjectByTypeRetrieves the first active loaded object of Type type.
FindObjectsByTypeRetrieves a list of all loaded objects of Type type.
InstantiateClones the object original and returns the clone.
InstantiateAsyncCaptures a snapshot of the original object (that must be related to some GameObject) and returns the AsyncInstantiateOperation.

Operators

OperatorDescription
boolDoes the object exist?
operator !=Compares if two objects refer to a different object.
operator ==Compares two object references to see if they refer to the same object.

Messages

MessageDescription
OnBecameInvisible OnBecameInvisible is called when the object is no longer visible by any camera.
OnBecameVisible OnBecameVisible is called when the object became visible by any camera.