Adding VR Multiplayer to UE5
Created by Austin Phan, Spring 2023
Tested using Unreal Engine 5.0.3, with latest plugin version.
Introduction
So, you want to make a multiplayer application in Unreal Engine, in VR. I did quite a bit of research on this topic, and found that currently there's no super 'nice' way to make it work, that's free. Unlike Unity, which has access to some free hosting plugins, or has native support for plugins that integrate directly with Unity's system and some servers, Unreal Requires a bit more work.
I found that Photon allows you to connect to their cloud server for free, with a bandwith cap and maximum number of connections. While looking into the server service, I found that Photon has Unreal Engine support, but only through their SDK, which could require some previous programming knowledge and a bit of time to get everything working nicely, which is something that I didn't have the time for while working on my projects.
I found this plugin, which packages everything nicely into Unreal Engine to work with photon cloud, and connect with your own free server. The only drawback is that it's $50. However, it seems to work pretty okay as a plugin.
The next sections use this plugin in order to get multiplayer to work nicely. Maybe a fun project would be working with the Photon SDK and releasing an open source version that allows people to integrate multiplayer with Photon cloud?
Important Tutorials:
I used one main tutorials to get multiplayer in VR. The main tutorial refers back to another tutorial multiple times, so I'll link that here too.
Adding Multiplayer VR to UE5 (The Gabmeister): https://thegabmeister.com/blog/unreal-vr-multiplayer-photon/
Adding Multiplayer to UE5 (3rd-person mode, Non-VR): https://thegabmeister.com/blog/unreal-photon-multiplayer/
Unreal Engine 5 Multiplayer FPS Tutorial Part 1/2 - Photon Cloud - https://www.youtube.com/watch?v=mL5cf8M4RRk
This is a video done by the developer of the plugin himself on how to get the plugin working (Non-VR).
Unreal Engine 5 Multiplayer FPS Tutorial Part 2/2 - Photon Cloud - https://www.youtube.com/watch?v=ywI7vmxhaz4
Second part to the above video (Non-VR).
Adding Teleport & Snap Turn to UE5 VR Multiplayer Pawn
One of the shortcomings I ran into while using the VR multiplayer Pawn that I created using the above tutorials was that they were unable to interact with the world. They are unable to move, grab, or interact with items in the world. I didn't have the time to implement grabbing in the VR world, but was able to add teleport and get it working in a multiplayer sense.
An aside: Teleport in multiplayer VR isn't a great implementation of movement. Due to the nature of needing to follow people sometimes in VR, having people teleport and jump around (sometimes possibly out of view) can make it extremely difficult to follow targets. I'd recommend that you implement some sort of smooth movement into your pawn (here's a tutorial I tried, but couldn't get to work), so that people are able to see movement of player. A workaround to this would be having some sort of 'animation' between movements client-side to give a sense of direction in teleport to the user, to make it easier to follow.
This section assumes that you've setup the Custom VRPawn actor in the same way as the first tutorial above.
Part 1: Setup
Ensure that you've setup the custom VRPawn actor that's multiplayer compatible in the world, and that it works with your photon server.
Import a copy of the original VRPawn template that's used in the VR template
You can do this by opening the content browser, pressing add, pressing 'Add Feature or Content Pack', and pressing 'VR'. Make sure you enable all of the requested plugins on import.
Part 2: Copying Blueprint Components
You'll need the template VRPawn actor, and the BP_VRPawn that you created in the multiplayer tutorial in this situation. You won't need any of the other BP_X creations that you've made in this section.
Open both in the blueprint editor. You can do this by double-clicking each item in the content browser, or right clicking on them and pressing 'Edit'.
View the components tab of the VRPawn Actor. It should look like this:
You'll need to copy the following items:
TeleportTraceNiagaraSystem
MotionControllerRightAim
WidgetInteractionRight
MotionContollerLeftAim
WidgetInteractionLeft
Select all of them, and copy them into the components of BP_VRPawn that you created. Arrange them accordingly:
Check the variable names for each imported item. Ensure that none of the imported components have spaces in their variable names. Hitting 'compile' for the entire system should yield no errors.
Part 3: Copying All The Needed Blueprint Functions
You'll need the template VRPawn actor, and the BP_VRPawn that you created in the multiplayer tutorial in this situation. You won't need any of the other BP_X creations that you've made in this section.
Open both in the blueprint editor. You can do this by double-clicking each item in the content browser, or right clicking on them and pressing 'Edit'.
In VRPawn, you'll need to copy the following functions:
isAxisGreaterThanDeadzone
TryTeleport
EndTeleportTrace
IsValidTeleportLocation
TeleportTrace
StartTeleportTrace
SnapTurn
Copy all of these functions into BP_VRPawn. They should now show up in BP_VRPawn's 'Function' Tab. (see right for example)
Compile now. You should see a few errors pop up. They're mostly missing variables that don't match or show up in this actor's implementation.
For example, in IsAxisGreaterThanDeadzone, compiling leads to the following error:
Simply right click the missing variable, press 'Create variable', and UE will add the variable for you. Make sure to recompile everytime you make a change. It should fix most issues. Do this with all of the missing variables. Make sure you compile after every addition, as it may clear duplicate errors.
Note: make sure to right click outside of the word, but still inside the code block. Different menus may show up depending on where you click. In the above example, click outside of 'Axis Deadzone Threshold', but inside of the box.
Also: Snap Turn Degrees in the 'snap turn' function should be set to 45 degrees, or however much you want to snap turn by.
Adding all of these variables will fix any compilation errors. Once that's done, the blueprint should compile successfully, and you can move onto the next section.
Part 4: Adding to BP_VRPawn's Event Graph
The final part you need to edit is in BP_VRPawn's Event Graph. Open it now. If you've followed everything up to this point, it should look a bit something like this:
It should contain sections to setup pawns, send and recieve pawn locations, and more.
Copy the following sections (all of the nodes) from the template VRPawn:
Movement AxisInput Right - Teleport
Movement AxisInput Left - Snap Turn
Paste it into BP_VRPawn's event graph, outside of all of the other nodes. Compile, and you should be all set! You've sucessfully implement teleport and snap turn to the multiplayer VR application you have.