When I try to instantiate a prefab over the network, I do not see the objects appear, and I see the following in the client's log:
Receiving state for an object whose network view exists but the observed object no longer exists
The code looks roughly like this:
public class MyClass : MonoBehaviour {
public Transform CarPrefab;
public void Awake() {
DontDestroyOnLoad(this);
networkView.group = 1;
}
public void OnGUI() {
if (Layout.Button("Create Car")) {
networkView.RPC("LoadLevel", RPCMode.AllBuffered);
CreateCar();
}
}
[RPC]
public void LoadLevel() {
this.lastLevelPrefix = lastLevelPrefix;
Network.SetSendingEnabled(0, false);
Network.isMessageQueueRunning = false;
Network.SetLevelPrefix(lastLevelPrefix);
Application.LoadLevel("mylevel");
Network.isMessageQueueRunning = true;
Network.SetSendingEnabled(0, true);
}
public void CreateCar() {
Transform carTransform = Network.Instantiate(CarPrefab, position, rotation, 0) as Transform;
carTransform.networkView.RPC("EnableDriving", Network.connections[0]);
}
}
This code is all run on the server. My best guess is that the scene prefix for the Instantiate command is the old scene, and thus the instantiate never fully succeeds. If I have a network view not destroy on load, is there something I need to do to make it's network view get a new id when I load a new scene?
Thanks!