SceneLoadLocalDone not being called, but SceneLoadLocalBegin is being called

Hey there ya'll,

So as the title suggests SceneLoadLocalDone isn't being called but SceneLoadLocalBegin is. Here is my script with the [BoltGlobalBehavior] tag.

[BoltGlobalBehaviour]
public class NetworkCallback_List : GlobalEventListener
{

public override void SceneLoadLocalBegin(string scene)
{
Debug.Log("Begin " + scene);
}

public override void SceneLoadLocalDone(string scene)
{
Debug.Log("Done" + scene);
}
}

and here is the line in a scene called "StartMenu" that loads this scene.

BoltMatchmaking.CreateSession(
sessionID: matchName,
sceneToLoad: "Character_Select_Screen"
);

Not sure what I am missing here any help is much appreciated. Thanks!

Comments

  • ShuntBalushian
    edited May 2020
    So weirdly enough it seems to be something else I am doing that is causing this issue. I have thins block of code in my StartMenu to handle users.

    void OnGUI()
    {
    if (GUILayout.Button("Play_Online", GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true)))
    {
    SpriteRenderer[] connects = connection.GetComponentsInChildren<SpriteRenderer>();
    foreach (SpriteRenderer s in connects)
    {
    s.enabled = true;
    }
    BoltLauncher.StartClient();
    }
    }

    public override void BoltStartDone()
    {
    if (BoltNetwork.IsClient)
    {
    BoltMatchmaking.JoinRandomSession();
    }
    else if (BoltNetwork.IsServer)
    {
    //Debug.Log("Started as Server");
    string matchName = Guid.NewGuid().ToString();

    BoltMatchmaking.CreateSession(
    sessionID: matchName,
    sceneToLoad: "Character_Select_Screen"
    );
    }
    }

    public override void SessionConnectFailed(UdpSession session, IProtocolToken token)
    {
    BoltLauncher.Shutdown();
    BoltLauncher.StartServer();
    //BoltLog.Error("Failed to connect to session {0} with token {1}", session, token);
    }


    As is the error as described above occurs. However, if I remove the BoltLauncher.StartClient in OnGUI and replace it with BoltLauncher.StartServer everything works as intended. Not sure why this would be happening. Do I have to clear something else, or should I have the StartSever in a callback from the Shutdown?
  • Hello @ShuntBalushian ,

    Photon Bolt does not shutdown instantaneously, it needs some time to reset it's internal data and communicate with any other clients that may be connected to it, that is why we have the BoltShutdownBegin callback. If you want to shutdown Bolt and then start it as a Server, you need to register a callback for it.

    Here is an example:
    public override void SessionConnectFailed(UdpSession session, IProtocolToken token, UdpSessionError errorReason)
    {
        BoltLog.Error("Failed to connect to session {0} with token {1}", session, token);
        BoltLauncher.Shutdown();
    }
    
    public override void BoltShutdownBegin(AddCallback registerDoneCallback,
        UdpConnectionDisconnectReason disconnectReason)
    {
        BoltLog.Info("Bolt is shutting down...");
    
        registerDoneCallback(() =>
        {
            BoltLog.Info("Bolt is shutdown done. Starting as Server...");
            BoltLauncher.StartServer();
        });
    }
    

    About the Scene callbacks not being invoked, we just executed a test with Bolt 1.2.12 (the latest version), and all callbacks are invoked as expected, even the obsolete ones. You should always use the latest version.
  • ShuntBalushian
    edited May 2020
    Hey @ramonmelo thanks for the response. The past couple days I figured out the callback section and my code is identical to what you posted. My issue now I run into is actually the same one as @pan1cmode post a couple days ago. My Bolt stays in Disconnecting... and logs a warning that says "Behavior not available in this dispatcher, ignoring call to Remove"

    Following your message on the other post here are my answers:
    Unity Version: 2019.3.11f1
    Bolt Version: 1.2.12

    So my issue happens when I start my game as a Client or as a Server then proceed to call Bolt.Shutdown() with a callback function on the shutdown. I tried multiple variations and no matter when I called Bolt.Shutdown it stopped the same way. My code is currently posted below.

    This is my script that handles starting Bolt and creating the sessions.
    public class Play_Online : GlobalEventListener
    {
        public GameObject connection;
        
        void OnGUI()
        {
            if (GUILayout.Button("Play_Online", GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true)))
            {
                SpriteRenderer[] connects = connection.GetComponentsInChildren<SpriteRenderer>();
                foreach (SpriteRenderer s in connects)
                {
                    s.enabled = true;
                }
                BoltLauncher.StartClient();
            }
        }
    
        public override void BoltStartDone()
        {
            if (BoltNetwork.IsClient)
            {
                BoltMatchmaking.JoinRandomSession();
            }
            else if (BoltNetwork.IsServer)
            {
                //Debug.Log("Started as Server");
                string matchName = Guid.NewGuid().ToString();
    
                BoltMatchmaking.CreateSession(
                    sessionID: matchName,
                    sceneToLoad: "Character_Select_Screen"
                );
                
            }
        }
    
        public override void SessionListUpdated(Map<Guid, UdpSession> sessionList)
        {
            Debug.LogFormat("Session list updated: {0} total sessions", sessionList.Count);
    
            foreach (var session in sessionList)
            {
                UdpSession photonSession = session.Value as UdpSession;
    
                BoltMatchmaking.JoinSession(photonSession);
            }
        }
    
        public override void SessionConnectFailed(UdpSession session, IProtocolToken token)
        {
            BoltLauncher.Shutdown();
            //BoltLog.Error("Failed to connect to session {0} with token {1}", session, token);
        }
    
    }
    

    This is my Network Callbacks script
    [BoltGlobalBehaviour]
    public class NetworkCallback_List : GlobalEventListener
    {
    
        public override void BoltShutdownBegin(Bolt.AddCallback registerDoneCallback)
        {
            BoltLog.Warn("Bolt is shutting down");
            
    
            registerDoneCallback(() =>
            {
                BoltLog.Warn("Bolt is down");
                BoltLauncher.StartServer();
            });
        }
    
        public override void SceneLoadLocalBegin(string scene)
        {
            Debug.Log("Begin " + scene);
        }
    
        public override void SceneLoadLocalDone(string scene)
        {
            Debug.Log("Done " + scene);        
        }
    }
    

    And here's a screenshot of my Unity Console, I can follow the trace but as you can see it just hangs on Disconnecting
    https://imgur.com/pcRu61x
  • @ShuntBalushian, I've been trying to do exactly the same than you for the last couple of days. And I'm getting exactly the same error. Could you solve it? It would be very useful to know how.

    In summary, to try to help in your description, shutdown presents the following error (and presumably, it never finishes running):

    Behaviour not available in this dispatcher, ignoring call to Remove.
    UnityEngine.Debug:LogWarning(Object)
    UnityWriter:BoltLog.IWriter.Warn(String)
    BoltLog:Warn(String)
    Bolt.EventDispatcher:Remove(MonoBehaviour)
    BoltInternal.GlobalEventListenerBase:OnDisable()
    UnityEngine.Object:Destroy(Object)
    BoltInternal.BoltCore:ShutdownProcedure(BoltNetworkModes, UdpConnectionDisconnectReason, AddCallback, ManualResetEvent, Boolean)
    BoltInternal.BoltCore:BeginShutdown(ControlCommandShutdown)
    Bolt.ControlCommandShutdown:Run()
    Bolt.ControlBehaviour:Update()

    And it seems that for this reason, registerDoneCallback never gets to run.

    I've also tried to launch a Coroutine after BoltLauncher.Shutdown(), wait for BoltNetwork.IsRunning to become false, and then try to start the server again. But StartServer seems to do nothing in this circumstance.

    @ramonmelo I'm also using 1.2.12 version.

    Thanks in advance for your help and suggestions, it's being challenging to get started with Bolt for me.

    Gloria
  • So I actually realized PUN2 is the sdk I should have been using. It definitely has a lot of the features I was looking for. It gives you a little more control so there's a bit more stuff you have to figure out, but overall I think it works better for my situation as a 1v1 game.