Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Network.instantiate in different scene

Discussion in 'Multiplayer' started by Rnd--, Jul 17, 2014.

  1. Rnd--

    Rnd--

    Joined:
    Sep 27, 2012
    Posts:
    30
    Hi Im new in unity networking..
    Im trying to make multiplayer game, Im follow this tutorial -> http://www.paladinstudios.com/2013/07/10/how-to-create-an-online-multiplayer-game-with-unity/
    everythings was alright and the tutorial works perfectly

    but I want to make game in different scene.
    so 1st scene is lobby, and 2nd scene is game play
    but when Im making network instantiate in 2nd scene, the 1st player did not appeared in client, just the 2nd player. but in host its appeared perfectly..

    and the client always show this error
    View ID AllocatedID: 1 not found during lookup. Strange behaviour may occur
    Received state update for view id' AllocatedID: 1' but the NetworkView doesn't exist

    anyone got same issue ??
     
  2. nscyber

    nscyber

    Joined:
    Jul 14, 2014
    Posts:
    22
    1. create script >>networkLoadLevel.js<< the code on below.(copy all code )
    http://docs.unity3d.com/Manual/net-NetworkLevelLoad.html
    2. open 1st scene.
    2.1.create empty object use name NetworkLevelLoad(you can use other name).
    2.2.drop script file networkLoadLevel.js on Inspector of gameObject name "NetworkLevelLoad".



    3.you will see (Size,Element 0,Disconnected Level) on Inspector.
    3.1.Size is amount of Element ,you can use more number such as 2 ,you will have Element 0 and Element 1(new).
    3.2.Element 0 is 2nd scene,on you instantiate in 1st scene,you will see button name "First Person"("First Person" is name scene of 2nd scene) and when have client connect to network,when >>server<< click button name "First Person" all client in network will change to 2nd scene name "First Person".
    3.3.Disconnected Level is 1st scene("empty menu" is name of 1st scene),if you have disconnect(client or server disconnect) you will returned to 1st scene name "empty menu",not returned all client or server.
    ------------------------------
    - you can use spawn player script run in 2nd scene ,not run in 1st scene,1st scene it same wait room.

    ;)
     
    Last edited: Jul 18, 2014
  3. Rnd--

    Rnd--

    Joined:
    Sep 27, 2012
    Posts:
    30
    Still not working :(
    1st player wont appear in client
    when Im using networkloadlevel in sceneLobby it keep crashing my unity
    so now Im using 3 scene
    1. networkmanager scene-> contains networkloadlevel.js
    networkloadlevel.png
    2. sceneLobby scene -> contains networkmanagerscript
    do I need special function to load level ?? im using application load level like this
    Code (CSharp):
    1. void OnMasterServerEvent(MasterServerEvent mse)
    2.     {
    3.         if(mse == MasterServerEvent.RegistrationSucceeded)
    4.         {
    5.             print ("Registered Server");
    6.             Application.LoadLevel("scene1");
    7.         }
    8.     }
    9.  
    10.     void OnConnectedToServer()
    11.     {
    12.         print ("connected to server");
    13.         Application.LoadLevel("scene1");
    14.     }
    3. scene1 scene -> the game scene contains network.instantiate
    Code (CSharp):
    1.     void OnEnable()
    2.     {
    3.         spawnObj.x = Network.connections.Length * 5;
    4.         Network.Instantiate(playerPrefab, spawnObj, Quaternion.identity, 0);
    5.     }
     
    Last edited: Jul 19, 2014