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
andPhoton.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. Read more here.
- For callbacks a class has to implement an interface and register itself as interested. Read more here.
MonoBehaviourPunCallbacks
implements most callbacks so you can inherit and override them. Read more here.
API Changes
PhotonNetwork.autoJoinLobby
andServerSettings.JoinLobby
are gone. Unless you need a lobby, don't join them.PhotonNetwork.GetRoomList()
is gone. You get rooms list and updates fromILobbyCallbacks.OnRoomListUpdate(List<RoomInfo> roomList)
callback. You can optionally cache it, update it and clear it when needed.PhotonNetwork.Friends
is gone. You get friends list fromIMatchmakingCallbacks.OnFriendListUpdate(List<FriendInfo> friendList)
callback. You can optionally cache it, update it and clear it when needed.PhotonNetwork.LobbyStatistics
is gone. When enabled, you can get lobby statistics list fromILobbyCallbacks.OnLobbyStatisticsUpdate(List<TypedLobbyInfo> lobbyStatistics)
callback. You can optionally cache it, update it and clear it when needed.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 thePhotonNetwork.NetworkingClient
.PhotonNetwork.ConnectUsingSettings()
no longer takesgameVersion
parameter. Instead the AppVersion parameter set from the Unity Editor in the PhotonServerSettings, AppSettings section is used asPhotonNetwork.GameVersion
. If you want to set thePhotonNetwork.GameVersion
from code you could either- set
PhotonNetwork.GameVersion
just after callingPhotonNetwork.ConnectUsingSettings()
- set
PhotonNetwork.PhotonServerSettings.AppSettings.AppVersion
before callingPhotonNetwork.ConnectUsingSettings()
- set
- 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). ServerSettings.EnableLobbyStatistics
is moved toServerSettings.AppSettings.EnableLobbyStatistics
.ServerSettings.AppID
is moved toServerSettings.AppSettings.AppIdRealtime
.ServerSettings.VoiceAppID
is moved toServerSettings.AppSettings.AppIdVoice
.ServerSettings.ChatAppID
is moved toServerSettings.AppSettings.AppIdChat
.ServerSettings.NetworkLogging
is moved toServerSettings.AppSettings.NetworkLogging
.ServerSettings.ServerAddress
is moved toServerSettings.AppSettings.Server
.ServerSettings.ServerPort
is moved toServerSettings.AppSettings.Port
.ServerSettings.Protocol
is moved toServerSettings.AppSettings.Protocol
.
Namespace Changes
RoomOptions
is now in thePhoton.Realtime
namespaceAuthenticationValues
is now inPhoton.Realtime
namespaceRoomInfo
is now in thePhoton.Realtime
namespaceRoom
is now in thePhoton.Realtime
namespaceFriendInfo
is now in thePhoton.Realtime
namespaceTypedLobbyInfo
is now in thePhoton.Realtime
namespaceTypedLobby
is now in thePhoton.Realtime
namespaceLobbyType
is now in thePhoton.Realtime
namespaceRaiseEventOptions
is now in thePhoton.Realtime
namespaceWebRpcResponse
is now in thePhoton.Realtime
namespaceIPunObservable
is nowPhoton.Pun
namespace
Renamed
camelCase to PascalCase
Public fields and properties:
photonView.isMine
is nowphotonView.IsMine
photonView.owner
is nowphotonView.Owner
PhotonNetwork.automaticallySyncScene
is nowPhotonNetwork.AutomaticallySyncScene
PhotonNetwork.gameVersion
is nowPhotonNetwork.GameVersion
PhotonNetwork.masterClient
is nowPhotonNetwork.MasterClient
PhotonNetwork.isMasterClient
is nowPhotonNetwork.IsMasterClient
PhotonNetwork.inRoom
is nowPhotonNetwork.InRoom
PhotonNetwork.isMessageQueueRunning
is nowPhotonNetwork.IsMessageQueueRunning
PhotonNetwork.offlineMode
is nowPhotonNetwork.OfflineMode
PhotonNetwork.countOfPlayersOnMaster
is now `PhotonNetwork.CountOfPlayersOnMasterPhotonNetwork.countOfPlayersInRooms
is nowPhotonNetwork.CountOfPlayersInRooms
PhotonNetwork.countOfPlayers
is nowPhotonNetwork.CountOfPlayers
PhotonNetwork.countOfRooms
is nowPhotonNetwork.CountOfRooms
PhotonNetwork.sendRate
is nowPhotonNetwork.SendRate
PhotonNetwork.time
is nowPhotonNetwork.Time
PhotonNetwork.playerList
is nowPhotonNetwork.PlayerList
PhotonNetwork.precisionForVectorSynchronization
is nowPhotonNetwork.PrecisionForVectorSynchronization
PhotonNetwork.precisionForQuaternionSynchronization
is nowPhotonNetwork.PrecisionForQuaternionSynchronization
PhotonNetwork.precisionForFloatSynchronization
is nowPhotonNetwork.PrecisionForFloatSynchronization
PhotonStream.isWriting
is nowPhotonStream.IsWriting
PhotonStream.isReading
is nowPhotonStream.IsReading
RoomOptions.cleanUpCacheOnLeave
is nowRoomOptions.CleanupCacheOnLeave
RoomOptions.publishUserId
is nowRoomOptions.PublishUserId
RoomOptions.suppressRoomEvents
is nowRoomOptions.SuppressRoomEvents
Others
PhotonNetwork.connected
is nowPhotonNetwork.IsConnected
PhotonNetwork.connectedAndReady
is nowPhotonNetwork.IsConnectedAndReady
PhotonNetwork.networkingPeer
is nowPhotonNetwork.NetworkingClient
PhotonNetwork.connectionStateDetailed
is nowPhotonNetwork.NetworkClientState
PhotonNetwork.playerName
is nowPhotonNetwork.NickName
PhotonNetwork.room
is nowPhotonNetwork.CurrentRoom
PhotonNetwork.lobby
is nowPhotonNetwork.CurrentLobby
PhotonNetwork.player
is nowPhotonNetwork.LocalPlayer
PhotonNetwork.insideLobby
is nowPhotonNetwork.InLobby
PhotonNetwork.otherPlayers
is nowPhotonNetwork.PlayerListOthers
PhotonNetwork.sendRateOnSerialize
is nowPhotonNetwork.SerializationRate
PhotonNetwork.versionPUN
is nowPhotonNetwork.PunVersion
PhotonTargets
enum is nowPhoton.Pun.RpcTarget
PhotonPlayer
class is nowPhoton.Realtime.Player
PhotonPlayer.ID
is nowPhoton.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.
CallPhotonNetwork.AddCallbackTarget(this)
andPhotonNetwork.RemoveCallbackTarget(this)
(likely withinOnEnable()
andOnDisable()
respectivly)Replace
Photon.PunBehaviour
withMonoBehaviourPunCallbacks
.
Always call the base class methods if you overrideOnEnabled()
andOnDisable()
forMonoBehaviourPunCallbacks
PhotonNetwork.OnEventCall
is gone.
You have two options:- use
PhotonNetwork.NetworkingClient.EventReceived(EventData)
instead. - use
IOnEventCallback.OnEvent(EventData)
.
In PUN2, events callback signature changed but you can get what you need from
EventData
. Also, events callback will be triggered for all events and not only custom events (custom event code < 200).- use
PUN 1 (Callback) | PUN 2 (Interface | Callback) | |
---|---|---|
OnConnectedToPhoton | IConnectionCallbacks | OnConnected |
OnFailedToConnectToPhoton() | IConnectionCallbacks | OnDisconnected(DisconnectCause) |
OnConnectionFail() | IConnectionCallbacks | OnDisconnected(DisconnectCause) |
OnDisconnectedFromPhoton() | IConnectionCallbacks | OnDisconnected(DisconnectCause) |
OnConnectedToMaster | IConnectionCallbacks | OnConnectedToMaster |
OnPhotonMaxCccuReached() | IConnectionCallbacks | OnDisconnected(DisconnectCause) |
OnCustomAuthenticationFailed | IConnectionCallbacks | OnCustomAuthenticationFailed |
OnCustomAuthenticationResponse | IConnectionCallbacks | OnCustomAuthenticationResponse |
OnMasterClientSwitched(PhotonPlayer) | IInRoomCallbacks | OnMasterClientSwitched(Player) |
OnPhotonPlayerConnected(PhotonPlayer) | IInRoomCallbacks | OnPlayerEnteredRoom(Player) |
OnPhotonPlayerDisconnected(PhotonPlayer) | IInRoomCallbacks | OnPlayerLeftRoom(Player) |
OnPhotonPlayerActivityChanged(PhotonPlayer) | IInRoomCallbacks | OnPlayerEnteredRoom(Player) OnPlayerLeftRoom(Player) |
OnPhotonCustomRoomPropertiesChanged | IInRoomCallbacks | OnRoomPropertiesUpdate |
OnPhotonPlayerPropertiesChanged(object[]) | IInRoomCallbacks | OnPlayerPropertiesUpdate(Player, Hashtable) |
OnJoinedLobby | ILobbyCallbacks | OnJoinedLobby |
OnLeftLobby | ILobbyCallbacks | OnLeftLobby |
OnReceivedRoomListUpdate() | ILobbyCallbacks | OnRoomListUpdate(List<RoomInfo>) |
OnLobbyStatisticsUpdate() | ILobbyCallbacks | OnLobbyStatisticsUpdate(List<TypedLobbyInfo>) |
OnLeftRoom | IMatchmakingCallbacks | OnLeftRoom |
OnPhotonCreateRoomFailed(object[]) | IMatchmakingCallbacks | OnCreateRoomFailed(short, string) |
OnPhotonJoinRoomFailed(object[]) | IMatchmakingCallbacks | OnJoinRoomFailed(short, string) |
OnCreatedRoom | IMatchmakingCallbacks | OnCreatedRoom |
OnJoinedRoom | IMatchmakingCallbacks | OnJoinedRoom |
OnPhotonRandomJoinFailed(object[]) | IMatchmakingCallbacks | OnJoinRandomFailed(short, string) |
OnUpdatedFriendList() | IMatchmakingCallbacks | OnFriendListUpdate(List<FriendInfo>) |
- | IOnEventCallback | OnEvent(EventData) |
OnPhotonInstantiate | IPunInstantiateMagicCallback | OnPhotonInstantiate |
OnPhotonSerializeView | IPunObservable | OnPhotonSerializeView |
OnOwnershipRequest(object[]) | IPunOwnershipCallbacks | OnOwnershipRequest(PhotonView, Player) |
OnOwnershipTransfered(object[]) | IPunOwnershipCallbacks | OnOwnershipTransfered(PhotonView, Player) |
OnWebRpcResponse | IWebRpcCallback | OnWebRpcResponse |