Search Unity

Button OnClick not working anymore after loading level: Missing Object

Discussion in 'Multiplayer' started by HadesHaido, Jun 30, 2015.

  1. HadesHaido

    HadesHaido

    Joined:
    Dec 8, 2014
    Posts:
    2
    Hi all,

    I have a problem with the UI buttons after loading a new scene and
    There are two scenes in my project: MainMenu and MainScene.

    In MainMenu I am doing networking stuff and preloading data from disc.
    When I click on the Host button the host is started and the MainScene is loaded via Application.LoadLevel("MainScene").
    I am not using the Network Manage HUD button, instead I am starting the host like this:

    Code (CSharp):
    1. public void StartHost() {
    2.             CustomNetworkManagerScript.instance.networkPort = int.Parse(serverPortInput.text);
    3.             CustomNetworkManagerScript.instance.StartHost();
    4.             Application.LoadLevel("Main");
    5.     }
    In the MainScene I have a GameManager singleton and a canvas with lots of UI buttons. The buttons are calling methods in GameManager, which are set up in the Unity Editor and not at runtime.

    When I start MainScene directly from Unity or use the "Host" button from the Network Manager HUD, everything works fine. But when MainScene is loaded from MainMenu, all buttons are not working anymore. In the inspector it says "Missing Object" in the OnClick section, even if there is the GameManager object !

    I've got the feeling I am missing something.
    Any tips are welcome !
    Thanks
     
  2. seanr

    seanr

    Unity Technologies

    Joined:
    Sep 22, 2014
    Posts:
    669
    You should use NetworkManager.ServerChangeScene() to switch scenes in a network friendly way.
     
  3. HadesHaido

    HadesHaido

    Joined:
    Dec 8, 2014
    Posts:
    2
    Thanks, that solved it !