UnityXR Tutorial - Creating a Wrist Menu with new Input System

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey everyone this is major batman at link gear studios here to go for a unity xr tutorial on how to utilize the new unity input action systems by creating a vr wrist menu let's get started so once the project's loaded the first thing to do is we need to install the new input system go to package managers it doesn't show we want to go to the unity registry click on input system and click install once you're back you'll want to scroll down and most likely you won't see the xr interaction toolkit and in the new version it has been changed location so let's go to advanced project settings and in the new menu click enable preview package i understand exit out of there and now we see the preview packages what we want to download is the xr interaction toolkit by default it shows the 0.10 preview 7. what we want is to go down and see other versions let's install 1.0 preview 3. once that's finished click on samples and we also want to install the default input actions next up we want to go into our edit and go to project settings go to expert plugin management and install xr plugin management i'm utilizing the oculus quest 2 and i haven't tried it without the without but i believe in order to get the oculus link to work we must click this button with that out of the way the next thing we want to do is we want to create a plane for us to play with next we want to create an xr rig so if you've taken tutorials in the past there's a device space which is what it used to be and now we're moved to the action-based systems so let's pick an act room scale xr rig so we click through the left hand and the right hand has these action based controllers but it doesn't know what to do it's not really doing anything so how do we do that in the extra action in xr interaction toolkit the default input actions are here the left controller and the right controller what we want to do is click the left controller and add to action base controller default we want to do the same for the right controller now what this does is this adds adds the default actions for the xr toolkit to the specific controllers so that the left stick does certain things the right a button does certain things the right trigger etc but if we create a new external direction toolkit it's not going to tie to it and that's because we're missing this a preset so open the project settings again and go to preset manager and for the right controller we wanted to look for the right controller and for the left let's look for the left so let's delete this and let's try that one more time if we look at the left hand we now have the left hand actions for all the various buttons as well as the right hand buttons on the xr interaction toolkit we want to add the input action manager and we want to add the default input actions next we want to import the hands hand models and we can do this easily okay i've added the left and right hand skeletal low res these are our hands that we can utilize so to add the model we go to the left hand controller and you just take this and drag it there and we do the same for the right hand what we're going to do is we're going to create two transforms on these controllers to adjust the orientation of the hand so that they more readily match with the default position of your hands when you're holding the controller so for the left-hand transform what we want to do is we want to adjust the transf transform on the z to 90. for the right hand transform we want to adjust this to minus 90. so what we failed to do was actually apply these transforms so let's move this transform over so you just take this and move it here so let's try this one more time and now they seem to be set up correctly however we can't move so let's fix that so go back to the xr rig and what we're going to do is we're going to add a locomotion system and drag the xr rig to the xr rig next we're going to add a continuous move provider and we want to make it an action based continuous move right we're going to drag the xr rig as well to the system so the continuous move provider is something that allows you to move around using a joystick in like normal 3d games so you can adjust the speed you can see if gravity affects you but what we're interested is how do we make this work so if we click use reference here we now need a input action reference and when we click here we can decide which one left hand move i believe fits what we want let's add a snap turn provider action based again we need to add the xr rig as to the locomotion system we can adjust the turn amount by default it's 45 degrees and we want to attach this to the right joystick select the right hand turn so let's test this out so if i use the left joystick i should move around which you can see and if i use the right joystick i spin and these can be used in tandem while you're moving not bad for a few minutes worth of work so so far we have a moving moving rig that responds to our joystick movements i want to show you how to get this to work with your own functions your own methods to figure out what you want to do so i've created an idea to create a wrist ui so let's do this on the left-hand controller we're going to add the xr ui canvas we're going to it's already default to world space but we want to change the scale to 0.01 0.01.01 this allows it to be closer to the scale of our hand good we're going to add here we're going to add two buttons the button's a bit too big so let's adjust the button to something more manageable maybe 35 by 50. let's let's change this to exit gain it looks like we need to adjust the font size a little bit let's duplicate this button and make it a little higher let's have this do something like return to menu so idea here is we can we have a first menu that allows you to pop up and do game specific items too so let's create that script so we're going to create a new csr script and we're going to call it the risk menu all right the first thing we're going to do is we're going to use the new unity engine.input system okay so what we want this to do is it does when we press the menu button on the left controller it opens the menu and then we click a specific button it does we want what we want it to do so let's do that now first you want to add the wrist ui that's going to be displayed next we want to add a boolean that that keeps track whether or not it's active or not okay on the start we wanted to do a do the proper display so we're setting it the active component to true to begin with but then what we wanted to do is to disable it so let's create a new function called display wrist ui so let's make this public and we want to do is if the first ui is active set it to inactive and if it already is inactive set it to true we have is a script that will display the wrist ui will hide the risk ui on initial start but we want a way to call this again now most normal ways we would just select this as a button unfortunately you can't do that in the new input system what you have to do is create a wrapper for it so let's create that wrapper we'll first start off by creating a public void called menu pressed and we're going to call in a callback context from input action action dot callback context and we'll name that context this callback context allows the code to tie to the player actions if the context is performed then we want to do something and in this case we want to to call our wrist ui function and that is it that creates the wrapper and so now we're able to tie in the input system and call any function we want using a few lines of code next i'll create the code to actually run each of the buttons let me get that started so now that we have the risk menu script written let's attach it we're going to attach it to the left hand but we could really attach it anywhere i think it makes sense here since it's on the left wrist so then we want to capture the wrist ui and that's this canvas here it defaults to active okay so then we want to attach the buttons to actually do things so let's do the exit button and i want you to know how unity does this because that's the same way we're going to do the player input so the exit button you click plus here we're going to add the left hand controller and we're going to call the risk menu x again we're going to click on the menu button hit the plus sign drag the left-hand controller over call the wrist menu that's attached to it and do not display wrist but return to menu and that's what we'll need to do so if we run this these buttons will allow us to do stuff but by default once the wri once the script is run the menu will disappear and what we want to do is to be able to call that menu back let's go back to the xr rig and let's add a player input so it requires an action asset so we created player controls so we could bring that over and we want to default we wanted the map of default being the ui and what we wanted to do is instead of send messages as the default behavior we want to change it to invoke unity events we open this up and then within ui we get a callback context for the menu so what is the callback menu callback context function we want to run and that's within our wrist ui so let's bring our left hand controller over and let's add so we could just do display wrist ui but it doesn't work instead because we have the dynamic callback context performed we have this menu pressed up here and that's the one we want to select and select that one thing of note is when we go back to the one thing to know is if we open up for player controls i've also added the start on the left hand oculus touch controller and you can find that using by following these directions or you could pick the left hand and start now the reason i did that is i've run into issues with it using the menu and maybe it's not the right button maybe it's home maybe it's the menu button instead or maybe it's just a start so i haven't exactly you know i'm going to figure that out stop okay one thing of note is that the player controllers i run i ran into a small issue and i want to make sure it gets clarified and so that we can make sure it works in the player controls i had to make it look like this the menu button for the left hand xr controller as well as the start for the oculus touch controller and for some reason this allowed them to map and i believe it's supposed to work organically but for whatever reason i needed to include both in order for it to work for me and so that is it let's test it out and you can see we have two hands we can move back and forth we can move left and right back and around we can rotate and let's see if this menu works if by pressing the menu button we now get a rest menu and it disappears open shut and now we can go and we can say exit the game or return to menu and that changes the scene back to normal and there we have it we have how to use the new input action system in unity xr with a wrist menu that can be called using the callback context i hope you enjoyed this tutorial again i'm major batmanlink here studios have a great day you
Info
Channel: Linkira Studios
Views: 1,551
Rating: undefined out of 5
Keywords:
Id: fTPFK-Hkm2w
Channel Id: undefined
Length: 17min 21sec (1041 seconds)
Published: Sun Apr 18 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.