LineRenderer not showing in build

I have a LineRenderer that appears in the Scene and Game preview windows when I am running the game in the editor. However, it does not appear in the final build. (it also shows up in the small camera preview window)

My cull mask is ‘Everything’ and I am not using layers.

The LineRenderer is created in a script.

I also tried replacing this feature with GL.Lines. They only render in the Game Preview window. I don’t know if these issues are related, but that is all the information I have.

I am not sure what code would be helpful to see. Here is the Line Rendering block:

// Update is called once per frame
	void Update () 
	{
		if(m_bTracked) //change this to GL Lines eventually
		{
			LineRenderer lineRenderer = GetComponent<LineRenderer>();
			
			float a = 0.5f*(m_RMax+m_RMin);
			float b = a*Mathf.Sqrt(1-(m_e*m_e));
			float Z = 0.0f;
			
			for(int i=0; i<360-1; i++)
			{
				float X = a*Mathf.Cos(Mathf.Deg2Rad*i) - (a*m_e);
				float Y = b*Mathf.Sin(Mathf.Deg2Rad*i);
				Vector3 pos = new Vector3(X,Y,Z);
				
				pos = m_OrbitMat.MultiplyPoint(pos);			
				
				pos = new Vector3(-pos.x,pos.y,pos.z);
				lineRenderer.SetPosition(i,pos);
			}
			
			float X1 = a - (a*m_e);
			float Y1 = 0;
			Vector3 pos1 = new Vector3(X1,Y1,Z);			
			pos1 = m_OrbitMat.MultiplyPoint(pos1);	
			pos1 = new Vector3(-pos1.x,pos1.y,pos1.z);
			lineRenderer.SetPosition(360-1,pos1);
		}	
		
	}

Let me know what else might be helpful.

So, I seem to have fixed this, but I would still like to understand why.

I added a public Material to the class and set it in the Editor. I actually only set it in one instance of the script (there are currently two in the scene) and don’t use it at all in the script itself, but this fixes both the LineRenderer and the GL.Lines for both instances of the Satellite.

Here is the initialization code:

void Start () 
	{		
		CreateLineMaterial();
		
		LineRenderer lineRenderer = gameObject.AddComponent<LineRenderer>();
		lineRenderer.useWorldSpace = true;
		lineRenderer.material = new Material(Shader.Find("Particles/Additive"));
		lineRenderer.SetColors(Color.green,Color.green);
		lineRenderer.SetWidth(20.0f*GR.m_GameScale,20.0f*GR.m_GameScale);
		lineRenderer.SetVertexCount(360);    		
		
		m_bTracked = true;
	}

static void CreateLineMaterial() 
	{
	if( !lineMaterial ) 
		{
		lineMaterial = new Material( "Shader \"Lines/Colored Blended\" {" +
			"SubShader { Pass { " +
			"    Blend SrcAlpha OneMinusSrcAlpha " +
			"    ZWrite Off Cull Off Fog { Mode Off } " +
			"    BindChannels {" +
			"      Bind \"vertex\", vertex Bind \"color\", color }" +
			"} } }" );
		lineMaterial.hideFlags = HideFlags.HideAndDontSave;
		lineMaterial.shader.hideFlags = HideFlags.HideAndDontSave;
		}
	}