YTread Logo
YTread Logo

How to Make VR Games in 2022 - Updated Unity VR Tutorial

How to Make VR Games in 2022 - Updated Unity VR Tutorial
You made it to

2022

. And you're  interested in starting VR development. And today's video I'm going to show you how to set  up in

Unity

a brand new VR project, we're going to   go through the basic setup, we're going to talk  about how to add in locomotion. So teleporting   and just doing continuous move, and then also  a little bit of very basic intractable stuff.   And at the very end, I'll show you where you can  download a template thanks to one of our amazing   discord members where you can just click on it,  and it will do all of the things that I'll show   you in this video. And go ahead and start you with  a perfectly setup project. So you won't have to go   through this process every single time you start a  VR project, which is absolutely amazing. So let's   jump into it. We're in my

unity

hub. And over  on installs, you'll see that I have the latest  

unity

version installed. And that is 2021. Point  2.7 f1. And you'll also notice that I have Android   build support and Windows build support downloaded  something to keep in mind as you're developing   your VR apps is if you are running off of a Mac  OS or a Linux OS, you are not going to be able to   play test your game or app or whatever you're  building through

unity

, you're gonna have to run   a build to the Android device that you're building  for, and test that way. So it takes a little bit   longer. If...
how to make vr games in 2022   updated unity vr tutorial
you're using a Linux or a Mac device.  With Windows, it's super easy. As long as your   device is plugged into the computer, you can test  right there. And to get these modules installed,   all you need to do is click on these three dots,  add modules, and then

make

sure that Android build   support is downloaded. So this is for standalone  specific headsets. And Windows build support is   needed for the PC headsets. So let's jump into  projects and start with a brand new one. So I'm   going to choose again 2021 point 2.7 F one is  the latest

unity

version.

2022

is still in beta.   So that's why I'm not talking about that one  right now. And then you're given a VR template   from

unity

. But the problem with this one is it  doesn't have the XR Interaction Toolkit in it. So   if you start with this one, you're going to have  to go through and change a whole bunch of settings   anyway. So I usually just like to start fresh down  in the description, you can grab the link to the   template that our comm

unity

has made for VR, which  has the XR Interaction Toolkit and everything you   need already built up for it. So let's start with  a 3d project. And here we go brand new project.   First thing we need to do is set up a bunch of  settings so that when you try to run your program   and actually goes to the headset instead of just  trying to play normally. So let's go up to Edit   and project...
how to make vr games in 2022   updated unity vr tutorial
settings. And then all the way down  to the bottom XR plugin management and install XR   plugin management. This is the system that kind of  does all the passthru stuff of between, you know a   normal, all the

Unity

things and XR and you'll see  that I have an Oculus option, an open XR option   and a

unity

mock HMD option. These three are  packages, and most headsets are moving towards an   open XR type package, which basically just says,  Okay, I can give one input. And it will translate   it from a whole bunch of different headsets and  controllers and everything because they all have   different buttons and whatnot. So open XR tries to  standardize all of the software. Essentially, it's   kind of like a middle layer that helps translate  between

unity

and all of the headsets. So instead   of having plugins for Oculus and Steam VR, and you  know, whatever other standalone headsets come out,   we just have open XR, and that kind of covers all  of them. So I'm going to check open XR, and it's   going to download a package into my

Unity

project,  you'll notice that I'm in the PC tab as well keep   in mind that all of the boxes you check over here  are going to be PC specific. When you download   open XR, it's going to automatically change your  input mode from the old input system that

unity

   was using to their new input system. So it's just  going to prompt you for that. So just click Yes,   and...
how to make vr games in 2022   updated unity vr tutorial
it's going to restart your

unity

project.  When it comes back up. You'll notice that open   XR is now checked in you have a warning symbol  right next to it. And if you hover over it,   it says your project has some settings that are  incompatible with open XR. So if we click on the   warning symbol, it will give us information for  every issue that we have in our current project.   And right now we only have one issue and that is  we need to add an interaction profile. So what   headsets are going to use. So if I click edit,  that will bring me to this page, which I can just   get to by clicking over on the side and open XR.  So we have a new open XR page here you'll see that   we have interaction profiles that are empty and  an interaction profile is really just what kind of   headset controllers are we going to end up using.  So Oculus Touch is the obvious choice. Also,   if you're building for a valve index, you want  to add that in also the HTC Vive as a controller   profile. So you'll just want to

make

sure you have  all of these included of controllers that you're   planning on using for your particular application.  Something else to keep in mind on this page   is the render mode so some people will have issues  with error when you're running your project,   it will only display in one eye. And that can be  fixed by swapping the render mode from single pass   instantiated, which essentially just...
takes one  picture of your scene, and then duplicate it and   puts that picture in both eyes, or what we can  do multipass, which means it basically does to   render calls. So one render call for one eye and  one render call for the other eye and then puts   them together, then that is a little better for  VR, as far as visuals go and everything, but it   requires a little more performance, because you're  essentially rendering your application twice,   one for each shot. And we also want to set up  the Android version for all of this as well.   So go back to XR plug in management, and then  we're going to click on the Android tab. If you   don't see the Android tab, that means you don't  have the Android module installed. So you need   to go back to your

unity

hub and add the module  to whatever version of

Unity

you have installed.   And for this one, we're actually going to choose  Oculus, because for some reason, inside of the   Oculus quest using a standalone app, when you try  to run an app via open XR, it plays it in like a   theater mode. So the game is actually in 2d, and  you're sitting in your Oculus Home environment,   it's very strange. And the simple fix for that is  just swapping your plugin provider over to Oculus.   And as new headsets come out that are not Oculus,  you'll want to swap over to open XR as well. And   so you'll just have to run builds for both, it'll  be kind of...
annoying, but you just have to uncheck   Oculus and recheck open XR to run to anything  that's not an Oculus headset that is standalone.   So this Android tab is for any headsets that  are going to run your application stand alone,   not using a PC. And you'll see that we also got an  Oculus page here. And Oculus by default is set to   multipass. You can also set your target devices in  here as well. So we automatically have the quest   and quest to targeted if your application is not  going to be able to be run on quest because it's a   little more performance, you might want to uncheck  this, just to

make

sure it doesn't get installed   on someone's quest and you know, just not work and  then you get bad reviews. So that's all we need   out of the project settings right now we will come  back to this but at the moment, we are set. And if   we go back into our Scene view, you'll also notice  in the Project window, we have a new XR folder,   which just has basic settings and stuff. Alright,  so now we have XR so now

unity

can can communicate   with our headset. But how do we know what the  headset is saying? How do we translate those   inputs into actions in our game. And to do that  we use the XR Interaction Toolkit, we can download   that via the package manager. So let's go to  Window Package Manager. And you'll see currently   we are inside of packages in project and you'll  see that the...
open XR plugin is in here because   we added that via the Settings and also the XR  plugin management package is in here as well.   And so in order to download the XR Interaction  Toolkit you use to be able to go to

unity

registry   and as long as preview packages were enabled, so  going to this advanced cog here, clicking advanced   package manager settings, enable pre release  packages tick that box say I understand that these   are in pre release and not fully released yet and  that used to

make

all of the preview packages show   up inside of the package manager. But no longer  does. For some reason,

Unity

just

updated

their   package manager and does different things.  Even inside of VR. If we look inside of there,   we only have Oculus XR and open XR which we have  both of them installed in our project already. So the new way to add the XR Interaction Toolkit  is going up to this plus icon up here in the top   left corner, and then going down to add package  from get URL and then it'll allow us to type in a   URL and that URL is calm colm.

unity

.xr interaction  toolkit hit enter and it will automatically   add in the XR Interaction Toolkit. It's like  you just have to know the secret word. Also,   the XR Interaction Toolkit recently got a major  update. So if you have a project that uses the 1.0   version, you will need to

make

a backup or just  not upgrade your XR Interaction Toolkit. While   you're building on your...
project, this new version  is 2.0. And it changes some things renamed a lot   of things. So it will break your project if you  are upgrading from 1.0. And that is the reason   for this pop up. And so if you have an empty  project like we do, or already have a backup are   not afraid of, you know, going through and fixing  some things just say I made a backup and go ahead   and add this. And now we have the XR Interaction  Toolkit which will give us a lot of interactions   that are pre setup for us, which is super nice.  This was recently

updated

on December 20 2021. So   this is a very new update. Also, we will want to  download the sample package that it gives us. So   default input action so just expand the samples  drop down and click on Import next to default   input actions. This is going to set up a lot of  the input actions that we're going to end up using   and it's nice because it'll just you know, pre  configure all of it in the in unities new input   system which is super helpful saves us a lot of  time and then back in our main screen here you'll   see that we now have a couple more folders so we  have XR array and we have the samples package XR   is just the XR Interaction Toolkit and sample  OLS is the sample inputs that we installed.   So just navigate down to the bottom folder,  there's a lot of folders this gives us five   pre setup input action scripts. So this one is for  continuous move this...
one is for continuous turn,   this one is your left controller, this one is  right controller and you also have the snap turn   provider. All of these are just actions based on  those particular configurations, we want to add   all of these to our presets. So there's buttons at  the top of each one. So just go through and click   all of those to add the presets and we also get a  pre setup input schematic as well. So you'll see   we have the head mounted display the left hand  and right hand which have different actions so   activate is pushing the trigger and we have select  which is pressing the grip those are the two main   ones. And you also have a bunch of teleporting  and rotating and tracking type things in here.   That was one more setting we need to do and then  we can start adding things to our scene finally.   So let's go back up to edit and Project Settings  and then over here on the left side we'll want   to go to preset manager and you'll see that all  the presets that we just added will be here so   you should have five total and on the presets  that are the left and right hand controllers   for some reason when you add these it does not  differentiate between left hand or right hand   so you have to add left and right into the filter  on the appropriate one. So just type in the word   left and right capitalization doesn't matter on  to these particular filters and everything should   be set up...
settings wise now so in our scene, let's  go ahead and set up a very basic scene for you to   get up and running with first I'm going to add a  plane onto the ground all this the ground and then   right click and you'll see we have an XR section  here and if you installed everything correctly,   you should see all of these options here and they  may change a little bit when

unity

updates things   because they are always continuously updating the  XR stuff so if something does not work for you,   they probably

updated

something so just join the  discord and ask questions and we can help you   out so we've got a lot of stuff in here it used  to be called the XR rig action based in which   has now been

updated

to the XR origin action  based in this is your full setup controller.   So we're going to find XR origin action based  action base is important because action based   also has your controllers in it XR origin is just  the head just your head mounted display. So XR   action based want to add that to our scene, it's  going to add an XR origin and an XR interaction   manager on the interaction manager, we want  to add a component so we're on the inspector,   we're going to add input action manager,  and we want to add the action assets that   we downloaded from the samples. So I'm just gonna  hit this plus sign and then click on the dot. And   the only option we have is the SRI default  input...
action. So I'm going to add that one,   and that is all set up. And then we click on  XR origin, you'll see that they have removed   the green box that used to be on the XR rig.  But you can see the camera in which direction   it's facing. It always goes with the blue arrow,  and then they have renamed the script from XR rig to XR origin. So that's one of the breaking  changes from updating from 1.0 to 2.0. And then   inside of the origin, you have a camera offset.  So that's how offset you are from the floor.   This is

updated

automatically. So don't move this.  And then you have the main camera, the left hand   controller and the right hand controller, you  see that the actions are preset up as well. So   just

make

sure that the right hand has right hand  actions and the left hand has left hand actions.   And if you see references in all of these,  that means you set up the presets correctly.   If you don't see presets in here, or you have  left hand things on both are and things on both   just delete your XR origin from your hierarchy.  And then go through

make

sure you added all   the presets correctly and added the left and  right hand filters and then re add your origin   and it should set everything up correctly.  So now let's run it. So if you have a PC,   this does not work on Mac or Linux at the current  time, you can hit this play button in here

make

   sure that your quest if you're using...
a quest  is in link mode, if you're not using a quest,   just

make

sure that your headset is attached  and recognized by your computer and turned   on and all that and then when you hit play, it  should run your scene. Also one little trick,   I like to run the cable or my headset through this  back little loop on the back of the quest and then   plug it in. And that kind of helps the cable from  you know all the weight of the cable resting on   and kind of trying to bend it. So just run it  right through the back of the headset there.   Little little tip. You also want to

make

sure  you allow USB debugging on your device. And then   we can hit play you should be in the scene and  you should have two lasers that move with your   controllers. So as I move my head around, the  world stays in place and I can move controllers   and they both move separately and I have one for  each. congratulations you have successfully made   your own VR app but you can't do much. So first  let's get you moving around. So we want to add   a locomotion system in the The hierarchy we're  going to right click Go to XR again and then add a   locomotion system. Also action based everything's  action based if you see something that's device   based that's using the old input system is going  to be

updated

by adding a locomotion system,   you'll see that we have a locomotion script in  here, the transform doesn't matter...
where it is,   this is just a global component locomotion script,  which will automatically find your XR origin. So   you don't necessarily need to drag and drop  that over here, but you can if you want to,   we have a teleportation provider. So this is  if you're using teleportation, specifically,   then this can be on and then we have a snap turn  provider already set up and you'll see that the   actions in here are already configured because we  added that preset and then in order to teleport,   there's one more ingredient you need to do.  And that is you can either there's two things,   you can either right click in the hierarchy, go to  XR, and then teleportation area. And that will add   in let me turn off the ground. And that will add  in a little plane with a teleportation area script   on it. This allows you to move around anywhere  on this plane going to turn that one off,   turn our ground back on, or you could just add the  teleportation area to you know, whatever you want,   the teleportation anchor that you saw, is being  able to move to one specific spot. So that's like   if you have a bunch of seats in an auditorium  and you don't want people to like you know,   kind of sit in the middle of seats, then you have  a teleportation anchor on each seat. And then   when you teleport to that particular spot, you  can't teleport like you know, in between seats,   if that

make

s sense. And it...
teleportation  area allows you to teleport anywhere   on that area. Since our red lasers turn white  when they're pointing at something that we want   to click on and the ground is white, I'm  going to change the ground materials. So I'm going to right click on assets create a folder  called materials, and then right click on that   create and then a material and this is going to  be called Ground mat. And we'll choose kind of   a grayish color and

make

sure you drag and drop it  onto the ground. So now if we hit play go in here.   All we did was add a teleportation area to the  ground and a locomotion system to our scene. And   now when I press the grip button, I can move  around on on the ground. And I can also turn   by Moving the thumbstick of either of  my controllers. So left one and right   one allow me to snap turn, what if you're going  for a more realistic kind of movement. Let's go   back to the locomotion system. And I'm going to  uncheck the teleportation provider component and   the snap turn provider collapse both of those 

make

sure you keep the locomotion system   on and we're going to add a continuous move,

make

  sure that you use the action based one. And then   we also want to add a continuous turn also action  based and you'll see both of these have a left   hand and right hand option. And a continuous  move will allow you to move around like it's a   first person shooter...
game. This causes motion  sickness, so it is good to have both options   in your game when you're making one. Now there  is one change you need to

make

after you add   both of these and that is that both thumbsticks  are controlling both actions, which is not going   to be very good. So you need to

make

sure you  designate which one is controlling which action.   And usually for most

games

, you move around with  your left thumb stick and you turn with your right   thumb stick so

make

sure continuous move has left  hand checked and right hand unchecked and then the   opposite for continuous turn

make

sure that the  left hand is unchecked and right hand is checked.   That way you move with your left turn with your  right so now just by adding those two components   and turning off the other, if we hit play, I can  still point at the ground or my laser still think   it's a valid teleportation area because it didn't  turn the turret teleportation area component off.   But if I tried to teleport with my grip there,  I don't move I don't do anything, I have to   move around with my thumb stick and the speed  setting can be changed in the component itself.   And then I could turn around with my right thumb  stick and this is a continuous turn. So nice and   smooth. Also very motion sick if you are not used  to VR, and you can get used to motion sickness. So   like you like goes away after you do VR enough.  So stay...
strong, you can get over it. Alright,   we're getting to the end of that

tutorial

, I want  to show you two more things. One of them is how to   add in grabbing directable. So how do you pick  things up. And then the second thing is how to   download and install the template that basically  has all this setup. So when you start projects,   you just click on I want that template and  it sets all of this up for you. So let's   grab something. So I'm going to right click in  the hierarchy, go to 3d objects and create a   cube on the Transform. I'm going to reset that  back to the center. And we want to scale that down   to something like point two issues good. Also,  there's a new locking scale. So now if you scale   one, it scales all of them which is super nice.  And then let's kind of drop this in front of us.   And in order to pick this box up. All we need  to do is add one component and that is the grab   intractable that will automatically add on a  rigid body and if you want it to be as smooth   as possible, you want to change the collision  detection to continuous dynamic because you'll   be picking this up and moving it around likely and  growing it so it's going to be moving quickly and   then we have the grab interruptible component  and again for the smoothing type thing we went   to smooth position and smooth rotation as well,  those are not turned on by default because it's   a little...
more performance intensive. And then  here is also where you can specify if you want   instantaneous movement, which means that every  time you move your hand, the object basically   just gets teleported to the next spot for that  frame there is kinematic which it takes velocity   into account. So it kind of slowly moves it in  instead of just teleporting it. Or you can do   pure velocity tracking, so you can't move it  through walls or whatever, which is, you know,   a more realistic kind of movement. So I usually  go with velocity tracking. So let's play that. So we had, all we did was add the cube, add the  grab interactable and then change a few set. And   now I can point at the cube, my laser pointers are  still pointing up turning up as white. And then I   can grab press the grip button, and it picks the  cube up. And you'll see that I can turn with when   I turn my hand and I can throw it as normal  physics applied to it. And as long as I'm in   range of my laser pointers, I can grab it again  and throw it normally there is one issue though,   is when I grab it, and I move my thumb stick, so  I'm walking, but I'm also moving the cube around   as I'm walking around, which is super annoying,  and kind of a weird default thing that they added.   And I'm not quite sure why they added this in. But  it's quite odd and very annoying. So if you run   into that issue, all you have to do is go to the ...
XR origin and then on the left hand and right hand   controller, so I'm going to hold down the control  button on my keyboard and click the other one. So   now I have both selected and then we want to not  the XR controller but the RE interact or which is   allowing you to grab this cue we want to uncheck  anchor control anchor controls what was allowing   you to move the cube with your thumb stick, which  might be good for some

games

, but for most

games

   that I can think of, we want to just leave that  unchecked. So if the object you're holding is   moving, when you're moving, just uncheck anchor  control. And there we go. You can move around,   you can pick up things, you can throw things, you  have a pretty functional VR app there at least   a good start, if you're running off of a PC, all  you have to do is hit play like I have been doing   to test your application. If you're running off of  a Mac or a Linux device, you'll want to go up to   File Build Settings,

make

sure you add the open  scene that you want to build and then swap over   to Android,

make

sure your device is plugged in,  switch your platform over to Android and then   build and run to your device. It will take a few  minutes to build every single time, which is kind   of annoying and why I recommend using a PC for  development. But it can be done you'll just have   to build and run every time you want to test for a  Mac or Linux...
Device. All the settings we have set   up in here will allow you to run to the Android  devices. And this is also how you share the game   with your friends to so you run a build and then  send the dot apk file or the whole folder with   the dot exe file. If you do a Windows build to  all your friends in order to play your game, no,   let's add that template. So you don't  really have to do this anymore. You can just   open up a new project and everything be nicely  set up for you. So there's a link down in the   description. I'm going to do my best to

make

sure  that link stays

updated

. If

unity

ends up updating   to a new version don't just come back to this  video and there'll be a link down the description   and hopefully that link will be

updated

if it's  not just ping me on Discord. And if you're not   in the discord join the discord because that's the  whole reason that this template came about because   we have an awesome discord comm

unity

. It's super  fun, we answer any dev help questions, anything   that you are struggling with. Or if you just want  to share your project that you're working on,   join the discord. It's super fun. So there is a  GitHub link down in description totally free for   this template. And that will bring you to this  particular page and you will want to download   this dot tgz file, click on it, add it to your  downloads and then on your PC will want to...
go or   your device you'll want to navigate to your

unity

  folder in like the Program Files or I'm not quite   sure what the equivalent for Mac is. But on PC it  is Program Files and then

Unity

will want to go to   hub editor and then choose the particular version.  You want to download this template for this one.   As of right now I know works for 2021 point 2.7  F one and then we'll go into the editor folder   data folder, Resources folder, package manager  folder and project templates. And here is where   you'll want to paste your dot tgz file. So  we'll go back to downloads cut this file,   click the back button to go back to the folder  we're just and paste it now you'll need to restart  

unity

hub so it is usually hidden. Even if you  have it closed here it's going to be hidden in   your toolbars. So

make

sure you quit

unity

hubs  right click Quit

unity

hub. And then let's open   that back up. And let's

make

a new project new  use the version and here we go. We have our VR   template and I'm just going to call this new 

unity

project because I don't care. And here   we go. Here's our template project. So it's going  to start out with a basic seen that just has an   origin and interaction manager but you'll see that  the input action manager is all set up we have   samples already installed. If we go to the project  settings you'll see that we have all of our  ...
resets are already in here and all of the settings  are already up to date multipass is already being   used. Everything is all set up in this template,  we are going to do our best to

make

sure this   stays

updated

for everyone. And I really hope  this video helped if you have any more questions   or just want to hang out or play some

games

with  me or whatever, then join the discord because it   is super fun. We are planning on doing a  game jam closer to the end of this month that I will be announcing shortly. So stay tuned  for that if you want to get a private meeting with   me every month or you want access to the source  code of any of my projects, then feel free to   support me on Patreon. I really appreciate  everyone who is continuously supporting me   it's been super nice. And in the meantime, in the  comments down below let me know what projects you   guys are planning on making for VR or what other 

tutorial

s or videos you want me to

make

. I am   super excited to you know continue on this journey  and I'm going to keep making up to date videos.   If something in this video goes out of date check  in the comments. It's probably answered down there   or in the discord or I'll be making another  update video shortly most likely if

unity

keeps   changing things the way they do. Anyway, thanks  for watching. I'll see you in the next video.