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
Rooms, Lobby support
Player Quality of Service (QoS)

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 Marco Polo 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 shows 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).

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:

Get Support

We, the Photon Team ( sometimes referred to as Photonians :), are dedicated to help you. If you've got questions, curiosities, ... or your app doesn't work but you really wish it would, try any of these:

Get It Faster

For quick turn-arounds please include, together with reproducible steps:

  • Photon Client SDK version
    • This is part of the SDK zip file name.
    • In case of PUN send us the value of: PhotonNetwork.versionPun.
  • Photon Cloud
    • Drop us the AppId and the Game Version which is set via Connect*() call.
    • If you have trouble with some room, send us the RoomName and the Server Address of it. In C#, log client.CurrentServerAddress while in the room
    • Let us know the Region and the Server Address.
  • Photon Server
    • Hosting a Server? Let us know the Server SDK Version. Again, this is part of the SDK zip file name.
    • Add your logs.

Get in Touch

We'd love to know what you want to read and see in our docs, whether that is more demos, specific documentation, an FAQ or example applications. If there's something you'd like to see that's not already in drop us your suggestion to developer@photonengine.com.

Want to learn more about Photon?

Get started, Try Free Plan
Find us at these events and venues.
Request a meeting.

 To Document Top