When creating a multiplayer app for Meta Quest, you need to implement a networking solution that can handle routing the networking traffic in a shared user experience.
When selecting a networking solution, it’s important to choose according to the needs of your app. The networking architecture and structure of an MMO-style game is vastly different from the networking needs of a smaller, 4-player app.
For this use case study, you will learn about how the SharedSpaces sample app uses Netcode for GameObjects with the Photon Realtime transport. This sample app expects a maximum of four users in a concurrent play experience, which is why Photon is an ideal choice.
App design considerations
In the SharedSpaces sample, the Photon networking solution uses the concept of a room where users can be grouped together in the same match or a lobby. Each created Photon room has a unique name that is pulled directly from the MatchSessionID string or the LobbySessionsID string. The Photon networking layer keeps track of the oldest member in the room, and labels them as the “master client”.
The master client acts as the primary peer for the Photon room and can accept connections from other players attempting to join.
In the following example, the user with a star next to their name is designated as the master client, and becomes the primary peer for the Photon room.
When the master client leaves the Photon room, host migration occurs, and a new master client will be selected. Typically, the user with the next lowest actor number (the number or ID assigned to a player when they join a room) will be chosen. For an example of how the SharedSpaces showcase app handles host migration, check the SharedSpacesNetworkLayers.cs in the oculus-samples Github repo.
Set up Photon Account for networking
After setting up Group Presence in your project, select and implement a networking solution for your app. Here is how to set up Photon.
First, configure the NetDriver with your own Photon account. If you don’t have a Photon account, use the following steps:
Ensure that the Application Type is set to Multiplayer Game and the Photon SDK is set to Realtime.
After finishing the new app form, set the type to Photon Realtime, then click Create.
Next, store the App ID from your created app. You can find and copy the App ID string from the Photon dashboard where your newly created Photon Realtime app will be displayed.
Note: Copy and store your Photon App ID somewhere securely.
Next, paste your App ID into the PhotonAppSettings.asset file. To do so, navigate to Assets > Photon > Fusion > Resources and select PhotonAppSettings.asset.
Paste your App ID into the App I Realtime, App Id Chat, and App Id Voice fields.
Connect to Photon
Once your app has been created and connected to the Meta Quest Developer Center you must connect your Unity app, for this use case the SharedSpaces sample, to your Photon App ID.
After connecting the Unity app to your App ID in the Meta Quest Developer Center, connect the pre-packaged networking solutions to the previously created Photon App ID in your Unity editor.
Use the following steps:
From the Project folder, navigate to Assets > Photon > Fusion > Resources, and select the PhotonAppSettings.asset file.
In the Inspector, copy your Photon App ID and paste it into the App Id Realtime, App Id Chat, and App Id Voice fields.
Once finished, save your Unity project.
After finishing the setup for the SharedSpaces sample app, players can be invited into the created Photon room and interact with one another and the app. The Photon networking layer handles communication for the players in the app experience.