Home
Blog
Building your multiplayer VR experience: Setting up your own copy of the SharedSpaces Sample in Unity

June 14, 2022

Building your multiplayer VR experience: Setting up your own copy of the SharedSpaces Sample in Unity

By Navyata Bawa

In this four-part “Building Your Multiplayer VR Experience” blog and video series, we’ll discuss the Platform SDK multiplayer features in Quest by exploring our open-sourced SharedSpaces sample made in Unity, and show you how to use the sample to build your own multiplayer app. This is Part 2. If you missed Part 1, you can read the blog post here and watch the video here.

If you're interested in learning by watching or listening, check out this video on the Meta Open Source YouTube channel.

In today’s blog, we’ll go over the steps involved in building your own copy of the SharedSpaces sample in Unity. We’ll discuss how to clone the repo from GitHub, set it up in Unity and deploy it on your headset.

Getting the code

The repo that contains the code for the Unity SharedSpaces sample can be found on the oculus-samples GitHub.

As mentioned in the README, make sure that you have Git LFS installed by running:

git lfs install

You can clone the repo by running:

git clone https://github.com/oculus-samples/Unity-SharedSpaces.git

If you haven’t already, install the Oculus PC App on your machine to be sure that all the necessary SDKs are available. The app can be installed from the Meta Quest website. While setting up the Oculus PC App, allow Oculus to be set as the default Open XR Runtime when asked. Next, let’s look at the setup on the Quest side.

Set up on Quest

Creating your new app

The first step is to set up a new app on the Oculus website so that this new app can be associated with our copy of the Unity SharedSpaces sample. To do this, visit the Oculus Developer Center website and create a new app for your project by clicking “My Apps” in the top-right corner.

On the Oculus Developers Dashboard, if you don’t have one already, create a new organization for your project as shown below.

Once your organization is set up, create a new app by clicking the “Create New App” button on the top right.

When creating a new app, choose a name and choose the appropriate platform for distribution. In our case, we’ll be building a Quest app for App Lab.

For this example, you can name the app Unity Shared Spaces.

Once the app is created, click “API” on the left navigation to reveal more details about the app. You’ll need to note the AppID to set up your app correctly once you’re in Unity.

Setting up destinations for your app

To set up the SharedSpaces destinations for your app, click “Platform Services” in the left navigation window, and then click “Add Service” in the “Destinations” box in the center window.

To create your destinations, you’ll need to add the settings that mention the API name and the deeplink message for each destination as shown in the table below. To do this, click the “Create Destination” button in the upper right corner of the Destinations page.

On the New Destination page, add the data for the first API, “Lobby,” and then click “Submit for Review”. You’ll need to do this for each API in the table below.

For the SharedSpaces sample, the Deeplink Type must be set to “Enabled,” and the Audience must be set to “Everyone.”

This step is also shown under “Destinations” in the README.md file in the Github repo.

API Name

Deeplink Message

Display Name

Description

Lobby

{"is_lobby":"true","map":"Lobby"}

Lobby

The Lobby

RedRoom

{"map":"RedRoom"}

RedRoom

The RedRoom

GreenRoom

{"map":"GreenRoom"}

GreenRoom

The GreenRoom

BlueRoom

{"map":"BlueRoom"}

BlueRoom

The BlueRoom

PurpleRoom

{"map":"PurpleRoom","public_room_name":"ThePurpleRoom"}

PurpleRoom

The PurpleRoom

Here’s how the Destinations page will look once the APIs are successfully added:

Once you’re satisfied with the page, click “Back to App Dashboard” to start the next step.

Setting up the Data Use Checkup for your app

The next step is to set up the Data Use Checkup for your app. Data Use Checkup certifies your compliance with Oculus Developer Policies and protects your users’ data. To do this, click “Data Use Checkup” in the Dashboard. You’ll need to request access to the platform data that is needed by SharedSpaces. Add the following items under Data Use Checkup and submit for certification:

  • User ID
  • User Profile
  • Deep Linking
  • Friends
  • Invites

For each item, choose the options that best describe your usage. An example of this prompt is shown below. Learn more about Data Use Checkup in our documentation.

The table below shows an example of usage options that you can choose when setting up the Data Use Checkup for this demo. When describing how you plan to use the item in your app, be specific and explain your use case. The use case for each item can vary from app to app. For the purposes of this demo, we will keep the description generic.

Item

Usage

Description

User ID

  • Use Destinations, Group Presence and App Deep Linking
  • Use Multiplayer with Photon/Playfab
  • Use Peer-to-Peer (P2P Networking)
  • Use Rooms
  • View Oculus username
  • Display friends to invite
  • Enable users to invite others
  • Use Voice Chat (VoIP)

Setting up User ID usage for Data Use Checkup for testing Unity Shared Spaces

User Profile

  • Use Destinations, Group Presence and App Deep Linking
  • Use Multiplayer with Photon/Playfab
  • Use Peer-to-Peer (P2P Networking)
  • Use Rooms
  • View Oculus username
  • Display friends to invite
  • Enable users to invite others
  • Use Voice Chat (VoIP)

Setting up User Profile usage for Data Use Checkup for testing Unity Shared Spaces

Deep Linking

  • Use Destinations, Group Presence and App Deep Linking
  • Enable users to invite others

Setting up Deep Linking usage for Data Use Checkup for testing Unity Shared Spaces

Friends

  • Use Multiplayer with Photon/Playfab
  • Use Rooms
  • Display friends to invite

Setting up Friends usage for Data Use Checkup for testing Unity Shared Spaces

Invites

  • Use Multiplayer with Photon/Playfab
  • Use Rooms
  • Display friends to invite
  • Enable users to invite others

Setting up Invites usage for Data Use Checkup for testing Unity Shared Spaces

Once you submit, you’ll be asked to provide a Privacy Policy URL. (If you fork the project, you can add a privacy policy markdown file and link to that.) After you provide the Privacy Policy URL, the requested platform features will be indicated as “approved,” as shown in the image below.

Set up on Photon

The next thing you need to configure is the NetDriver with your own Photon account. Photon’s base plan is free and will be sufficient for you to create and run this demo. Visit Photon’s website and create an account. Once your account is created, click “Create A New App” on your Photon dashboard. While filling out the form, make sure to set the type to “Photon Realtime.” Next, click “Create.”

Once the app is created, click “App ID'' to reveal the complete App ID. You’ll need this information to set up Photon in your Unity project.

Set up on Unity

Setting up the Unity project

Now that the project is set up in the Oculus Developer Dashboard as well as Photon, you can open the project that you cloned from GitHub in Unity. If your version of Unity is different from the one that the project uses, it might throw a warning to update the version and dependent packages. Go ahead and accept it by clicking “Continue,” and it will regenerate the dependencies and open up the project.

Once the project has successfully launched, make sure that you have the Oculus XR Plugin for Unity installed. This is required to build apps for Meta Quest devices. To install the plugin, open the Package Manager under Window in the Unity editor. Search for "Oculus XR Plugin" and click Install if it's not already part of the project.

Now, open your main scene called “Startup.” To open this scene, click Assets → SharedSpaces → Scenes → Startup.

When the scene tries to load, it might warn you about a missing package called TMP or TextMesh Pro as shown below. Import the package to proceed.

Setting up your Oculus app in the Unity Project

The next step is to set your App ID in the resources so that the project can be associated with the new project that you made on Oculus. To set this up, add the App ID under Assets → Resources → OculusPlatformSettings as shown in the image below. You can find your App ID in the Developer Dashboard under the API section for the app.

Setting up Photon in the Unity project

Set up Photon App ID by copying the ID from your Photon app that you created on Photon. To do this, copy the App ID from the newly created Photon project to PhotonAppSettings under Assets → Photon→ Resources. Populate the App ID Realtime, App ID Chat and App ID Voice with the App ID created on Photon as shown.

Congratulations! You are all done with setting up the Unity SharedSpaces project. We’re on the home stretch. Next, let’s see how to build and run the project on our Quest.

Building the project

Since you’ll be building the app on Quest, you can update your target build platform to Android. To do this, click File → Build settings from the main menu on the top left of the editor. Under available platforms, choose Android as shown below.

Also make sure to update the Android manifest file under the Oculus settings. To do this, click Oculus → Tools → UpdateAndroidManifest.xml in the top menu of the editor. Updating the Android Manifest file is necessary and will make sure that any missing properties are correctly included in the manifest file.

You’ll also need to update the bundle name to a unique name that best suits your app. This can be done by clicking Bundle Identifier under Assets → Resources → OculusPlatformSettings → Build Settings.

Click “Build,” making sure that you have set the keystore and the platform is set to Android. Unity will create an APK file that we will use to upload and run on our headset.

Running the app

You can use Oculus Developer Hub (ODH) to run the app using the APK that you created from the Unity project build. ODH is our essential desktop companion tool that streamlines Meta Quest development (download here).

Once you have ODH installed, open ODH. Sign in with the same Oculus developer account that you are signed in with on your Quest headset. Go to the Device Manager tab to locate your headset. Make sure your headset is powered on and connected to your computer via USB-C. Read more about enabling your device for development and connecting your headset to ODH. You may need to enable Developer Mode and Allow USB Debugging if you have not completed these steps before.

You can upload your APK in ODH. Click the App Distribution tab → Choose the app for your SharedSpaces project → Choose release channel (we recommend “Alpha”) → Upload.

You should also make sure to add yourself, as well as any other people, as “Users” under App Manager → Distribution → Release Channels on the Developer Dashboard as shown below. All users listed here on the release channel will get access to the app. The app will now show up in their library, and they can install it from there.

You are now ready to run your own copy of the Unity SharedSpaces sample on your headset. In ODH, click “Install build on device” under the App distribution tab → your SharedSpaces project → your selected release channel → three dots for more options. This will install the app on your headset.

Once you launch the app, you’ll see your character in the lobby. You can see the debug log, the invite panel and the roster. You are the server and the one hosting the room. This is depicted by the arrow above your username. You can invite your friends or colleagues to join using the invite panel as well as get details on who has joined you by viewing the roster panel.

This was a detailed walkthrough of the steps involved to set up our own copy of the Unity SharedSpaces sample app, all the way from cloning the repo to building and running it on your headset. In our next blog, you’ll learn how you can build a simple multiplayer VR game on top of the SharedSpaces sample app you just created. We’ll go over the networking layer, the steps to customize your character and how to invite friends.

Be sure to check out our previous blog in the “Building your multiplayer VR experience” series to learn more about what multiplayer features offer, what you can build with them and how you can use the SharedSpaces sample to help you get started:

Building Your Multiplayer VR Experience: Platform SDK and Unity SharedSpaces Sample


About this series

In this series, we discuss the Platform SDK multiplayer features in Quest by exploring our open-sourced SharedSpaces sample made in Unity. This blog is the first of a four-part series of blogs supporting the video series “Building your multiplayer VR experience.”

To learn more about the Platform SDK multiplayer features and how the SharedSpaces sample works, check out this Connect session that discusses building and growing multiplayer apps for Quest. Try out the Unity SharedSpaces sample by visiting App Lab and running it on your own headset. To learn more about how to use Platform SDK multiplayer features in your own apps, checkout our documentation for multiplayer features.

To learn more about Meta Quest, visit our website, subscribe to our YouTube channel, or follow us on Twitter and Facebook. If you have any questions, suggestions or feedback, please let us know in the developer forums.

To learn more about Meta Open Source, visit our open source site, subscribe to our YouTube channel, or follow us on Twitter and Facebook.


Get our newsletter

Sign up for monthly updates from Meta for Developers.

Sign up