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?