Getting Disconnected from Server During Scene Loading

Aydin
Aydin
edited December 2020 in Photon Bolt
Hi,

I want to pass some data to a scene using IProtocolToken and BoltNetwork.LoadScene on the server side and get the token using SceneLoadLocalBegin on the client side; This data is critical for the next scene to work.

I am wondering though how edge cases are handled in Photon Bolt:

1. Does the client wait for receiving the token then initiate the scene change or it triggers the scene change and the token gets received after that?
2. Are there any scenarios in which the scene gets loaded on the client - in response to a call to BoltNetwork.LoadScene on the server - but the SceneLoadLocalBegin does not get called at all on the client?

Look forward to hearing from you.

Regards,
Aydin

P.S. I think if I don't use BoltGlobalBehaviour attribute and add the GlobalEventListener manually, I cannot use SceneLoadLocalBegin since it gets triggers very early. So my follow up question is:

3. How can I get the IProtocolToken which is passed to the BoltNetwork.LoadScene on the client side without using SceneLoadLocalBegin or SceneLoadLocalDone? Is it accessible through a method or a property?

Comments

  • Hello,
    1. Does the client wait for receiving the token then initiate the scene change or it triggers the scene change and the token gets received after that?

    The Scene information is received at once, there is no wait to receive the Token, but the sequence for change scenes is:

    1. Scene data is received by the client;
    2. The new Scene is enqueued for loading;
    3. Client start loading scene in the background using "SceneManager.LoadSceneAsync"
    4. Bolt loads all "GlobalBehaviours" that should be loaded on the new scene. This only applies to "GlobalBehaviours" that contains the "BoltGlobalBehaviour" attr with the Scene being loaded as a target.
    5. Bolt invokes the "SceneLoadLocalBegin" callback, this includes the Token.
    2. Are there any scenarios in which the scene gets loaded on the client - in response to a call to BoltNetwork.LoadScene on the server - but the SceneLoadLocalBegin does not get called at all on the client?

    The "SceneLoadLocalBegin" will only be invoked on currently loaded "GlobalBehaviour", and that always occurs. Keep in mind that in order to get a reference to the "GlobalBehaviour", it must be Enabled.
    So, if you are creating it manually, it may be possible that, as it's is not loaded yet on the new scene, its reference can`t be found by Bolt and for that reason, the callback will not be invoked on that particular "GlobalBehaviour".
    3. How can I get the IProtocolToken which is passed to the BoltNetwork.LoadScene on the client side without using SceneLoadLocalBegin or SceneLoadLocalDone? Is it accessible through a method or a property?

    Currently no, we store the scene information internally, but it's not exposed at the moment.
    We may expose this on a future version, but it's not on our plans, as the Callbacks are the best solution for this, and they are working fine for now.

    --
    Ramon Melo
    Photon Bolt Team
  • Aydin
    Aydin
    edited December 2020
    Does the SceneLoadLocalDone event always get called? I think based on your previous answer when the scene loading process started this event will get called eventually regardless of the state of the network at that moment; Is that right?
  • Hello,

    The "SceneLoadLocalDone" will be invoked on the already loaded "GlobalBehaviours" if you are starting Bolt, considering that you are using the latest version of the SDK. That is the default behavior.

    This is the only case where this callback will be invoked without "changing scenes".

    Take a look at the Release History for version 1.2.13c: https://doc.photonengine.com/en-us/bolt/current/getting-started/sdk-release-history

    --
    Ramon Melo
    Photon Bolt Team
  • Thanks a lot for the thorough response. However regarding exposing the token in ways other than the callbacks, I should say that to me they seem somehow required to make manually added GlobalEventListener more useful; For example I know a certain MonoBehaviour gets loaded when a specific scene is loaded, so it would be much more easier for me to simply get the scene token by reading a property like BoltNetwork.CurrentSceneToken for example, instead of making my code and design unnecessarily complex by creating a universal GlobalEventListener and try to get the token from it.
  • Hi,

    If you know that "a certain MonoBehaviour gets loaded when a specific scene is loaded", why don't just use the "BoltGlobalBehaviour" attr and let Bolt deal with it for you? And just subscribe to the necessary callbacks?

    "GlobalEventListener" are just MonoBehaviour in the end, you can use them just like you would use a normal MonoBehaviour.
    --
    Ramon Melo
    Photon Bolt Team
  • Hi,

    The problem here is that BoltGlobalBehaviour attribute enforces a certain architecture which is not necessary desirable for my project or as I mentioned would cause unnecessary complexity.

    For example suppose I have a canvas in the scene which is supposed to show the results of the game when the scene is loaded; It is more desirable for me to attach a MonoBehaviour as a component to the canvas's GameObject in order to get the scene's IProtocolToken, add the results to the canvas and control it. This way I can group the related components/objects in one GameObject and for example I can make a Prefab out of them to use somewhere else or remove them altogether without worrying about possible dependencies. This is not something I can do with BoltGlobalBehaviour attribute as it takes this flexibility from me by enforcing a certain architecture.

    BTW, I think exposing scene token in other ways makes "manually added GlobalEventListeners" complete and more useful.

    Regards,
    Aydin
  • Hello @Aydin ,

    We will be exposing this information on a future version, that is already agreed.

    But for now, your options are to follow how the Bolt is architectured to get the information you want, use events, or even a global entity with properties replicating the data you want to access.

    --
    Ramon Melo
    Photon Bolt Team