How to Create a VR Wrist Pause Menu

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey everyone this is Major Batman in Lincoln studios here to show you how to set up an VR rig with a working pause menu notice how he paused these buttons not work so let's show you how I did it first step is to open up Unity Hub okay so we're going to create a new project and we're going to utilize the 2021.3.7 LTS this template we're going to utilize is the VR template and we can download this and then let's name this and create the project first thing you're presented with is this welcome screen which tells you to go into the edit project settings and select your platform so we'll do just that edit project settings go to XR plugin management and you can select openxr or Oculus I usually utilize my Oculus Quest 2 so I usually pick the Oculus so that allows me to air link directly into unity and test out my Solutions however I've ran into issues during the recent game Jam where when you're utilizing the pcvr that sometimes it doesn't work for other devices in our sample scene we have an XR rig a plane and a directional light it's kind of cool has a little like 3D grid on it which is kind of neat and in the XR rig we have a few things we have the camera right controller left controller and honestly at this point it it doesn't really matter because what we're going to do is we're going to utilize something a little different now you can use this but I like the XR interaction toolkit framework and so that's what we're going to work on so let's just delete that all right first up we are we go to our package manager we're going to the unity registry we're going to click the little Advanced icon Advanced project settings and make sure we enable pre-release packages I know how to click understand now on this you'll see some pre-release packages here [Music] but the one we're looking for Isn't So once we enable the preview packages if you're utilizing 2021.3.7 or earlier you might not find it and we'll have to add a by name and I'll show you how to do that the reason for this actually I don't necessarily know the reason for this but I did create a a bug and I reported it and it is fixed in later versions so it's kind of cool that it's being fixed um so if you do find bugs feel free to bug report them it eventually does get fixed I did report this in April and in 2021.8 it is now available as you can see here you can install it normally so in order to install the XR interaction toolkit we need to add a package by name so we'll copy the package name com.unity.xr dot interaction toolkit and we'll add it in unity add package by name and we can version do the version as 2.0 .3 click add [Music] kept an extra space for me so delete that let's try again [Music] and now it's there you can import it and then go to the samples and then also import these starter assets so we'll right click in the scene go down to XR we're going to add XR origin action based have you seen previous videos you might have heard it being called an XR rig it is now changed to an XR origin so that's this is the one we'll select once we do that we want to then right click the transform and click reset so that it's zeroed out in our space and you'll see automatically it also creates our XR interaction manager and then we have our XR rig now called XR origin and if we open this up you hold alt it's pretty simple we have the extra origin our camera offset our main camera our left hand controller and our right hand controller okay so what the next thing to do is we go down to our starter assets and if you didn't get the starter assets you can you can grab that from the XR interaction toolkit and just importing the starter assets so from there it creates the starter assets and what we'll do let me show you what which one to do we grab our left hand controller we take the XR default left our left controller we just bring it over there we do the same thing to the right controller just drag and drop pretty simple the left hand controller has an XR controller an XR Ray interactor and a line renderer and an XR interactor line visual this is what the line would look like and you can adjust this whether it's a long wider or the colors what is going to hit stuff like that even if there's a reticle your XR Ray interactor is what it's going to interact with and what you want to do when it interacts with things and then this is going to be the buttons in addition to our model prefab which we'll Import in just a little bit now if we open it up we should be able to move around a controller but we really don't see anything there's no model attached underneath this so now that we have the controller set up so that they have tracking stage they'll get the right buttons enabled and stuff like that uh let's set up our extra origin to move okay so from the XR origin what we're going to do is we're going to add a few components the first one being a Locomotion system this allows you to move right Locomotion move and we're just going to drag the xor origin over we don't have to do that I believe it automatically works but it's good to just make sure all your all your dependencies are lined up next we're going to add an input action manager [Music] so this allows us to do particular actions so the first thing we'll add one to this list and we're going to grab the XR default input actions from our starter assets and bring that over you could also click this little Dot and there's only one in our area so we can just grab that all right next we want to have a continuous move provider on the left right so we want to use the left control stick analog stick to be able to move around in the Z and the X space so we're going to continuous move provider action based and so The Locomotion system is up here and we'll move that down we can adjust the speed as well [Music] um too much you're going to start to get into little like VR sickness type stuff so don't mess with it too much but uh you you can definitely change this so for example you could make this so when you push for further it moves faster so you can work on that as well all right and then so at the moment it's created but it's not tied to anything so let's use a reference to tie it to her left hand and we can use input action reference which has all of these and we want to use Locomotion move on the left hand XR left hand Locomotion move and that should allow you to move with your left hand alright and with the right hand we want the analog stick to allow us to to to snap turn I like Snap turns myself but you could also change it to a continuous turn as well so you'd snap turn provider is one way or continuous Term Provider action base so I use a snap term Locomotion system again drag your Locomotion system down turn them out I think 45 is a little too much I kind of like 30 um as kind of a way to get a little bit in between those so and then enable turn left right allows you to do both ways and enable turn around means if you press backwards on the stick it allows you to just snap and turn around immediately I use this in a recent VR game jam it worked pretty well um so I think it's a good way to just quickly turn around in VR space without actually having to physically turn around all right so because we have it on the left hand already for the continuous move provider we then want on the snap turn to be on the right hand and so we're going to click this little dot we're going to scroll down to the right hand Locomotion turn [Music] all right next we'll import a package I've had this package for a little bit um it's it's freely available but I'll include a link down below so it's freely available from Oculus just the free Oculus hands that are included um they are just oriented right for the Oculus Quest and so I'll include that down below in the description so the issue is the if you see that the hands are pink the material isn't quite lined up so I just change the Shader to a standard and it will work now all right so when we go to the left hand controller and go down here under XR controller there's a model prefab we can just grab the prefab and bring it over and we do the same to the right hand controller with the right hand model now at the moment these aren't configured to move when you press any buttons but just having hands adds a lot to the VR space and to do this quickly it works well so I think that's enough for this part so let's test it out I'm grabbing my Oculus Quest 2 headset I'm opening up the Oculus air link which connects to my PC over Wi-Fi open up my primary monitor and then press play on the unity editor if that's all you wanted to see please give me a like And subscribe I really appreciate it I'm going to take this a little further and show you how to get make a pause menu show up on your wrist so that you can pause the game restart it exit it and use that option I like to put it on the left hand because I am right-handed Right Use the right hand to kind of point so what we're going to go is so we're going to click on the left hand controller right-click go to XR and add a UI canvas so the nice part about this is it automatically adds this event system which includes this xrui input module and that's needed for it to kind of work and Target see here [Music] set in World space we're gonna add two buttons [Music] and we'll import TMP Essentials we'll add one more button on the canvas element we are going to add a vertical layer group so what that means is it puts the two buttons and makes them Stack Up you can see it there now obviously those are way too big so we're going to click this little enable constraint proportions and we're going to make it point zero one [Music] we only need to do it on one [Music] and so that's a bit smaller that will actually work and then for these buttons we can just make them a little smaller so instead of the width of 160 maybe we make it a width of 100. and so that's probably a little more appropriate and if we pull it into [Music] pull it into VR this is what it'll look like pull it into VR this is what it'll look like at the fingertips so maybe we want a little smaller which which is fine and then we want it a little bit up and perhaps forward maybe would be appropriate so let's play with those numbers here let's take the canvas element and we will make it go forward let's say about a half a meter and then we wanted it a little bit up so let's go with maybe 0.25 so that's a little bit up and forward and then the buttons were a little big so let's edit the text on both of these buttons [Music] to be Auto sized with a minimum of eight and a maximum of 30. let's go back to edit the buttons and let's make it a width of 60 and a height of 20. there's a little faint there but we can see that how the height of the canvas is affecting it so if we change the height here maybe a little something smaller like 50. [Music] now they're stacked on each other all right next let's change the button text so let's make this one restart and the bottom one exit so let's test that out in game one second so we have a little controller button here and then you can see that when I use my raycaster to go over these buttons it changes to White so the idea here is that I can click the button click it and you can see how it kind of shows a little highlight like I clicked the button we can mess with this a little bit more but I think for the purposes of what we want it works so let's work at the next step so let's create a c-sharp script and name this pause menu okay now that we have the menu open we want to add a few extra Library calls the first is scene management and the second is the input system all right then we want a reference to this risk canvas this risk UI that we have we'll just make it public and then finally we want to have a Boolean to determine whether or not the risk UI is active [Music] it'll start off as true and when it begins we are going to have it display the wrist UI [Music] that implies that we need to create a rest UI function and make sure to make it a void so the idea here is if the wrist UI is is active so it's currently there what are we going to do and then if it isn't what are we going to do right so if it's so the idea is like we could press it once or twice and we can make sure to get the right uh instance to occur so you press the pause button it opens the menu press the pause button again it it closes the menu so let's write that out so if the active wrist UI is true and we just write it this way it makes it a little easier but you could also do a comparison and then otherwise else if not active wrist UI then we're going to do another another set of actions so if if it is true we want to then make this wrist UI instance and set it to false so this basically turns it off and then we want to also make sure that the our reference to whether it's on or off gets set [Music] so let's do the opposite for if it's hiding what are we going to do so let's make it set it active true and then make the Boolean true as well [Music] okay that that's pretty good so far um next what we wanted to do is since this is a pause menu we wanted to actually pause it right so [Music] we're going to add in a time.time scale [Music] so we're going to add the time.time scale [Music] 0 and 1. right so the idea is if it's if the pause menu is on we know that the time scale is going to be the is already zero and then when we press it again it sets it back to one and this the opposite is true so if it's hiding we press the pause button we display the pause menu and then we're pausing the time scale kind of cool now if your game doesn't need a pot need to slow down the time scale you can just disregard this portion all right next what we want to do is we want this actually do something when we press the pause button so let's do that so we're going to create a new um a new function that just does this [Music] so we're going to call it pause button pressed and then we're going to make an input action dot callback context and we'll just have it in context this is how the new input system works but basically what is the context button of what we're sending back what's the button pressed and then what this allows us to do is use the unity editor UI to point it to this to this function and so if the context is performed right then we want it to call the display risk UI [Music] right so now we have this wrapper of this callback context being pressed the pause button and it's going to display wrist UI finally what we wanted to do is have the restart and exit game buttons let's make them actually work great so public void uh restart game and we will do c manager dot load scene Mana scene manager [Music] dot get active scene [Music] build index so this reaches in the scene manager class it finds out the current active scene with the build index number and the load scene requires a build index number so that's why we do it this way so the idea is no matter what level or world you're you're building it will get the current scene and restart that level which is which is a little helpful foreign exit game Button as well and this is a simple application.quit very easy to overlook a lot of VR games they fail to have this information or a way to really quit it without actually pressing the Oculus button then Force quitting the game which is kind of like requiring someone to press alt f4 to exit out of the game which isn't I think the appropriate manner all right so this is the code let's clean up this update here we don't need an update here and let's scroll down one more time so we have Unity engine scene management input system we have a reference to a wrist UI a public Boolean of our wrist UI at start we call it once all right so it's it's displayed first then when we press it the idea is it goes in here and sets it to false and initiates the time scale and then we have the wrapper for our callback context and then we have our two buttons so let's save this so we could put this anywhere let's put on the left hand controller because that's where the canvas lies so let's copy over the wrist UI element here and then for these buttons [Music] on click so this is a the restart button we bring the left hand controller over and then we want it to on the pause menu to restart the game and then for the other button we're going to drag over a left hand controller here as well go down to the pause menu and exit game so now both of those buttons will work the only thing missing now is the is the wrapper element all right so now that we have the pause menu set up we need the wrapper so it actually talks to our VR controller so I'm just going to go into the starter assets and we're going to right click and create and down at the very bottom is the input actions and we'll since the other one's called default input actions we'll call this custom input actions [Music] let's open that and let's click auto save just in case we don't save it we're going to create an action map you can really name this whatever I'm going to name it menu because that's what we're going to work on and then for the action we're going to make it do the menu press these are specific action maps that we can call back and that's the context that we're going to do and it's going to check to see if any of the bindings below are pressed so we're going to add a binding and I don't I haven't had much luck in this in figuring out which works what and it could be because I'm using the Oculus versus the XR but if we go to XR controller down at the bottom for specific XR controllers because I'm using the Oculus Quest and then select the start this works for me now for you you might have to go in and find and do a few different ones until you get the right one that works so it might require a little testing but for the Oculus Quest 2 with the Oculus set in the preferences the start Oculus touch controller works for me the next thing is we're going to go to the XR origin we're going to add a component called player input in it it requires an actions asset so now we have two we have the custom and the XR default we're going to use the custom because that's what we created and this chooses a default map so what is the map that we're going to use and we're going to use the menu that's the one we we decided on for the behavior instead of sending messages we want it to invoke a Unity event and this creates a UI that is very similar to like the buttons we just we just dealt with and in the menu context there is one action the menu pressed so when many pressed it's going to check to see which of the buttons that we bound to this action when they're when they are instantiated it's going to do something so we're going to add this plus and at runtime we want it to look at the left hand controller and we want it to go to the pause menu and we want to use this Dynamic callback context pause button pressed and now if you don't see that you probably didn't invoke in the library the Imp the input actions so go back and make sure that is done so we're going to select this pull it into VR this is what it'll look like so we have our hands they move I can move left and right I can move around and see him from different angles and when I pause he stops and in addition I I can turn once but I can't move around either so that's nice to know and I have my two buttons I had an extra little UI element to it to make it a little more pretty and you can click it and it restarts back from Square One the exit button won't work for this but you can see that the pause does stop and if I press it again back to normal he's moving so I hope you enjoyed this tutorial I'm major Batman link here studios please give me a like And subscribe hope you have a great day [Music] foreign [Music]
Info
Channel: Linkira Studios
Views: 4,803
Rating: undefined out of 5
Keywords: #unity3d, #gamedev, #indiedev, #learnunity, vrtutorial, pausemenu, pausemenuunity, quicktutorial, learnunity, oculusquest2, unity tutorial, xrtutorial, game development, unity3d, unity, restart game unity, pause game unity, pause button unity, vr ui unity, vr ui, vr wrist menu, unity vr tutorial, unity vr tutorial oculus quest 2, vr unity, vr unity tutorial, vr unity 2022, vr pause time, vr pause menu
Id: RLYBtpr5S8Q
Channel Id: undefined
Length: 26min 23sec (1583 seconds)
Published: Fri Aug 26 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.