Problem instantiating object over a network

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!

Check the order of the calls. Maybe the "LoadLevel" RPC is send only AFTER the CreateCar call, in which case the Car would be deleted after loading the new level. Maybe it's not being executed at all because of the Application.LoadLevel("mylevel"); being called first.

Furthermore, this doesn't seem right to me: carTransform.networkView.RPC("EnableDriving", Network.connections[0]); I think this does not proberly work on the server.

I had believed that level loading was a synchronous call, but in fact it sets a flag to load the level once it finishes the main loop. This meant that my calls to create the object were actually occurring before the new level was loaded (and then immediately destroyed). The proper thing to do is to Load the level, and then put the car creation code (or any code that's supposed to occur after the level load) in OnLevelWasLoaded.

I met the same question and solved it at last. You may check out This thread for detail. Enjoy.