Trying to draw a box with Line Renderer, trouble

EDIT: So it seems to work if I just instantiate one gameobject and not the 4 to make up the four sections of the line. The hell? Can you only have one line renderer in the scene? I DO have them as seperate gameObjects, each with their own line renderer… Hmm.

So I am trying to draw a box on the screen with line renderer. was able to draw a single line no problem, but now I cant get it to work. Not sure what happened…

I have a prefab with a line renderer component, I have tried changing around the properties. When I drag it into the scene, its fine. See picture:


But when I instantiate the prefab from my script, it shows up blank!

code:

GameObject top = Instantiate(linePrefab, new Vector3(curMousePos.x, (curMousePos.y - 1), curMousePos.z), Quaternion.identity) as GameObject;

Picture of the blank instantiation:

I am at a loss, I cant figure out why it is blank when I instantiate via code. Cant find anything in the manual that describes any special action I need to take with instantiating line renderers. Worse, I had it working fine as a single line, now when trying to instantiate multiple lines it doesnt seem to work - arg!

I just tried what you did, and it worked fine for me. Created an empty game object and added a line renderer to it, prefab’d it, deleted the original and brought back the prefab and it worked as expected.

Couple of things:

The points in the Positions array are in world space and ignore the parent’s transform by default, so even if the object is where you want it, it’s possible the lines are not.

When you chain more than one line on a given line-renderer it ends up getting pinched at various points along it, depending on the angle between consecutive segments. This is probably not what you want.

You can only have one line-renderer per gameobject, so to make a square, you want four gameobjects with one line per object.