Show Sidebar

Photon Unity Networking Intro

Get Started

Photon Unity Networking (PUN) is a Unity package for multiplayer games. It provides authentication options, matchmaking and fast, reliable in-game communication through our Photon backend.

PUN exports to almost all platforms supported by Unity and comes in two flavors:

PUN FREE

PUN FREE Unity Plugin Export to almost all platforms. iOS and Android exports require Unity 5 or Unity 4 Pro with mobile license.

Get PUN FREE

PUN PLUS

PUN FREE Unity Plugin Export to all supported platforms, no matter what Unity license you have. It also includes a 100 concurrent user Photon Realtime plan for 60 months.

Get PUN PLUS for just $ 95.

Note: For Unity 5, both PUN packages contain the same files. You can buy PUN+ to get 100 CCU for 60 months but still use PUN Free on the client side.

Comparison of PUN, PUN+ and Unity Networking

  PUN PUN+ UN  
Price FREE $ 95 FREE
Free CCU 20 100
World wide hosting UN needs Master Servers.
Unity Networking compatible Old Unity Networking (not UNet).
Unity FREE: Web, Standalone
Unity 4 FREE: iOS, Android UN has punchthrough issues on mobiles.
Unity 5 FREE: iOS, Android UN needs Relay Service for mobiles.
Host migration (not built-in) (not built-in)
Rooms, Lobby support

See the article Photon Unity Networking (PUN) Compared To Unity Networking (UN) for a in-detail comparison of the two.

Some Code Required

To get the best out of PUN, you will need to write some scripts. This page shows you the most important pieces to get you started.

You should also take some time to work through the "PUN Basics Tutorial".

Connect

The code above is all you need to connect and start using Photon's features.

ConnectUsingSettings sets your client’s game version and uses a config file that's written by the PUN Setup Wizard and is stored in PhotonServerSettings.

Matchmaking

Next, you'll want to join an existing room or create your own. The following code snippets show possible method calls to start or join games.

Friends usually want to play together. If they can communicate (e.g. with Photon Chat, Facebook), they can make up a room name and use JoinOrCreateRoom. As they know the room's name, they can create it invisible for others like so:

With JoinOrCreateRoom, the room gets created if it didn't exist. If it's full, OnPhotonJoinRoomFailed gets called (if you implemented it somewhere).

Read more about matchmaking in our guide.

Gameplay

GameObjects can be Instantiated as "networked GameObjects". They have a PhotonView component to be identified and an owner (or controller). The owner updates everyone else. Continuous updates can be sent by dragging a script into the Observed field of a PhotonView. The script must implement OnPhotonSerializeView like this:

Clients can do Remote Procedure Calls for infrequent actions:

Independent from GameObjects, you can also send your own events:

Read more about PUN's RPCs and RaiseEvent here.

 To Document Top