The Photon Forum
is Closed Permanently.

After many dedicated years of service, we have made the decision to retire our Forum and switch to read-only: we´ve saved the best to last! Your search result can be found below. Plus, we offer support via these channels:

Try Our

Please check if you can find an answer in our extensive documentation on PUN.

Join Us
on Discord

Meet and talk to our staff and the entire Photon-Community via Discord.

Stack Overflow

Find more information on Stack Overflow (for Circle members only).

Write Us
an E-Mail

Feel free to send your question directly to our developers.

How to Switch Master Client?

2016-12-28 21:17:23

Good day,

My biggest issue before putting out my android game is now related to the master client putting the app into the background, or disconnecting.

The game looks "paused" or the other players get disconnected automatically.

I don't really understand how to switch the masterclient, along with the objects that it instantiated.

How would I tackle this problem?


2016-12-28 21:37:36

@Pav If a client leaves a room all his instantiated objects will get destroyed.
The MasterClient switches automatically when he leaves.
Use photon network instantiate scene object instead of the normal PhotonNetwork.Instantiate.

Notice that only the masterclient can change the transform of those scene objects but they will not get destroyed when the mc leaves or a another player becomes the mc.


2016-12-28 22:10:26

Ah, I see.
I did a lot of searching before I put up this question, wasn't aware that the master client switches automatically if that player leaves.

What about cases regarding having the app in the background?
Or it'll be fine as long as I use networkinstantiate scenebject

2016-12-28 22:13:28

@Pav Check out if the player stills sends data when the app is backgrounded. If the player stays connected and sends data you will not have a problem. Btw unity got a allow background settings but i don't know if it works with mobile too.

2016-12-28 22:36:41

I tried "PhotonNetwork Instantiate Scene Object" but because it has a photonview for transform, it's frozen when the masterclient is running the app in background.

2016-12-28 22:55:44

@Pav there you go:

2016-12-29 02:54:23

I see. That doesn't work with android unfortunately, but I figured out how to determine if the masterclient is paused.

However, I haven't played around with getting photonPlayer ID's and I'm stuck at..

2016-12-29 04:11:26

Alright. I got it to switch masterclients, but it doesn't work properly.

When current masterclient puts the app into background, it doesn't transfer. Only transfers when the app comes back into focus.

2016-12-29 21:01:45

@JannickL Ok, it works properly now, How could I choose the the next playerID to be the master client? so far I just do..


2016-12-29 22:29:18

@Pav @JannickL

ICYMI: there is a documentation page about "Master Client and Host Migration".

2016-12-30 03:22:03

@JohnTube I've seen that, and it makes sense. I've made a script that switches the masterclient, however, it's based on OnPhotonSerializeView.

Would you suggest doing PunRPC instead?

2016-12-30 10:45:02

I'm not a PUN expert. I'm used to plain Photon events (RaiseEvent).
My other colleagues are on vacation so I can't ask them now.
But IMO, PunRPC is better than OnPhotonSerializeView.

In any case I think you should switch the MasterClient from another client that detects the MasterClient disconnection and use this:


2016-12-30 17:14:45

@JohnTube That works even better than what I had. Appreciate it :)

2018-02-05 11:56:23

*******Best Working way to change Master Client in photon network.******
void OnApplicationPause(bool pauseStatus)  

        if (pauseStatus)  
            if (PhotonNetwork.connectionState == ConnectionState.Connected && PhotonNetwork.inRoom && PhotonNetwork.isMasterClient)  
                // Game is in Background | pause | quit  
                //PhotonNetwork.BackgroundTimeout = 2f;                                                  
            if (PhotonNetwork.connectionState == ConnectionState.Connected && PhotonNetwork.inRoom && PhotonNetwork.isMasterClient)  
               // do whatever you want . if you not reach time to live player then you are connected and inroom already.  

            //check if game end ||room destroyed ||timeout  
    } // End OnApplication Pause.

   /// Changes the master client if availble.  
    public void ChangeMasterClientifAvailble()  
        if (!PhotonNetwork.isMasterClient)  
        if ( <= 1)  

 public virtual void OnMasterClientSwitched(PhotonPlayer newMasterClient)  
 //event will fired to all connected players in same room.  
//if master client goes in background then new master client info hear.   

2020-01-12 11:38:03

Hi, i am using this method. could it be any better? or am i doing it wrong?

2020-01-12 12:21:23

As I understand the masterclient is automatically switched by photon on current mc got disconnected. You just have to setup plugin properly.
And the problem was with an app going to background, and in that case you should use OnApplicationPause/Focus to check if you are mc and tell others you are about to go to background via rpc.
I'm not an expert, so its just things to think about )

2020-01-12 12:49:37

Hi @Djebedia thanks for your response. However the OP is 4 years old. I am sorry i had to resurrect it.

what do you think of my code above? is it good idea to check latency using RPC? I am following the idea of "heartbeat" in this photon documentation here

I dont think of any other method but correct me if im wrong

2020-01-13 10:42:12

I have answered here.

2021-08-19 16:46:12

I'm looking if there's a way to set another player to Master Client during game.

Back to top