Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Resolved Loading scene issue in editor playmode

Discussion in 'Editor & General Support' started by Leiunn, Apr 7, 2020.

  1. Leiunn

    Leiunn

    Joined:
    Apr 7, 2020
    Posts:
    2
    Hello everyone,

    as the title says I have an issue loading a scene when in playmode in the editor.

    The workflow of my game is as follows:
    1. Initializing (works fine)
      There is an empty scene that creates some global game objects that will exist during the entire runtime.
    2. MainMenu (works fine)
      After the Initializing is done it loads the MainMenu scene. I can interact with the scene and everything is nice.
    3. Connect to game server (works fine)
      In the main menu I have an option to connect to a game server (a dedicated server application I created on my own)
      Establishing the connection and sending the login works well.
    4. Character selection (not working)
      After the login on the server I get the resonse to select a character. (This works as expected.)
      Then I'm going to handle this response by opening the character selection scene.
    And here I have the issue. In Playmode inside the editor the handler method is executed (verifyed by debug logs) but the scene is not loaded actualy.
    When I build the game and run the created .exe and follow the exact same steps the character selection scene is loaded and shown as expected.

    I searched the documentation and also the web but did not find any similar issues (maybe I still missed something)

    So my question is as follows:
    How do I get the scene to also load in the editor playmode? My approach seems not to be totaly wrong as it works after build.

    Here is the code snippet that should load the scene:

    Code (CSharp):
    1. private void MessageRecived(object sender, GNL.ResponseMessageEventArgs e)
    2.     {
    3.         GameEventMessage message = this.eventManager.MessageHandler.ParseMessage(e.Message);
    4.  
    5.         Debug.Log($"Recived message with type {message.Type}");
    6.  
    7.         switch (message.Type)
    8.         {
    9.             case GameEvent.CharacterSelectionRequired:
    10.                 Debug.Log($"Handle character creation 01");
    11.                 this.HandleCharacterSelectionRequried(message);
    12.                 break;
    13.             default:
    14.                 break;
    15.         }
    16.     }
    17.  
    18.     private void HandleCharacterSelectionRequried(GameEventMessage eventMessage)
    19.     {
    20.         Debug.Log($"Handle character creation 02");
    21.         SceneManager.LoadScene("CharacterCreation");
    22.     }
    All three Debug.Log statements are executed. Only the LoadScene isn't working in the editor playmode.

    IMPORTANT ADDITION
    After further testing I have to mention that the network communication is done in a seperate thread. From this thread when a new message arrives an eventHandler is called.

    This is where the Method is added to the Event handler:
    Code (CSharp):
    1. this.client = new GNL.GameClient(System.Net.IPAddress.Parse(host), port);
    2. this.client.AnnounceRecivedMessage += this.MessageRecived;
    3. this.clientNetwork = new Thread(this.client.Start);
    4. clientNetwork.Start();
    5.  
    And this is the definition of the eventHandler:
    Code (CSharp):
    1. public event EventHandler<ResponseMessageEventArgs> AnnounceRecivedMessage;
    IMPORTANT ADDITION - Part 2
    I just discovered that it works after a normal build but does not work when selecting "development build" in the build settings.
    I'm thankful for any help and suggestions.
     
    Last edited: Apr 8, 2020
  2. Leiunn

    Leiunn

    Joined:
    Apr 7, 2020
    Posts:
    2
    After much more debugging and testing I figured out that this issue indeed is a threading issue. Deep in the debugger I found the exception I would have expected for a threading issue. So I will have to change my implementation here.

    But still there is an inconsistence in how threads are handled in Unity when running the game with debugging tools enabled (playmode in editor and development build) and with them disabled (normal build).