Migration Notes

PUN 2 aggregates a lot of breaking changes and updates in one package but the overall usage will be similar to PUN as you know it. It is a separate package from PUN 1.x so you can choose when to update. Also, you can go back anytime.

If you use PUN Plus (v1.x) and want to update to PUN 2, please use your existing AppId with the PUN 2 Free package! All benefits carry over.

To update, it's best to completely remove PUN and do a clean install of PUN 2 to make the necessary API and logic changes. Below, you will find the biggest changes but the list may be incomplete.

Overview

  • PUN 2 now includes and makes use of the Realtime API, which is less Unity specific.
  • There are two distinct namespaces for the two layers: Photon.Pun and Photon.Realtime.
  • Best Region selection and a system for callbacks are now done in the Realtime API. The regions enum is gone.
  • Only ConnectUsingSettings() is making use of the PhotonServerSettings.
  • Many callbacks, methods and fields were renamed for various reasons.
  • For callbacks a class has to implement an interface and register itself as interested.
  • MonoBehaviourPunCallbacks implements most callbacks so you can inherit and override them.

API Changes

  • Set the PhotonNetwork.GameVersion before you call PhotonNetwork.ConnectUsingSettings() or simply use the PhotonServerSettings.
  • PhotonNetwork.autoJoinLobby is gone. Unless you need a lobby, don't join them.
  • PhotonNetwork.GetRoomList() is gone. You get a rooms list from ILobbyCallbacks.OnRoomListUpdate(List<RoomInfo> roomList) callback and optionally cache it.
  • PhotonNetwork.FriendsList is gone. You can get friends list from IMatchmakingCallbacks.OnFriendListUpdate(List<FriendInfo> friendList) callback and optionally cache it.
  • PhotonNetwork.connecting is gone.
  • PhotonNetwork.connectionState is gone.
  • PhotonNetwork.isNonMasterClientInRoom is gone.
  • PhotonNetwork.autoCleanUpPlayerObjects is gone. The setting is per room, so it's now in the RoomOptions. Example: PhotonNetwork.CreateRoom(null, new RoomOptions() { CleanupCacheOnLeave = true });.
  • PhotonNetwork.networkingPeer is gone. The tasks it covered are either now handled directly in the PhotonNetwork class or in the PhotonNetwork.NetworkingClient.
  • Only ConnectUsingSettings() is making use of PhotonServerSettings. When using the other connect-methods, the app needs to set AppId and other values manually (and the settings won't override those values).

Namespace Changes

  • RoomOptions is now in the Photon.Realtime namespace
  • AuthenticationValues is now in Photon.Realtime namespace
  • IPunObservable is now Photon.Pun namespace

Renamed

camelCase to PascalCase

Public fields and properties:

  • photonView.isMine is now photonView.IsMine
  • photonView.owner is now photonView.Owner
  • PhotonNetwork.automaticallySyncScene is now PhotonNetwork.AutomaticallySyncScene
  • PhotonNetwork.masterClient is now PhotonNetwork.MasterClient
  • PhotonNetwork.isMasterClient is now PhotonNetwork.IsMasterClient
  • PhotonNetwork.inRoom is now PhotonNetwork.InRoom
  • PhotonNetwork.isMessageQueueRunning is now PhotonNetwork.IsMessageQueueRunning
  • PhotonNetwork.offlineMode is now PhotonNetwork.OfflineMode
  • PhotonNetwork.countOfPlayersOnMaster is now `PhotonNetwork.CountOfPlayersOnMaster
  • PhotonNetwork.countOfPlayersInRooms is now PhotonNetwork.CountOfPlayersInRooms
  • PhotonNetwork.countOfPlayers is now PhotonNetwork.CountOfPlayers
  • PhotonNetwork.countOfRooms is now PhotonNetwork.CountOfRooms
  • PhotonNetwork.sendRate is now PhotonNetwork.SendRate
  • PhotonNetwork.time is now PhotonNetwork.Time
  • PhotonNetwork.playerList is now PhotonNetwork.PlayerList
  • PhotonNetwork.precisionForVectorSynchronization is now PhotonNetwork.PrecisionForVectorSynchronization
  • PhotonNetwork.precisionForQuaternionSynchronization is now PhotonNetwork.PrecisionForQuaternionSynchronization
  • PhotonNetwork.precisionForFloatSynchronization is now PhotonNetwork.PrecisionForFloatSynchronization
  • PhotonStream.isWriting is now PhotonStream.IsWriting
  • PhotonStream.isReading is now PhotonStream.IsReading
  • RoomOptions.cleanUpCacheOnLeave is now RoomOptions.CleanupCacheOnLeave
  • RoomOptions.publishUserId is now RoomOptions.PublishUserId
  • RoomOptions.suppressRoomEvents is now RoomOptions.SuppressRoomEvents

Others

  • PhotonNetwork.connected is now PhotonNetwork.IsConnected
  • PhotonNetwork.connectedAndReady is now PhotonNetwork.IsConnectedAndReady
  • PhotonNetwork.networkingPeer is now PhotonNetwork.NetworkingClient
  • PhotonNetwork.connectionStateDetailed is now PhotonNetwork.NetworkClientState
  • PhotonNetwork.playerName is now PhotonNetwork.NickName
  • PhotonNetwork.room is now PhotonNetwork.CurrentRoom
  • PhotonNetwork.lobby is now PhotonNetwork.CurrentLobby
  • PhotonNetwork.player is now PhotonNetwork.LocalPlayer
  • PhotonNetwork.insideLobby is now PhotonNetwork.InLobby
  • PhotonNetwork.otherPlayers is now PhotonNetwork.PlayerListOthers
  • PhotonNetwork.sendRateOnSerialize is now PhotonNetwork.SerializationRate
  • PhotonTargets enum is now RpcTarget
  • PhotonPlayer class is now Photon.Realtime.Player
  • PhotonPlayer.ID is now Photon.Realtime.Player.ActorNumber

Callbacks Changes

You can read more about new callabcks on this page.

  • All callback interfaces except IPunInstantiateMagicCallback must be registered and unregistered. Call PhotonNetwork.AddCallbackTarget(this) and PhotonNetwork.RemoveCallbackTarget(this) (likely within OnEnable() and OnDisable() respectivly)

  • Replace Photon.PunBehaviour with MonoBehaviourPunCallbacks Always call the base class methods if you override OnEnabled() and OnDisable() for MonoBehaviourPunCallbacks

PUN 1 (Callback) PUN 2 (Interface.Callback)
OnConnectedToPhoton() IConnectionCallbacks.OnConnected()
OnFailedToConnectToPhoton() IConnectionCallbacks.OnDisconnected(DisconnectCause)
OnConnectionFail(DisconnectCause) IConnectionCallbacks.OnDisconnected(DisconnectCause)
OnDisconnectedFromPhoton() IConnectionCallbacks.OnDisconnected(DisconnectCause)
OnConnectedToMaster() IConnectionCallbacks.OnConnectedToMaster()
OnPhotonMaxCccuReached() IConnectionCallbacks.OnDisconnected(DisconnectCause)
OnCustomAuthenticationFailed(string debugMessage) IConnectionCallbacks.OnCustomAuthenticationFailed(string debugMessage)
OnCustomAuthenticationResponse(Dictionary<string, object> data) IConnectionCallbacks.OnCustomAuthenticationResponse(Dictionary<string, object> data)
OnMasterClientSwitched(PhotonPlayer newMasterClient) IInRoomCallbacks.OnMasterClientSwitched(Player newMasterClient)
OnPhotonPlayerConnected(PhotonPlayer newPlayer) IInRoomCallbacks.OnPlayerEnteredRoom(Player otherPlayer)
OnPhotonPlayerDisconnected(PhotonPlayer otherPlayer) IInRoomCallbacks.OnPlayerLeftRoom(Player otherPlayer)
OnPhotonPlayerActivityChanged(PhotonPlayer otherPlayer) IInRoomCallbacks.OnPlayerEnteredRoom(Player otherPlayer)
IInRoomCallbacks.OnPlayerLeftRoom(Player otherPlayer)
OnPhotonCustomRoomPropertiesChanged(Hashtable propertiesThatChanged) IInRoomCallbacks.OnRoomPropertiesUpdate(Hashtable propertiesThatChanged)
OnPhotonPlayerPropertiesChanged(object[] playerAndUpdatedProps) IInRoomCallbacks.OnPlayerPropertiesUpdate(Player targetPlayer, Hashtable changedProps)
OnJoinedLobby() ILobbyCallbacks.OnJoinedLobby()
OnLeftLobby() ILobbyCallbacks.OnLeftLobby()
OnReceivedRoomListUpdate() ILobbyCallbacks.OnRoomListUpdate(List<RoomInfo> roomList)
OnLobbyStatisticsUpdate() ILobbyCallbacks.OnLobbyStatisticsUpdate(List<TypedLobbyInfo> lobbyStatistics)
OnLeftRoom() IMatchmakingCallbacks.OnLeftRoom()
OnPhotonCreateRoomFailed(object[] codeAndMsg) IMatchmakingCallbacks.OnCreateRoomFailed(short returnCode, string message)
OnPhotonJoinRoomFailed(object[] codeAndMsg) IMatchmakingCallbacks.OnJoinRoomFailed(short returnCode, string message)
OnCreatedRoom() IMatchmakingCallbacks.OnCreatedRoom()
OnJoinedRoom() IMatchmakingCallbacks.OnJoinedRoom()
OnPhotonRandomJoinFailed(object[] codeAndMsg) IMatchmakingCallbacks.OnJoinRandomFailed(short returnCode, string message)
OnUpdatedFriendList() IMatchmakingCallbacks.OnFriendListUpdate(List<FriendInfo> friendList)
- IOnEventCallback.OnEvent(EventData)
OnPhotonInstantiate(PhotonMessageInfo info) IPunInstantiateMagicCallback.OnPhotonInstantiate(PhotonMessageInfo info)
OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) IPunObservable.OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
OnOwnershipRequest(object[] viewAndPlayer) IPunOwnershipCallbacks.OnOwnershipRequest(PhotonView targetView, Player requestingPlayer)
OnOwnershipTransfered(object[] viewAndPlayers) IPunOwnershipCallbacks.OnOwnershipTransfered(PhotonView targetView, Player previousOwner)
OnWebRpcResponse(OperationResponse response) IWebRpcCallback.OnWebRpcResponse(OperationResponse response)

 To Document Top