Loading/Changing Scenes for all clients in a room.

I am seeking the best method for sending players in the same room to another scene.

Right now, if I send Player 1 to another scene, then Player 2 to another scene:
- Player 1's client wont show the second player
- Player 2's client will show the first player

But if Player 2 is send to another scene before player 1:
- Player 2 will be sent over in his/her client, but will still exist in the old scene where player 1 is
- Player 2 receives a stacking amount of "We have no such PhotonView" warnings
- When player 1 is finally sent over, Player 2 doesn't show in his client, but Player 1 shows up in player 2's client.

Also, I noticed that when either player is sen into another scene, the other player is still visible in the prior scene.

Lastly, is there a built in function/attribute for finding out what scene the master client is in? I want to make sure that new clients are send to the correct room in the case that they are late joining clients, or if I should reconsider allowing late joining clients

Comments

  • :)

    We just implemented a synced level loading for the new version of PUN.
    The latest preview package has this. Download link is here: viewtopic.php?f=17&t=2333

    You need to enable automaticallySyncScene (on all clients) and then make the call LoadLevel on master client. This will set a room property and and when that's updated, a client will change to the scene on all clients. Note: even if non-master clients load another scene, they re-load the same as the master has.
    Currently, we don't clean up instantiated game objects before we load. This has to be done by you (if you change scene more than once).
  • Awesome, I was in a bit of a crisis about this for a moment. Ill check this out promptly.
  • Once I've updated the package, I'm getting a problem with my enemy spawner. As soon as the player joins a room, the enemies aren't spawned, and I get this warning:
    OnDestroy manually allocated PhotonView View (0)1 on Enemy Spawner (scene). The viewID is local (isMine) but not in manuallyAllocatedViewIds list. Use UnAllocateViewID() after you destroyed the PV.

    [code2=csharp]void OnJoinedRoom()
    {
    if (PhotonNetwork.isMasterClient)
    {
    if (activeOnStart)
    SpawnEnemy();
    //photonView.RPC("SpawnEnemy", PhotonTargets.Others, null);
    }
    else
    {
    Destroy(this.gameObject);
    }
    }

    [RPC]
    void SpawnEnemy()
    {

    PhotonNetwork.Instantiate("Enemies/GrassHopper", transform.position, Quaternion.identity, 1);
    Destroy(this.gameObject);
    }[/code2]

    One other note, the room changing is working well. I noticed that trying to reload the same scene (which is not something I plan on doing anyway), it will not properly create/carry over the players.
  • The opposite of PhotonNetwork.Instantiate is PhotonNetwork.Destory.
    Your Destroy calls are breaking things.

    Re-loading the same scene is not supported by the LoadScene method. It won't load at all in this case.
    Also, it doesn't clean up GameObjects from the existing scene. You need to remove the existing GOs before you load as workaround until we implement this properly.
  • The destroy calls are meant to destroy the spawning object one they spawn the enemy, not the enemy itself, but I'm assuming that I will still need to use PhotonNetwork.Destory to destroy the spawner, despite being called after the enemy spawner?

    I will make to clean up the GO's as well, i just need to make sure to call it in the right place. Thanks for your help so far!
  • If the object you destroy has a PhotonView on it, we currently always "complain". Maybe just rearrange things to keep the GO with the scene's PV but destroy the pure script components that spawn. Or maybe even better: Don't destroy the scripts just cause they shouldn't run. What I see will only execute once (on joined room).
  • And now can we sync map change in lobby? or we can do it earlier?
    And with new version we can only change a map for all the players in the room(game scene) to another map?
  • Syncing the map even before joining a room is not yet possible "out of the box". You would set a property for that, make sure it's listed in the lobby, too and then the clients could use that value to load something before they join.
    But if loading delays joining the room, it might become filled until you loaded the scene. Then you can't join but loaded the scene for nothing.

    Acolit: I don't understand what the second question is about.
  • So, i ask if i can add sync map change only in new version of PUN?
    and can i change map inside the lobby, where player can choose maps, and then the players could just update and change map too, and after that start the game, download the map, etc?
  • Just use the new PUN version.
    When you create a room, you can define which properties are sent to the lobby:
    CreateRoom(string roomName, bool isVisible, bool isOpen, int maxPlayers, Hashtable customRoomProperties, string[] propsToListInLobby)

    The scene property used by our synchronized loading is: NetworkingPeer.CurrentSceneProperty. This must be in the string[] propsToListInLobby.
    Something like:
    [code2=csharp]string[] propsToListInLobby = new string[] {NetworkingPeer.CurrentSceneProperty};
    Hashtable roomProps = new Hashtable() {{NetworkingPeer.CurrentSceneProperty, initialScene}};
    CreateRoom(roomName, true, true, 4, roomProps, propsToListInLobby);[/code2]