- Home /
Network.Instantiate a Non-prefab
I've been trying to figure this one out for hours with no luck. I'm trying to Instantiate a line renderer across a networked game, but I need to calculate how one player draws the line and then have it instantiated across the network. My code looks something like this:
if(Input.GetButtonDown("Fire1")){
newLine = Instantiate(line, transform.position, transform.rotation);
LR = newLine.GetComponent(LineRenderer);
LR.SetVertexCount(1);
point1 = FindNewPoint();
LR.SetPosition(0, point1);
}
if(Input.GetButtonUp("Fire1")){
LR.SetVertexCount(2);
point2 = FindNewPoint();
LR.SetPosition(1, point2);
EditorUtility.ReplacePrefab(newLine, Resources.Load("RecalculatedLineRenderer"));
Destroy(newLine);
canDraw = false;
Network.Instantiate(Resources.Load("RecalculatedLineRenderer"),transform.position, transform.rotation, 0);
GC.networkView.RPC("CalculateAngle", RPCMode.AllBuffered, point1.x, point1.y, point2.x, point2.y);
The problem is I don't know how to access the point vectors of the line renderer after it's been created, as far as I know the only way to change those points is through the LineRenderer.SetPosition();, otherwise I'd be able to instantiate across the network initially then send out an RPC and change those points after doing the calculations for drawing the line.
So I went to this method of instantiating locally, doing the calculations, then replacing the prefab with EditorUtility.ReplacePrefab() and then doing the Network.Instantiate(). I thought it was working till I tried to make a build to test the networking. I guess you can't make a build if you use EditorUtility >.< . This would be easier if I could just do Network.Instantiate(newLine : GameObject, etc...); but unlike a regular Instantiate(), Unity will only do prefabs for Network.Instantiate()... Is there something I'm missing? or any ideas on how I could pull this off?
Answer by nowhereman · Sep 05, 2011 at 08:26 AM
GAAAAh. Thought about it a little more after posting that. I could just instantiate then do an RPC call and do LineRenderer.SetPosition(); So I just had to add a line with
newLine.networkView.RPC("DrawLine", RPCMode.AllBuffered, point1, point2);
Did not think that one through all the way...>.<