Lag on masterclient switch

Options
I am developing an open world game and am using PUN during the alpha stage because it really makes my life a lot easier.

My players only experience one problem; when the player that was the masterclient leaves, and a new masterclient is appointed randomly, that new masterclient gets a lot of lag. Usually so much it makes the game unplayable for them.

The game has between 100 and 200 items with a photonview (loot and AI), which I guess have to have their ownership transferred to the new masterclient?

Is there any way, any technique I can use to smooth out the switching of the masterclient?

Comments

  • chaozz
    Options
    Nobody?
  • Carme
    Carme
    edited April 2017
    Options
    Are you using PhotonNetwork.InstantiateSceneObject to create the objects - not 100% sure what happens if the master leaves, testing in my own scenes on npcs for instance, they are are not affected by a master leaving.

    The master still owns them of course, but would it reduce your lag?..dunno.
  • chaozz
    chaozz
    edited April 2017
    Options
    I'll try using InstantiateSceneObjects for spawning of loot. I'm not even sure if the transfer of ownership is causing the lag, but that is the only thing I can imagine.

    I know InstantiateSceneObjects can only be used by the MasterClient, but can someone who isn't the masterclient do this:
    GameObject GO = PhotonNetwork.Instantiate("someprefab", Transform.position, Transform.rotation, 0, null); GO.GetComponent<PhotonView>().TransferOwnership(0);
    
    Would this work? As in, would this make them spawn an item an make it owned by the scene?
  • chaozz
    Options
    I'll try that for the spawning of the loot and zombies. But I also let non-masterclients spawn things and for example handle their own AI chases. They take ownership of AI when they get detected and then handle the movement.

    I know only the masterclient can instantiate scene objects, but would this work for a normal client:
    GameObject GO = PhotonNetwork.Instantiate("trap_closed", TrapTransform.position, TrapTransform.rotation, 0, null); // spawn closed trap (loot)
    GO.GetComponent().TransferOwnership(0); // transfer ownership to the scene
  • chaozz
    chaozz
    edited April 2017
    Options
    ** removed **
  • Carme
    Carme
    edited April 2017
    Options
    chaozz said:

    I know only the masterclient can instantiate scene objects, but would this work for a normal client:
    GameObject GO = PhotonNetwork.Instantiate("trap_closed", TrapTransform.position, TrapTransform.rotation, 0, null); // spawn closed trap (loot)
    GO.GetComponent().TransferOwnership(0); // transfer ownership to the scene



    Not sure if that would work, try it, change the trap_closed photonview owner to take over.

    I'd just get the non master to send an rpc to the master, and when the master gets the rpc, it then creates the PhotonNetwork.InstantiateSceneObject. so:

    [PunRPC]
    public void trapDoorControl(vector 3 pos, Quaternion rot )
    {
    GameObject GO = PhotonNetwork.InstantiateSceneObject ("trap_closed", pos, rot, 0, null); // spawn closed trap (loot)
    }

    photonView.RPC("trapDoorControl", PhotonTargets.MasterClient, pos, rot);

    That should work, same amount of messages, as you had to transfer anyway..
  • chaozz
    Options
    That's true. Sadly, changing all loot spawning to InstatiateSceneObject didn't change anything to the lag the new masterclient experiences when they receive that role.

    I have no idea what is causing it.
  • Carme
    Options
    I think you need a pun admin to help diagnose further (@Tobias), but one last thing; from reading here: https://doc.photonengine.com/en-us/pun/current/reference/hostmigration

    Two things are interesting in that doc:

    1) You should avoid sending events to Master Client only. Replicating data is better than losing it. When you send to all actors you make any eventual Master Client switch easier. Since all actors will keep track of the room's state, the newly assigned Master Client will have the full room state already.

    2) Custom room properties are the best reliable option if you want to persist game data in case a Master Client switch happens.

    Do you have a lot of rpc's direct to the master? perhaps if so, try sending to all or all buffered - ..\messages per second might be an impact here though.

    Kind Regards and when you fix, please let me know :)

    Carme



  • chaozz
    Options
    Thanks Carme. I almost send no bufferend RPC calls, because these stack up and make joining a running game (which might run for hours on end) a nightmare.

    All my persistent objects are locally instantiated and don't use PUN.

    It's only AI, animals and loot. I use a pooling system to spawn them, and that seems to work fine without lag. It really is just when the master client leaves, the lag starts for the new master client. Any advice from @Tobias or any other admin would be MUCH appreciated.