- Home /
Problem with line renderer material
I am trying to just add a material to the line that is rendered but I am only seeing a magenta line. The material is in the project and so it is not missing, but yet the line renderer just seems to ignore the material I have assigned to it. Code show below;
var startWidth = 0.05;
var endWidth = 0.05;
var aMaterial : Material;
private var line : LineRenderer;
function Start ()
{
line = this.gameObject.AddComponent(LineRenderer);
//line.material = new Material (Shader.Find("Particles/Additive"));
line.SetWidth(startWidth, endWidth);
line.SetVertexCount(2);
line.material = aMaterial;
line.renderer.enabled = true;
}
Any help would be greatly appreciated.
Answer by FerdieQO · Nov 11, 2013 at 03:17 PM
First of all, this line = this.gameObject.AddComponent(LineRenderer);
should be this line = this.gameObject.AddComponent();
. Argument of the AddComponent should be empty, only the type assignment operators <> to define its type. But that's not going to solve your problem.
I've been stuck with the same problem but luckily I found a solution. You'll need a simple, constant, self-illuminating material (so NOT one of the Particle materials) and assign that one to the lineRenderer (this works best in the editor).
Add a LineRenderer component to the gameobject via the Unity Editor
Change this:
line = this.gameObject.AddComponent(LineRenderer);
to this:line = gameObject.GetComponent();
Make a new material with a Self-Illumin/Diffuse and assign a color to it (no texture!)
Assign the new material to the LineRenderer component in the Unity Editor
This worked for me, hopefully you'll be helped with this too :)
Answer by FlightOfOne · Feb 24, 2016 at 01:31 AM
I know this is an old post but might help someone else. To get the built in start / end colors this is what I did. Not that this is a very quick solution.
Create an Empty object
Add component > Effects> Line Renderer
Create a material
Change the Shader Particles Alpha Blend. Particles>Alpha Blend.
Add the Material to Line Renderer Materials
Most of the particle shaders will work but Alpha blend gave me the best look. I didn't have to do any coding for this part. Only code I had to display the line was setting the positions.
///------------------------------
LineRenderer lr;
Void Start()
{
lr = GetComponent<LineRenderer>();
lr.SetPositions(points); //points=an array of points(Vector3)
}
///------------------------------------------
Answer by ShawnFeatherly · Nov 28, 2015 at 07:00 AM
Self-Illumin/Diffuse didn't work well for me. This 6 line shader taken from another similar question did tho: http://answers.unity3d.com/questions/34437/shader-needed-for-gradients-using-a-linerenderer.html
Shader "Vertex Colors" {
Subshader {
BindChannels {
Bind "vertex", vertex
Bind "color", color
}
Pass {}
}
}
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Can't select shader help! 1 Answer
Chain Texture for Line Renderer 1 Answer
Android Audio Delay 0 Answers
Problem with SSL CA cert 0 Answers