Can not make RPC calls during Start()

Hi!

Last week I started working on a network project in Unity. I have been using unity for quite a while and are familiar and comfortable with the documentation.

The Problem:

Making RPC-calls is a pice of cake (Thanks Unity) but there seems to be some problems…
Making a RPC-call while playing the game is fine (doing this in the Update() loop) but when trying to do it in the Start() function fails.

I looked at the Execution order documentation to see if I needed to set the Network view before the monobehaviour making the RPC-call but no improvement. I also check to see if the Network view component is there before running my RPC-call and it says that it is there but i still get no response.

Here is the example that i have been using:

private var runOnce : boolean = false;
private var startTime : float;

function Start(){

  startTime = Time.time;
  if (networkView){
	
	Debug.Log("NetworkViewExists!");
	networkView.RPC ("PrintText", RPCMode.All, "Hello worldASDASDASDASDASDASDASDA!");

  }

}

function Update(){
  if (!runOnce && Time.time - startTime > 0.4){
	networkView.RPC ("PrintText", RPCMode.All, "Hello worldASDASDASDASDASDASDASDA!");
	runOnce = true;
  }

}

@RPC
function PrintText (text : String, info : NetworkMessageInfo)
{
    Debug.Log(text + " from " + info.sender);
}

If i set the wait to a time like 0.4 seconds that call comes through but anything lower then that is just lost and the start call is never run at all. I will get a result if I make a yield WaitForSeconds(1) and then running the RPC-call from Start. Another thing i have tried is to make the call AllBuffered but no difference.

Output:

NetworkViewExists!
UnityEngine.Debug:Log(Object)
RPCTest:Start() (at /Users/patriknyblad/Dropbox/carmine/Games/NetworkTest/Assets/RPCTest.js:9)

Hello worldASDASDASDASDASDASDASDA! from -1
UnityEngine.Debug:Log(Object)
RPCTest:PrintText(String, NetworkMessageInfo) (at /Users/patriknyblad/Dropbox/carmine/Games/NetworkTest/Assets/RPCTest.js:27)
UnityEngine.NetworkView:RPC(String, RPCMode, Object)
RPCTest:Update() (at /Users/patriknyblad/Dropbox/carmine/Games/NetworkTest/Assets/RPCTest.js:18)

Wrapup:

Why cant I make an RPC-call in the Start() function and why cant I make an RPC-call until 0.4 seconds from the start of the component?

OK!

So my project was based on a few scripts from the Unity Network Tutorial and i have not read them thoughroly enough. A NetworkView belongs to a Network.group, unity sets up a default group with ID 0 for you. You can offcourse split your communication into different groups and handle traffic the way you want to.

Now that we access the Network.group we can set it to receive or not receive network messages which in turn one of the Unity Scripts was doing.

The Unity Network Level Load disables communication over Network.group 0 when loading a new level and waits for the level to load before enabling the network messages again. It is doing this for good reason tho because you might recieve calls from objects in the old level while you have loaded the new one because your other clients are slow and have not yet got the update or due to queued messages through RPC or sync.

My simple solution is to create a new network group at load of the script and then i set the sending to enabled for this group and add my networkview to that network group.

I see what I did wrong and now it works in my sample project. I just have to implement it into my real project.

I hope this is good reading for someone else out there!