Creating a VR multiplayer scene

Tutorial

intermediate

+10XP

20m

Unity Technologies

Creating a VR multiplayer scene

The second in a 3-part video series covering how the VR Multiplayer Project Template for Unity 6 can be used to make your own VR game by reusing prefabs and creating new gameplay. In part 2, we create a new Multiplayer scene, adding core multiplayer components, UI and interactables. We will be making our own networked interactable and test it.

1. Creating a VR multiplayer scene

Transcript

Introduction

Welcome to part two of this tutorial series on Unity's VR Multiplayer template. In part one, we covered the essential components and features that power VR multiplayer. Now, in part two, we'll keep working within the multiplayer template project and use it to create a scene from scratch, showing just how easy it is to set up a multiplayer environment. Let's jump in and bring these components to life in a real VR multiplayer experience.

The three core prefabs

This is the scene we looked at in part one: the sample scene that comes with the VR Multiplayer template project. It contains three core prefabs we can use to speed up building our own VR multiplayer scene:

  • XR Interaction Setup MP Variant is a core prefab in the template. It provides the foundational structure needed for VR interaction within a multiplayer environment.
  • NetworkManager VR Multiplayer Template is a critical prefab that manages the project's multiplayer networking setup. It contains the components responsible for handling network connections and synchronizing players across the multiplayer environment.
  • XRI Network Game Manager is essential for managing core multiplayer features in the template. It provides components tailored specifically for a networked VR experience.

Reusing these three prefabs is incredibly useful because they provide a solid foundation of multiplayer and VR functionality without needing to build it yourself. Each prefab is preconfigured with the essential components that handle complex VR and multiplayer interactions. By reusing them, you streamline development, build on reliable templates, and simplify the path to an engaging multiplayer VR experience.

Creating a new multiplayer scene

Let's begin by creating an empty scene. Go to File > New Scene, select Basic (URP), and click Create.

In this fresh scene, remove the Main Camera, since we won't need it. Next, add a surface for the player to stand on: add a plane to the scene and make sure it's positioned at 0, 0, 0.

To get multiplayer connectivity up and running quickly, we'll reuse the prefabs from the sample scene. In the search bar, type "XR Origin," and you'll see XR Origin Hands (XR Rig) MP Template Variant. Drop that into the scene, since it's the one used in the sample scene, and position it at 0, 0, 0. I'll also scale up my floor. This XR Origin contains everything needed for it to work in multiplayer: the Camera Offset with all the usual XR Interaction Toolkit components, plus the addition of the offline player avatar.

We also need the NetworkManager VR Multiplayer prefab. In the search box, start typing "network manager," and you'll see NetworkManager VR Multiplayer Template. Select it and drop it into the scene. It's preconfigured, so we can get going with multiplayer straight away.

The last prefab we need is the XRI Network Game Manager. Once it appears in the search results, drop it into the scene as well.

We can test this right away. Enter Play mode, and our controllers and everything else work as before. Press the menu button on the left controller, and a panel appears informing us that room options aren't available offline. That's fine, since we haven't joined a room yet. Under Appearance, we can customize our avatar, randomize its color, and give ourselves a name using the spatial keyboard by clicking the globe icon. Under room options, we can quick-join a public room or create a new room. I'll choose Quick Join, and there we are: we've created a room and we're in our multiplayer space, with a notification saying we've joined voice chat, just as before.

Testing with Multiplayer Play Mode

To test our multiplayer functionality, we can use Multiplayer Play Mode, which we discussed in part one. Activate the second player, and you'll see Player 2 is now active with a second game window we can use.

Enter Play mode again and choose Quick Join Public Room as Player 1. We're now in our virtual space. Next, switch to Player 2, bring up the menu, name ourselves "Player 2," and click the globe icon. We can see the player's room available to join, which belongs to our main player, the main Unity instance. Click Join, and we're joining that player's room.

Now we're in the scene. I can see Player 1, the main Unity instance, while I play as Player 2 in the separate window. By leveraging these ready-made prefabs, we can very quickly create a multiplayer VR scene. They're all configured and ready to go, speeding up development and letting us focus on gameplay and interactions.

From here, we'll add some interactables to make the scene more engaging and look at the components required to sync those interactable objects across the network.

Adding networked interactables

In this section, we'll look at interactable objects and how to sync them across the network. I've added a very simple table with a couple of interactable objects to the scene. One is an arch, a prefab from the sample scene. This grabbable object contains components from the XR Interaction Toolkit, namely the XR Grab Interactable and the XR General Grab Transformer. It also has three network components:

  • Network Object is essential for syncing objects across the network. It gives each object a unique identity and keeps it consistent for all players. It manages ownership, so each player has control over their own objects, and it handles spawning and despawning so everyone sees the same game world.
  • Client Network Transform is crucial for synchronizing an object's position and rotation across clients. It lets each client directly update the transform of its own objects, which is ideal for VR, where players need responsive, accurate movement such as hand and head tracking to feel immersed. It reduces network load by letting clients manage their own movement while still keeping everything in sync for all players in the shared space.
  • Network Physics Interactable brings realistic, synchronized physics interactions to multiplayer VR. By combining network synchronization with physics properties, it lets objects behave consistently across clients whether they're thrown, dropped, or manipulated, so all players see the same real-time responses to forces and interactions.

Let's test this in the VR environment. Enter Play mode, bring up the menu to join a room, and choose Quick Join Public Room. Now we're in our VR space, and I can interact with both objects: a regular cube and the networked arch in front of me.

Using Multiplayer Play Mode, I can switch to Player 2 and do the same. Under public rooms, I can see the player's room and join it. Player 1 is over there in front of us. As I approach, I can pick up the networked object, and Player 1 sees it moving around along with everything I do to it. If I increase its scale, Player 1 sees that change too. These scripts are syncing position, rotation, and scale across the network.

Adding UI

Next, we'll add some UI to make it easier for the player to join a room. Currently, when we enter Play mode, there's no obvious way to join or create a room. Pressing the menu button on the left controller brings up a panel that lets us join a room and edit our avatar, but it'd be nicer to have that UI right in front of us.

We can leverage the sample scene again and bring some of its UI into our scene to speed up development. Let's jump into the sample scene and look at the UI available there. It has an Offline Menu UI element, which includes options to change the player's appearance and to create and join rooms. We can bring this Offline Menu UI prefab into our scene for a smoother avatar customization and room-joining experience.

To add these UI elements, we first need a canvas for our world space UI to sit inside. On the Canvas component, add a Tracked Device Graphic Raycaster. Creating the canvas also creates an Event System by default, which places itself in the scene. For our controllers to interact with canvas objects, add the XR UI Input Module to the Event System and remove the Input System UI Input Module.

Back on the canvas, change the render mode to World Space and set its position to 0, 0, 0. We're essentially copying the values from the sample scene here.

Now drop in the Offline Menu UI. If you can't find it, type its name into the search box, then drag and drop it onto the canvas we just created. This places the Player Appearance UI, the currently active Lobby UI object, and a door object into the scene; we'll talk about the door in a moment.

The two UI elements are currently positioned very high, so select them and change their height to 1, which is more appropriate for this scene. Then jump into VR to check that everything works.

In VR, we can see our character and use all the usual tools, including the spatial keyboard. After confirming our avatar, we can use the Lobby UI to create a public room with the same options as before. Choose Quick Join Public Room, and it's as simple as that. By bringing in this UI from the sample scene, we've made it easier for users to create a lobby and personalize their avatar.

Toggling objects based on connection status

Now let's look at the door object. In the sample scene, once you connected to a room, the door removed itself so you could see the level beyond. Using components from the template project, we can recreate that functionality very easily.

First, create an empty object called "UI" to store all our UI elements, and position it at 0, 0, 0. Drag the canvas into that object and rename the canvas "World Space Canvas." It currently contains the Offline Menu UI, and we can add more UI there as needed.

To make the door disappear, search for the Connection Toggler component on the UI object and add it. Under Objects to Enable Offline, add the door object.

The Connection Toggler script is a simple tool for managing GameObjects based on network connection status. When a player connects, specified objects are enabled while others are disabled, and vice versa on disconnect. It's perfect for tailoring in-game visuals and interactivity to the connection state, so players see only the content relevant to whether they're online or offline.

We can take this further with our table interactables. We wouldn't necessarily want users interacting with these until they're connected online; the first thing they should see is the UI for creating or joining a lobby or room. So turn off the table interactables object, then add a Connection Toggler to the interactables object and drop the table interactables into Objects to Enable Online.

Let's see it all working. In the scene, confirm the avatar and choose Quick Join Public Room, which should remove the giant doorway in front of us. There it goes, and the table now appears as well. As soon as the connection was established, the door was removed and the table was activated, all using the Connection Toggler.

Making an interactable from scratch

Next, let's add an interactable from scratch, along with the components required to sync it across the network.

Right-click the table interactables object and choose Create Empty. This will be the parent object for the new interactable; call it "Sphere Interactable" and move it near the table in the scene.

Inside Sphere Interactable, add a 3D object so we can see it: create a sphere and scale it down across all axes. I like to keep artwork separate from colliders, so remove the collider from this sphere.

Then create another object inside Sphere Interactable for the colliders. Inside that colliders object, create a new 3D object; since we're working with a sphere, we can use a sphere again. Scale it down to match, and since we don't need the artwork for this one, remove its renderer component. Rename it "Sphere Collider."

On the Sphere Interactable parent object, add a Rigidbody, and to make it grabbable, add an XR Grab Interactable. The XR Grab Interactable defines how an object can be grabbed and interacted with in VR and AR, and it supports a range of interactions, including picking up, dropping, and manipulating.

Another component we'll need is the XR General Grab Transformer. Part of the XR Interaction Toolkit, it enables intuitive object manipulation in VR and AR, supporting both single- and two-handed interactions. It allows movement, rotation, and scaling, with customizable constraints and behaviors.

Within the XR Grab Interactable, make the following changes:

  • Change Movement Type from Instantaneous to Velocity Tracking. This uses the interactor's movement speed to drive the object's motion, so it collides with other objects in the scene.
  • Enable Use Dynamic Attach, which also enables the Match Position, Match Rotation, and Snap To Collider Volume checkboxes. When enabled, Dynamic Attach updates the interactable's attach point based on where the user grabs the object.
  • Uncheck Retain Transform Parent. This setting determines whether a grabbed object's transform stays relative to its parent or becomes independent when picked up. Unchecking it detaches the object's transform from its parent so it behaves independently, allowing proper synchronization across all clients.

With the sphere selected, add the network components:

  • Network Object, a key component that enables synchronization of player actions and objects across multiple users in a shared virtual environment.
  • Client Network Transform, which synchronizes the object's position, rotation, and scale across clients in the multiplayer environment.
  • Network Physics Interactable, which syncs physics-based interactions across players, enabling real-time object manipulation for all clients.

Now we're in Multiplayer Play Mode. As before, the arch prefab from the sample scene moves for both players because it's synced across the network. Our new sphere, with all its components attached, can now be grabbed and manipulated too, and its position and rotation are synced across the network for all players.

Conclusion

In this video, we explored how the template project can be used to set up a multiplayer environment from scratch quickly. In just a few minutes, we went from a blank scene to supporting user customization, room creation, and connection-dependent object toggling.

This template is more than just a quick start. It's a powerful foundation for building your own VR multiplayer game. With built-in prefabs, network-ready components, and core features like avatar customization and room management, you have a solid base to expand on and tailor to your unique gameplay vision.

Corrections from the auto-captions included "scam" to scene, "fre core prefabs" to three, "track device graphic raycaster" to Tracked Device Graphic Raycaster, "X our UI input module" to XR UI Input Module, "spheral ligher" to Sphere Collider, "sink" and "think" to sync, and "snap to collide the volume" to Snap To Collider Volume. I also changed "interactive's movement speed" to "interactor's," which matches how Velocity Tracking works.

Complete this Tutorial