well unity's been pretty busy with XR lately and while this video is not necessarily about
the new updates to the xr toolkit and interaction system i will end up going
over a few of them because they're interesting and i know some of you have been encountering
some issues when trying to get a project up and running in the newest version of unity
so let's jump into the project and i'll show you how to do sockets and then also go
through setting up a general vr project so you can see how it's done in 2021.2
so like i said you can see up here at the top i'm using unity 2021.2.6 f1 which is the newest
version at the time of this video and there have been a few changes to the plugins you need for
vr so let's go through those real quick just like any other vr project we're going to start let's
open up the window package manager and i'm going to dock that over here where the scene view goes
and then we want to navigate to packages unity registry and then you'll see one of the newest
updates is you get collections of packages based on what they're used for which is kind of helpful
so if you could look down at this vr one there are two packages that they've deemed useful the oculus
xr plugin and the open xr plugin but you can also get to them just like normal by scrolling all the
way down here and finding the xr plugin management so you can click install here or we can go up to
edit project settings dock this one up next to package manager and then if we scroll all the
way down here go to xr plugin management you can still install the plugin management there as well
and this is generally how i like to install it i'll just go to the settings and find xr plugin
management and install it and then here you're prompted with what providers you want so i usually
go with open xr open xr if you're not aware is the sdk that is the most widely used so we'll work
on the most devices at this current time and so when you download openxr you're also going to be
downloading the new unity input system and it's going to prompt you to restart your unity project
so just hit yes for this and once that loads back in you'll notice that over in player if we scroll
down to active input handling you'll see that we are now on the new system so if you're using any
of the code commands like input get key down or any of that kind of thing you're going to want to
use the old system or at least both so if you're using any of those kind of commands where it's
just input get key or on mouse down or anything like that you'll need to use both in order to use
vr but in vr you're not usually using keyboard and mice so i don't generally worry with it back in
xr plugin management we're getting a warning here next to openxr and if we click on that it's going
to say we need at least one interaction profile so we can click the edit button and that's just
going to drop us down from xr plugin management to this open xr tab and what it wants us to do is add
an interaction profile here so let's hit the plus sign and then you add whatever vr devices you want
to be able to build to so i have a valve index and an oculus touch so that's usually what i set my
projects up for i usually add the vive in here as well and then if you want to be able to build to
oculus specifically to your oculus quest you're going to want to go back to xr plugin management
and then if you have installed the android package in modules which you can find if you go to unity
hub installs and then click on the three dots here add modules and you'll want to download
android build support and the android sdk and open jdk this will allow you to build your project to
the quest specifically and any other standalone headsets that end up coming out in the next few
years so we have a pc tab which we're gonna try to always open in openxr but if we now have this
android tab which you got by adding in that module we can click on oculus here i have run
into an issue where if you check openxr here in the android tab if the application tries to open
on oculus it's just like a flat screen like you're watching a movie in vr so if you are running into
that issue just make sure you have oculus checked over in your android tab so now that our xr plugin
management is all set up we want to download one more package and this is what some of you have
been having issues with if we just like normal try to go in and add in the xr interaction toolkit
by clicking this gear icon advanced project settings and then enable pre-release packages
click i understand because pre-release packages are not officially released yet so may have bugs
go back to project manager you'll notice that it's still not there did they remove the xr interaction
toolkit no it's just hidden right now so if you want to still download the xor interaction toolkit
you're going to click on this plus sign clicks next to it and then we're going to add a package
from git url and then this is what you're going to type in it's going to be com comm dot unity
this is the package name for the interaction toolkit so just type that in click add and
then it will install the xr interaction toolkit and there it is and it may prompt you to restart
unity as well so just click i made a backup go ahead because we haven't really started doing
anything it's not going to mess anything up so now we have the xr interaction tool kit and just
like normal we're going to expand the samples drop down and import the default input actions
that's going to give us this samples folder with the xr interaction toolkit and then whatever
version it is make sure you're constantly updating your packages so if we go into package manager
you can go to packages make sure your in project packages are checked and make sure you're updating
these so any of them that have an up arrow next to it like this just make sure you periodically every
time you start a new project go through and update them and just a side note just like we added the
xr interaction toolkit all of these packages can be added manually like this and don't you
if you can't seem to find one inside of the package manager they all have a url that you
can type in to download them just keep that in mind if unity one day decides to update your the
package that you love using and it's not showing up anymore you can always manually install it now
let's set up our xr interactions so in the samples folder we want to drill all the way down to
default input actions and then we have a few presets here five to be exact and then if you
look over in the inspector panel there's a button at the top of each one of these presets and it's
add to action based continuous move provider add to turn provider add to action based controller
action based controller and snap turn provider so we're gonna go through and click all those
buttons and make sure you add all those providers this will set up your default input actions so we
don't actually have to manually go through and say this button does this and this button does
this this is all set up from the beginning for us to go ahead and jump start and use if you do
want to play around with the interactions you can double click on this one here and you have
the ability to go through and update what clicking on the grip does and what pulling the trigger does
and whatnot right now the grip press is select so you'll see grip pressed and then activate is the
trigger press now that we have all those added to their appropriate providers there's one more thing
we need to do before we can start adding things to our scene so we're going to go back into project
settings and then up in preset manager i want to find that and this is where all those presets
that we just added are going to end up so you'll be able to see all five of them here and for the
controllers the left and right controller we want to specify in the filter section right and left if
you don't do this then you'll only end up seeing one of your controllers because they're both
going to be mapped to the left hand so you need to specify this filter in order for them to be mapped
to separate hands i don't know why it's not set up by default but um this is just something you have
to do to make sure they don't map to the same hand and you only end up with one controller so now we
go back to our indoor scene right click go down to xr and there's no xr rig anymore it's an xr origin
so all the way up here at the top and we actually want to add in this xr origin action based so the
action base the the difference between xr origin and xr origin action based is if i click on
action based it's also going to give me this xr interaction manager which is what i want and on
the xr interaction manager we're going to add an input action manager click the drop down for the
action assets add in one element and then you can click on this little dot over here on the side and
just select your xri default input actions and now if we go and look at our xr origin you'll see it's
set up just like the xr rig was except you have an xr origin component instead of an xr rig component
unity's kind of updating things adding in some more features and so they decided the name change
would be good and just like normal we can look at our left and right hand controllers and just make
sure your left hand has all left hand actions and your right hand has all right hand actions
and something i usually like to do is i'll select both of them by holding down control selecting the
other one and then going to ray interactor and unchecking anchor control anchor control just
means you can move whatever object you pick up with the thumb stick so it like kind of pushes it
away and rotates it and whatnot and i don't like that because i like to move around with my thumb
sticks and so i don't like to move but then also have the object i'm holding kind of drift away
from me so uncheck anchor control and then here you can also adjust your xhar interaction line
visual if you would like so let's get to sockets how do you use sockets so i'm going to right click
create a 3d plane object and then let's install a package to make things a little more fun on
the unity asset store there is a free fantasy hammer and shield asset that we're going to use
you can just search fantasy hammer and shield on the unity asset store and this should pop up and
is free to download so i'm just going to import this we're going to use this to actually show off
sockets so i need all of these i don't need the scene though so i'm going to uncheck the scene
click import and that'll give me a folder with the hammer and shield down here in my project
window so i'm going to drag and drop the hammer end of the scene and the shield into the scene
press f to focus in on them get a little closer and then let's kind of bring them up a little bit
i think these will end up being small but it's fine one thing we need to do
for both of these objects is to add in an anchor point or a grab point attach point whatever you
want to call it we're gonna go with attach point and the attach point for the let's make sure this
is on uh local space for a hammer needs to be pointing this direction so i'm when i'm holding
it i want the forward direction of the hammer to be that direction and then the attach point
for the shield let's create a new game object is going to be back on the handle here there we go
that'll work and then we want both of these to be grabbable we want both of them to interact with
physics so i'm going to select the top of both of them hold down control select both and then let's
add in a rigid body and then if these are going to be objects that we grab we also want to make the
mesh colliders convex that way it's a little more performant when we're picking them up and moving
them around and whatnot keep in mind that this will fill in all the holes so it may make your
physics a little weird so you may want to go in and just add in a couple box colliders instead of
making the mesh collider convex and then let's add the mass let's make the mass 10 or something like
that and then let's add in a grab interactable this is for both components i'm still i still have
both selected and you'll see this is your normal grab interactable so when these are pointed at and
selected all these pre-configured values will allow me to throw it and pick it up with like
a little smoothing effect and whatnot i'm gonna check smooth position and smooth rotation for both
that'll kind of that'll fix any jittering you see when you're holding it so let's have it so i can
either pick up the shield or i can attach it to my arm like it's uh i don't know what is that called
now so let's have it so i can pick up the shield with my hand or i can just attach it to my arm and
i don't have to worry about holding it constantly so onsite on the xr origin left hand controller
start with the left hand let's create a 3d object cube and this is just going to be our hand it's
going to represent our hand so we're just going to make very small 0.1.1.1 same thing for the right
hand controller new 3d object cube and 0.1.1.1 there's also a new lock constraints button here so
if you click on this and slide these values up and down they're all locked together which is really
nice so you can't scale things out of proportion so it's a new feature i love like just seeing the
random like updates pop up it's pretty fun and then let's add in a sphere for the spot that i
can actually attach my shield so let's add a 3d object sphere and then we're going to scale this
down to 0.1 as well and then i'm going to click on the blue axis which is forward hold down control
and then go back one tick so holding down control makes you less you move in increments so 0.25
increments in this case and then for the sphere we don't want it to be an actual collider because
then your shield would just bump into it and not do anything so we want it to be a trigger and this
will actually allow us to recognize okay we have moved our object into this trigger area and thus
want to attach it to the socket and so let's add in a socket interactor and then we actually want
to be want to rotate this socket as well so let's bring up our move tool and then rotate this around
one more otherwise when we attach the shield the shield's gonna be pointing forward like through
our arm so that that's gonna be kind of weird so we have to attach it and then kind of rotate it
and this is on our left hand so maybe i'll go the other way so it's not being backwards and then i'm
going to duplicate this sphere move it down to the right hand and then rotate it all the way around
180 degrees save everything and then let's hit play and i'll show you how it works so we have
our cube here and then this is the sphere that represents where our socket interactor is and
so i can pick up my shield and i'm holding it just like normal but if i try to dock it to this sphere
here so as it enters the collision of this sphere object we get this little um holographic kind of
display that shows us where the shield is going to go and then when i let go
it just snaps to that spot and so now i have a little uh shield that's just docked and so
this is a good way you can make inventory kind of systems so you can make like thigh pouches or um
the or like the little half-life alex wrist sockets or you know over-the-shoulder kind of
boneworks style things you could do all that with these socket interactors which are super cool and
so this will work for both um but actually if you notice it works for the hammer too
but what if we don't want the hammer to be docked because that's kind of weird let's uh let's fix
that really quick it's actually a relatively new way to go about solving this issue and that is
inside of our xr socket interactor there is an interaction layer mask and so this is just a
list of all the different layers that are specific for interaction so it's not physics layers it's
not tags it's specifically for things that you can interact with in vr so we can say we want a shield
to be able to be interacted with and we can use this layer to say okay i only want a shield to be
able to be put in this particular spot so we only want a shield to be put in this particular spot so
let's go back to the sphere we say our interaction layer mask is nothing and then we're gonna check
shield same thing for the other sphere nothing and then only allow a shield and then when we click on
our shield let's go to the xr grab interactable and then the interaction layer mask for shield
is shield so uncheck well it can be default and shield so it can still interact with
everything else like a normal default interaction interactable object but it also has the layer of
shield and so now we can attach it to our socket interactor so let's hit play again and now we can
still pick up our shield and attach it to our um arm there but when we try to attach the hammer
it doesn't go which is perfect that's exactly what we want and so but our shield still works
so perfect exactly what we want and now you can imagine using this kind of thing for a lot of
different game mechanics you have a physicalized inventory system with this kind of things you have
over the shoulder sockets and rib sockets and holsters and thigh sockets and whatever you want
you just have to map it to the xr rig or you can map it to an inverse kinematic body to the
particular joints and then it's more realistic you can have a weapon locker and so each item has a
specific spot and you can do keys so you you put a key in a door you can have this little socket that
shows you that okay you're in you're inserting the key into the door and if you want a wider
area or a tighter area to be able to say where is the socket going then all you have to do is adjust
this sphere collider or box collider or whatever you want by you could let me turn this plane
off so we can see a little better so we don't necessarily need this mesh here you can disable
the mesh collider and not actually see the sphere at all so you could just remove the mesh colliders
from the sphere and you still have just this trigger area here and all you have to do to expand
the area that you need to touch in order to attach that socket is to either just press r or the or
the expansion tool over here or you can click on this handy dandy little thing and then you
are able to grab the point and just kind of drag in whatever direction you want to increase and
that will help you scale to more specific sizes if you want to have it in relation to something else
like a coat rack or a chess board you could have a lot of really tiny sockets on a chessboard which
would be really cool this is an often overlooked property but is super super powerful so i highly
consider you taking into account sockets in your vr game because it is super handy super easy to
set up and i hope me walking through the whole process here of using unity 2021.2 to actually
set everything up kind of help clear up any issues you might have been having when you set up your vr
project if you run into issues you can always leave a comment down below i am not really able
to answer all the comments anymore because the channel has just exploded here in the last year
but if you do run into a specific issue or you just want to hang out with a lot of other cool vr
developers there is a link down in the description to the discord that's where all of us hang out day
to day and you can ask your specific questions and collaborate with other artists and developers and
make some pretty cool stuff if you're interested in getting this specific project or any of the
other source code from any of my other projects consider supporting me on patreon helping me
keep putting out videos like this there are not a lot of vr developer channels so your support on
patreon really helps me to be able to continuously put out these videos so i really appreciate each
and every one of you who are supporting right now and last thing as a thank you to all of you who
have stuck to the very end i'm going to be doing a live stream this saturday more of like a ama kind
of question and answer answer your dev questions here on youtube and i'm going to be going through
how to use sockets live and just generally talking about whatever you guys want to talk about so
come hang out it's going to be uh kind of probably around noon eastern time on saturday if you're
interested in hanging out live i want to start engaging more with y'all and playing games and
doing a lot more live stream kind of stuff because i think that's a lot more personable but anyway
enough of me rambling i hope you have a great rest of your week and i'll see you in the next one
you