Search Unity

  1. Unity 2019.1 beta is now available.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We're looking for insight from anyone who has experience with game testing to help us better Unity. Take our survey here. If chosen to participate you'll be entered into a sweepstake to win an Amazon gift card.
    Dismiss Notice
  4. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  5. Unity 2018.3 is now released.
    Dismiss Notice
  6. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

finishing a multiplayer game, restarting scene, not working

Discussion in 'Connected Games' started by mudibushnaq, Jul 9, 2018.

  1. mudibushnaq


    Dec 16, 2012
    so i have a 1 v 1 multiplayer match .
    here is how the logic is built :
    MainMenu scene is a fully offline scene , no match making , no multiplayer u just type or name , name and score saved , u press PLAY button then you choose ur champion and saves it localy in Playerprefab.
    and then loads Multiplayer scene
    the multiplayer scene has the network manager script (turned on) but nothing starts yet .
    player presses Find Match > it starts the Matchmaking then searches for a match > it tries 4 times if there is no room then it will create a new room and then it will spawn the player prefab and enable / spawn everything on the gameplay scene and waits for client to join (other player) (but the match making UI is ON and counting as its still searching for a match) .
    then client presses find match and happens the same , then client joins the match and the UI coz i check when 2 players are in the room and i turn all UI off and count to 10 then start the game.

    everything until now is ok.
    when one of players lose and another win , it shows the victory or the lose UI.
    and then i press the Go To Main Menu button
    and this button brings the players back to MainMenu scene (the offline scene).
    then i press PLAY again on host > it will tell me DropConnectionRequest when the multiplayer scene loads.
    and then it shows :
    networkmanager detected a script reload in the editor. this has caused the network to be shut down.

    then the scene restarts and gets back to MainMenu

    for client it will load normal so no errors .

    then i try to find a new match for host joins good and waits for the client to join .

    but then when the client joins it will load MainMenu scene for client
    and register on host that the client is in the game but he is NOT.

    when i spawn an object in the scene (from host) it will spawn on the client too but in the wrong scene.
    so things gets messed up , the host has multiplayer scene on but client has MainMenu (the offline scene with no NetworkManager)
    so only the multiplayer scene got the networkmanager.

    on my networkmanager script i have this code on Awake()

    Code (CSharp):
    1. void Awake(){
    2.             singleton = this;
    3.             Application.targetFrameRate = 60;
    4.         }
    5.     }
    so it will create a singelton on Awake function when the scene is loaded .

    when i restart the game and start from the beginning everything works great.

    Things i tried :
    * send an RPC that the game is done with this code :
    Code (CSharp):
    1. NetworkManager.singleton.ServerChangeScene(level);
    both client and server load the scene but still not working (it will give other errors).

    *StopClient/StopHost will give Errors and DropConnectionRequest then the MainMenu Scene loaded .
    but still not working and brings different errors .

    *Changing the Awake() function coz i read that it makes some errors in NetworkManager and i replace it with OnEnable() function.
    but didnt change anything or fix the problem.
    i changed it to Initilize() function too , but didnt help .

    so how do i end the game and get back to MainMenu to start a new match ?
    and what is the logic behind restarting the whole game so i can join a match without errors ?
    and i just load the MainMenu scene back so that means everything will start refreshed and new when i press PLAY again and load Multiplayer scene .
    Last edited: Jul 9, 2018
  2. Vegoo89


    May 11, 2018
    Do you destroy Network Manager while loading Main Menu again? It may be an issue.
  3. mudibushnaq


    Dec 16, 2012
    no i dont destroy it , i just send a command to load for both scenes or stop client / host
  4. mudibushnaq


    Dec 16, 2012
    so i tried to destroy it then after loading a new scene this will popup :

    NetworkManager detected a script reload in the editor. This has caused the network to be shut down.

    and then it will call this function :

    Code (CSharp):
    1. public void cancelServer(){
    2.         Debug.Log("cancelServer Function");
    3.     }

    and so this function gets called on two other functions and they are :

    Code (CSharp):
    1. public override void OnStopClient(){
    2.         cancelServer();
    3.     }
    4.     public override void OnServerDisconnect(NetworkConnection conn){
    5.         cancelServer();
    6.     }

    and the third error is :

    NullReferenceException: Before using the library you should call Init() and do not forget to call Shutdown() afterwards
    UnityEditor.NetworkDetailStats+NetworkOperationDetails.NewProfilerTick (Int32 tickId)