No history yet

Introduction to Photon and Unity

Building Multiplayer Games

Creating a multiplayer game adds a new layer of complexity. It’s not just about what happens on one player's screen; it's about synchronizing actions, positions, and events across multiple devices, potentially continents apart. Unity used to have its own networking solution, but it has since been deprecated. This is where third-party tools come in, and one of the most popular is Photon.

Photon Unity Networking, or PUN, is a framework that makes building multiplayer games in Unity much simpler. Think of it as a specialized postal service for your game. Your game sends out small packets of information, like "Player A moved to these coordinates" or "Player B fired a laser." Photon's servers, called the Photon Cloud, act as the central post office, receiving these packets and delivering them to all the other players in the game session almost instantly.

PUN handles the complex server infrastructure, so you can focus on building the game itself.

Why choose Photon? It's built for scale. Whether you have ten players or ten thousand, Photon’s infrastructure is designed to handle the load. It's also known for being relatively easy to get started with, and it has a large, active community. If you run into a problem, chances are someone has already solved it and shared the solution.

Lesson image

Setting Up Photon

Getting started with Photon requires two main steps: creating a Photon account to manage your applications and then integrating the Photon SDK (Software Development Kit) into your Unity project.

First, you'll need to create a free account on the Photon Engine website. Once you're logged into your dashboard, you'll create a new application. For the "Photon Type," select "Photon PUN." Give your application a name, like "MyFirstMultiplayerGame," and create it.

The dashboard will then generate a unique "App ID" for your project. This ID is crucial. It’s how your game will identify itself to the Photon Cloud and connect to the right servers.

Your App ID is like a secret key. Keep it safe and don't share it publicly.

Integrating with Unity

With your App ID in hand, it's time to bring Photon into your Unity project. The easiest way is through the Unity Asset Store.

  1. Open your Unity project.
  2. Go to Window > Asset Store.
  3. Search for "PUN 2 - FREE".
  4. Click "Download" and then "Import".

Unity will display a window showing all the files and folders in the PUN package. For now, you can leave everything selected and click "Import."

Once the import is complete, a new window called the "PUN Wizard" will pop up. This is where you connect your project to the Photon Cloud. It will ask for your App ID. Copy the ID from your Photon dashboard and paste it into the wizard's input field. Click "Setup Project," and you're done. Your Unity project is now connected to Photon's network and ready for you to start building multiplayer features.

Ready to check your understanding?

Quiz Questions 1/5

What is the primary role of Photon Unity Networking (PUN) in game development?

Quiz Questions 2/5

What is the unique identifier that connects your Unity project to the Photon Cloud?

Now that you have Photon integrated, you're ready to start scripting your first multiplayer interactions.