Developing for the Meta Quest 3 with Unreal Engine 5
You’ll be using Unreal Engine 5 to develop Virtual Reality on Meta Quest 3, implementing Teleportation, Grab Actions, Switches, and Deploying to Device. By Matt Larson.
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress, bookmark, personalise your learner profile and more!
Create accountAlready a member of Kodeco? Sign in
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress, bookmark, personalise your learner profile and more!
Create accountAlready a member of Kodeco? Sign in
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress, bookmark, personalise your learner profile and more!
Create accountAlready a member of Kodeco? Sign in
Contents
Developing for the Meta Quest 3 with Unreal Engine 5
30 mins
Open Sesame
The variable in the Gate_BP, named isOpen, sets if the gate has been opened. This provides a way to now hook the action of the switch you created earlier to affect the gate being opened or closed.
Open again, the Lever_BP in the Blueprint editor. You will now modify this blueprint to control the state of the gate after the player’s interaction.
- First, create a variable in the blueprint, and make this a reference to an object of type Gate BP. This will let you wire in an instance of a Gate_BP to an in-game instance of the Lever_BP. Under the Details panel, enable Instance Editable to allow this variable to assigned to a target in-game.
- Now, drag this variable into the event graph. Choose to make this a Get Gate BP node.
- Drag from the output node of Get Gate BP and create a function Is Valid node, to check if the blueprint instance has been assigned to a valid Gate BP.
- From the query of Is Valid, add a Branch node. At this point, you should have elements similar to the below:
- Break the existing link from Play Animation to Set Switch On node by right-clicking at the arrow and selecting Break This Link. Then, rearrange the connections from the nodes, so that the exec output from Play Animation feeds into the branch, and that the setting of the Switch state occurs afterwards.
- Drag the Gate_BP variable into the event graph as another Get Gate BP node near the Set Switch On node.
- Now, drag from the output node of Gate BP to add a Set Is Open node that targets the Gate BP.
- Finally connect the exec output and value output of the Set Switch On node as the inputs of the Set Open node. This will carry over the boolean state from the switch into the Gate BP to open or close the gate.
This is a good point to Compile and Save this blueprint. If there are any errors, compare to the overall blueprint below to adjust:
Drag the Lever_BP into the scene and place this on the wall near the potion table. Transform values, set in the Details panel of Location X:30.0, Y:1250.0, Z:150
, and Rotation of Z:-45.0
will position it nicely.
Next, drag the Gate_BP and connect this instance into the existing Lever_BP on the wall as a target to affect. Again, values for Location X:260.0, Y:1330.0, and Z:20.0
, with Rotation of Z:-90.0
will fit it in the path. Also adjust the scale as X:1.5, Y:1.5, and Z:1.5
to completely fill the gate.
Assign the Gate_BP as a target for the Lever_BP instance:
After setting this in the level, you can once again give it a test. Press the Play this level in VR button and try the switch!
Treasure Time
You now have the tools needed to quickly generate interactive Blueprints for VR games!
This tutorial concludes with a Blueprint containing static mesh components for a treasure chest — by following the steps below — to build the player interaction:
- Start by opening the TreasureChest_BP in the Blueprint editor. Notice on the left side, in the Components tab, that there exists a DefaultSceneRoot with a rotation_axis and two Static Mesh components for the Chest_ChestTop and Chest_ChestBottom.
- First, you’ll need to add a collision and handle events in the Event Graph. Under the Components tab, add a Box Collision below the DefaultSceneRoot and re-center the box outline by setting the Transform Location values as
X:20.0, Y:145.0, and Z:60
and Scale ofX:1.5, Y:1.5, Z.1.5
to cover the chest. - Now, switch the Event Graph tab of the Blueprint. Right click on the Box collision and choose to Add Event ▸ On Component Begin Overlap.
- Underneath Variables, add a Boolean variable isOpen.
- You’ll need to find collisions with the VRPawn to change the object state to isOpen =
True
. To do so, drag from the output of the On Component Begin Overlap node you just added, and add a Get All Actors of Class. Set the Actor Class to match VRPawn. - Drag the output from this to add a Set Is Open node and check the box on Is Open to set to true.
- Next, drag from the Set Is Open node to add a Play Sound at Location. Select for a sound the ChestOpening sound wave. The nodes should look as below:
- You need to queue the isOpen state to control the animation opening up the Chest_ChestTop component. Find some real estate on the Event Graph above the nodes you just created, then right-click on the Event Graph and choose to Add Timeline and name this Chest_Animate. This will be the Timeline node that will animate the chest top rotating open.
- Double-click on the Chest_Animate node to open a separate tab in the editor. Add a Float Track and name it Open_Chest_Timeline.
- Now you need to add two time points on the graph. Right-click on the graph and choose to add a key. Set this key to
Time: 0.0
and set theValue: 0.0
. Add a second key withTime: 3.0
andValue: 90.0
. This will drive a change in the angle of the chest lid over 3 seconds, from 0 degrees to 90 degrees open.
- Now, return to the Event Graph and drag from the Open Chest Timeline pin of Chest_Animate to create a new node that is a Make Rotator. Remove the path to the Make Rotator and switch it to be connected to the Y (Pitch) input. Break the link to the X (Roll) to remove the default connection.
- Drag from the output pin of Return Value to add a Set Relative Rotation (rotation_axis) node on the graph. Note that you are choosing to apply the relative rotation on the rotation axis that is the parent of the chest lid.
- A couple of connections remain to finish up the Blueprint. First, connect the Update pin to the input arrow of the Set Relative Rotation. This will pass through the time step changes and drive the animating of the chest lid opening. This block should look as below:
- You only want this animation to occur when the player has opened the lid, so you will need to add a branch logic between the source Event Tick and the Chest_Animate timeline node. Drag from the output arrow pin on Event Tick and choose the Branch node, under the Flow Control section.
- Drag your variable IsOpen onto the graph before the Branch, make this a Get Is Open node, and connect it to your input Condition pin on the Branch.
- Last, connect the True result into the Chest_Animate Play pin. This completes the Blueprint, where the collision with the player controller sets a state and activates an effect of rotating open the treasure chest!
At the end of this section, you will have completed the TreasureChest_BP Blueprint, similar to the graph shown here:
Compile and Save your work on the Blueprint.
Find this TreasureChest_BP Actor in your Content Drawer and drag it into the level at the final room. Set its Location as X:320.0, Y:3000.0, Z:40
and Rotation as Z:-90
to have this rotated and facing towards the room entrance.
Save your level and give it a try in VR Preview.
This concludes the tutorial for building VR applications in Unreal Engine 5!