Keep Connection in the Scenes Change

Hi everybody,

I have a project with litelobby at server side, and i get a connection when the UnityClient starts, but i want to keep the connection when the UnityClient change the scene, anyone have one idea of how can i do that?

I tried using a static instance of photonpeer but he disconnects since there's no object to handling the connection while the scene is changing.

In my project i handle the connection of my photonpeer class with the method "Update" like below:

void Update()
{
PhotonPeerInstance.Update();
}

How can i work with a static class and keep it through the scenes?

Comments

  • To prevent confusion for other PUN users:
    I beleive you are implementing Photon yourself, right? This doesn't look like you are using PUN.

    In PUN I used a background thread to keep the connection alive while scenes are loading. You could take a look at my implementation there.
  • The problem is most likely not that your static variable doesn't "work" but Update is not called while you load.
    You could try FixedUpdate (but make sure it IS called while you load) or best: Start a Thread and let it call SendOutgoingCommands(). Make sure this Thread ends when you finished loading and make sure you never use a peer instance from 2 concurrent Threads.

    If you would call Service(), this would call DispatchIncomingCommands(), too. Most likely, you don't want to dispatch stuff you got, before you loaded. So only call SendOutgoingCommands() while loading.
Sign In or Register to comment.