Transcript for:
Unity 6 and XR Toolkit Overview

You want to make a VR game with the most up-to-date information? Then this is the video for you. This is going to be the quick start guide to using Unity 6 and the XR Interaction Toolkit 3.0.

For my newbies, we are going to be covering the 20% that you'll need to know to get 80% of the work done in VR development. And for my veterans, we are also going to be covering all the new things that the XR Interaction Toolkit 3.0 has added. So you'll definitely want to check out the locomotion and interaction section because there are some changes there.

If it's your first time meeting me, I'm FistfulShrimp. I like to make Unity tutorials with a focus on VR, but I branch out into other areas from time to time, so it's good to meet ya. If you are just getting started and you're an absolute newbie, first thing you want to do is install Unity Hub. So all you have to do is come to this little webpage that I'll provide in the link down below, and just download Unity Hub and install it. Not too complicated, pretty self-explanatory.

Now, once you have Unity installed, this is going to be your central location where you can handle... different versions of unity that you've installed and also where you manage all of your projects that you're working on now throughout this process you'll probably be asked to make a unity account just make sure you go make a unity account after you have installed unity hub and next we're going to want to install the newest version of Unity, Unity 6. So if we go over to installs, we go to install editor, you'll see we'll have this little drop list of official releases. And you'll notice down here it has 2022, 2021 LTS, that stands for long term support. So that's going to be supported for quite a while.

So if you're building a game, you kind of want to choose long term support in Unity 6 is still technically in preview, but I'm a little impatient right now, so I made the tutorial now. So in the future, if you see long-term support for this as opposed to Unity 6 Preview, go for the long-term support. All right, go for the LTS.

But yeah, I'm just going to click install. And right here, we're going to make sure that we install both the Android build support, OpenJDK, and Android SDK, and NDK tools. Now, we're doing that because I'm assuming that you want to build out for hardware like the Quest, Quest 2, Quest 3, things like that. And that's actually Android-based. So we're going to need this if we want to develop for that product.

If you're doing something for the Vision Pro, you're probably going to have to add iOS builds and maybe a few other things. But sadly, I don't have a Vision Pro, so I can't develop for it. So I can't make a tutorial for it. If someone wants to mail me one, go ahead. Yeah, then I'll make some tutorials.

But as for now, we're just going to choose this and hit continue and agree and install. Once we've installed Unity 6, you can see the new version here. We can go over to projects, go over to new project, and we can drop this down.

and pick which Unity version we want. So you can see I have an older preview version of Unity 6, and I'm going to pick this newer one that I just installed. And you can see here we have a few templates to pick from.

And if we come down here, you actually see there is a VR template we can download and install. And you might want to consider using that in the future because it does a pretty good job now. of setting up your project automatically for VR.

But instead, I am going to choose this because I want us to go through and install all the things that we need for VR so you can kind of see what you need, what goes into it, and how these things all work together. If we just start off here and have it all built in, it's not really what we want to do. You're trying to learn here, so this is what we're going to do to learn.

One quick thing I'll mention here is you might have to pick your Unity organization. That can just be your login. You know, whatever your Unity account is, just pick that. So I'm just going to rename this Make VR Game and then hit Create Project. Once the project's been created and boots up, you will be greeted with this.

You'll see all these different windows and yours might look a little different from mine. I actually use a custom layout where I move these windows around to look like this. I have my hierarchy here. I have my inspector right there.

Project, console, the game there, and the scene. Now, as this stands right now, this is a game ready to make any 3D game that we'd like, but we want to make a VR game. So in order to do that, we're going to have to install a few packages.

The first one we're going to install is the XR Plugin Management, and this is going to handle all the plugins we need for XR development, VR development, AR development, all the developments. So if you go to Edit, Project Settings, and come down here, you can actually find it right here at the bottom. You select it and hit Install XR Plugin Management.

It's that shrimple. Now, after that, we get to choose which plug-in provider we want. And you might be asking yourself, what's a plug-in provider? And it's just how we translate to the hardware and our inputs what's going on.

So OpenXR is what I'm personally going to choose because OpenXR is a universal standard for VR. So in the future, this is going to... give us the highest probability of being able to deploy to the most headsets that we want for our game.

If you're only developing for Quest, you know, you might consider just using the Oculus, but for longevity, I'm going to choose OpenXR. Now after we have installed the plugins for OpenXR, you'll see here it'll take us to project validation, and it's a little upset that we don't have an interaction profile here. And all we can do, I mean, what we need to do here is just hit edit, and it'll take us over to the screen we need.

And this is where the OpenXR is, and it's looking for this interaction profile. And what's that? Well... that's just simply the controllers that we're trying to target so it knows which ones it needs to include so it can translate it if we are using that hardware so if you're going to target valve index you want to include their profile and you know what i'm definitely going to do oculus so i'm going to include that but add all the ones that you want you can't go wrong we're going to want to do the same over here on the android side so if we go over to android this is when we're deploying to quest so the only one i really care about there for myself is this guy right here for the oculus touch controller profile And so after that setup, well, we're pretty good with OpenXR.

We can also come to project validation just to make sure. It says that there's two more things upset here. So I'm going to hit fix all and it should go over and fix all that for us. Now, one thing I mentioned here, I did hit fix all and nothing was really happening.

But after a little bit, something updated and it corrected everything. So that looks like it's fine now. If this video has helped you out so far, consider a like because that helps me as well.

man, I have spent a ton of time making this thing. Now that we've set up our XR plugin management correctly, and we are using OpenXR, and we have our profile set, we now need to install the XR Interaction Toolkit. And one thing I will mention here is XR Interaction Toolkit is not the only toolkit out there.

And if you're wondering what a toolkit is, it's just a collection of software or tools or resources used to help developers build applications a little more effectively. So in this case, toolkits... specific for VR development.

And as I mentioned, XR Interaction Toolkit is just the toolkit provided by Unity. It's free, they're updating it, and it's constantly changing, and I just like playing around in it. But there are other ones out there. If you really want to, you can actually come over here. There's popular ones.

If you look up in the asset store, you can use Hurricane VR, which is very popular. So is Autohand. That's another very, very popular one.

See here. Yeah. And you can see the different interactions and things that you can do with it, but it does cost $80.

And well, not everyone has 80 or $90. And I'm sure it'll go on sale. If it does, you might want to consider picking this up.

But for now, we are going to use the XR Interaction Toolkit. And in order to install that, we just need to go to the package. Manager so you just go to window package manager and it should bring up that window inside the package manager We are going to go to the unity registry and we are gonna look up the XR interaction toolkit And you'll find it right there interaction toolkit three point zero point four go ahead and install once that's installed We're also gonna install some samples We're gonna get some starter assets here and this is just gonna give us a few prefabs and stuff so we don't have to build everything with our own hands because it can take a very, very long time. And it's easier to explain if we just have some starter assets.

So I'm just going to go ahead and import that. Now, after all of that has installed, we're going to want to go back to our project settings. So edit project settings and come down here and you'll see project validation. It's a little upset because the starter assets wants the interaction layer three or 31 to be set to teleport.

So we're going to do that. We're going to go ahead and press fix and have that update and we should be good there. Now with that, I'm going to minimize this screen.

I'm going to come back to this scene and we are going to look at a demo scene that they've given us and we're going to start going over the XR Interaction Toolkit or, you know, learn how to do VR development. If you come down here and go to samples, XR Interaction Toolkit 3.0 starter assets, click that folder, demo scene, double click it. You will be greeted with this, this lovely scene here with a bunch of samples and things set.

up for us and well practically you can boot this up with your headset and be ready to go. Now a few things I'm going to point out here for you so you understand what's going on. First we have the XR Origin. This is where your camera is going to be. This is where all the tracking is going to be and if we expand this out you can see this is where our controllers are.

This is where our locomotion system is. This is where the whole entire rig is the player of the game. is going to be.

And so if we click the XR origin, I'm going to run through some things here really quick. So this is what's responsible for moving our player around. And you'll see here it has a few components.

We have the XR origin itself, which has a bunch of components here. First, we have the XR origin, and this is responsible for tracking the camera and pretty much managing this entire rig setup. We have the character controller.

So this is going to determine the collider that represents our character or player. And this is also how we're going to be moving around is using transforms on the character controller. We also have an input action manager. This is what handles all our inputs.

And if we double click here on the XRI default input actions, you can see this is just what we are given for our heads tracking, our left hand controller, left hand controller for interactions, left hand controllers for locomotions. This actually can be a pretty complicated subject. I do have a few videos that I'll link down below that covers this in a little more depth, but I just wanted to point that out for you so that that's how we're able to translate and understand what are these inputs coming from these controllers and what do they mean and represent.

We also have this XR input. modality manager. And this is just a fancy thing that allows us from switching between hand tracking and then using our controllers and tracking with those instead.

We also have a few demo scenes here that I'm going to cover in a few moments. We have grab interactables, objects that we can grab. We have poke interactors. So like buttons, we'll press down and it will shoot some particle effects.

We have a far grab interactor. So these are going to be objects that we can grab from afar as opposed to just up close, which is nice because sometimes you drop things on the ground in VR and you don't want to have to have the player just crowd like bend over and pick things up all the time. It's that's exhausting. So far grab interactor. And then we have some UI samples, some ladders and some teleportation anchors, which I'm going to explain in a moment.

but that is our sample scene. Now, if you are going to create a scene that is ready for VR, you're going to want to start with three main components. Those three main components are going to be an XR origin, which is this guy that I explained a moment ago. You're also going to want an interaction manager. you can see here this is just an empty object that they've added to the scene and just slap the script on it and the xr interaction manager is going to be responsible all the interactions between the xr origin and objects like these grab interactables and then the final one that you'll want to make sure that you have in your scene is this event system which is used for ui events but more specifically for vr you need an xr ui input module and this is going to allow the translation of our xr inputs into Unity's UI canvas system.

So you know this guy right here if we don't have this it's not going to really understand when we're trying to interact with it what we're doing. So in order to practice this I say we make an empty scene and add those three components to it. So I'm just going to create a new scene here.

I'm going to right click go over to scene and I'm going to name it practice. Double click that and open it. And I'm going to start off first by deleting this main camera. With the camera out of the way, I'm going to start by getting our player set up.

So the XR Origin, you can find that in the prefabs folder here. you can also find it here, XR and then XR Origin VR. But the problem with this guy is if we expand it out, you can see it's only the camera.

It doesn't include all the goodies like the controllers or the locomotion system. So I advise you go into prefabs and drag that bad boy in. Another funny thing is we need to add an XR Interaction Manager.

Well, since I added this right here, the XR Origin, it automatically- Through this into the scene so I mean you can create it that way you can create an empty object in this add this script To it doesn't really matter or if you want to slap it on to this guy you can as well the next thing I'm one gonna want to add is the event system and the components needed to interact with VR and UI. So if we come over here and we go into UI canvas, you'll see it actually added the event system and it added the XR UI input module. So that's set. We have a canvas, we have our XR origin, and we have our interaction manager.

The last thing I'm going to add is a plane just so we can get some reference of where we are. Let's zero this out and maybe expand this out by two. There we go.

Now is the first moment of truth to test this. out. We need to test this bad boy out.

But in order to do that, we have two kind of options ahead of us. We can get the MetaQuest Link application. In this, you can either use AirLink or you can use a USB cable and connect it to your PC and then link up with this application right here, which I'll link down below. And then as soon as you log on through your headset using the Quest Link and press play mode, you should be able to test out your application. But you won't be able to send out a build.

to your headset unless you do some more step. Now, in order to build out to your headset instead of just only doing play mode, you're going to have to come over here. This is a step by step guide provided by Meta.

It will walk you through how to activate developer mode on your headset, how to use the Meta Quest developer hub. You'll also have to download this little fancy guy here. It's an Android debugging bridge, and it just it's needed for you to be able to, well, use any of this.

But I will link this down below. I'm not going to walk. step by step through this one. I think it's pretty self-explanatory if you just read it all.

Depending on what you choose, you should be able to come back to the scene, plug it in, connect through the MetaQuest developer hub, or connect through the Oculus or MetaQuest link, and then press play and see if this is working. And you can see I am in the game now, and if I move my controllers around, I can see myself and I can walk around in the scene. So cool. We're off to a pretty good start here.

If you found this video helpful at all? I hope you don't mind helping me out a little bit with just a quick like. But yes, back to more stuff. Now that we have set the scene up, let us go back to our demo scene. So I am going to go ahead and save this scene, control S, and go over to the demo scene.

And let's talk about locomotion. And if you're a VR veteran, you've done some dev before, especially with the XR Interaction Toolkit, you'll want to pay attention to the locomotion system because some things have changed here. Now, if I expand out the XR origin, I'm going to tell you what I am talking about.

So there used to be an old locomotion system that kind of covered all of this. But now we have two new components that will allow us to move around this character controller that we have. So this new locomotion system or updated locomotion system essentially works like this.

First, we have locomotion providers. And you'll see here there's different. kinds that I'm going to go over in a moment.

You have the snap turn provider and continuous turn provider. This is how we are able to turn left and right. This is the dynamic move provider, how you move forward and backwards, climb, teleport.

These providers, what they'll do is they'll send a message on up to the locomotion mediator. And what the locomotion mediator does is it kind of cues all these different inputs and says, this one's actually more important, or this one takes precedent over the other one. Once it kind of shuffles through all of them and determines who's worth sending onto the next step, it will then, well, send some transformations over to the XR body transformer. And this is going to be the guy that's responsible for queuing up all the different movements that all these guys have been sending up to the mediator, and the mediator then determines if it is worth sending here, and then this guy finally queues it up and then says, okay, this character controller, we're going to move it this way, this way, and this way. And that's how that works.

That's the locomotion system. So with that, I'm going to dive into the providers because those are very important to understand. And one quick aside before I dive into the providers, I'll mention with movement, people can get motion sick quite easily in VR.

So one way around that or to reduce it is using something called a tunneling vignette. And you can find that in the camera offset main camera right here. This is the tunneling vignette, and it just kind of creates a little black circle around our users eyes.

and narrows the vision and it can reduce motion sickness. But if you don't like that and you don't want that, you can just come in here. Here's the tunneling vignette controller and you can just turn it off right here.

You want to just click through here because you can assign it and turn it on for very, very specific use cases or, you know, like grab move, moving dynamically, whether you're turning or not. So if you want to turn it off, you can just click enabled or not enabled and that should take care of that. But right, let's move on to the providers.

So first and foremost is the turn providers. First, we have the snap turn provider and the continuous move provider. So the snap turn this is you'll hit the thumb stick and it will move you over a chunk. This continuous turn provider, as it says, is you press it and then you continually turn and that can cause more motion sickness.

So this is a good option to offer your players is to turn on snap turn or continuous turn and how you would turn that on and off. off if you come over to one of the controllers you should be able to find this little thing here smooth motion enabled and smooth turn enabled so you can just turn that on and off so smooth motion is actually for the next part which is teleporting versus continuous move so if you wanted smooth turn to be enabled you check it here otherwise you turn it off that's it if you were doing settings for the player and you want them to be able to save it this is this is where you would use the script to reference this and then turn this on and off here As I mentioned, there's smooth motion enabled. So if this is clicked to true, continuous movement will be enabled. Otherwise, it's going to default to teleportation. So if we come over here, this is the dynamic move provider.

This is where you can press the thumbstick forward and you'll start walking forward. You can change the move speed here. You can enable strafing.

So that's moving diagonally. You can enable flying if you want. Why not?

And then you can also set the transformation priority. So the lower this number is, the higher priority it is. That's what I was saying here earlier.

This would, if this was set to a five, so it's super low priority and all these other things are sending in to the locomotion mediator, well, then this guy's going to get queued in the very back. So, I mean, just leave it at zero. There's no reason for you to really change it.

Now, the last one I'll mention here is the teleportation provider. So you have this, this is where you would like push forward on your thumb stick and it would send out a beam. And if there's a valid target, the beams hitting and allow you to teleport to it.

And there's two different ways in which we can teleport to something. We can either use a teleportation area or an anchor, a teleportation anchor. So you can see here, this little square here is a teleportation area.

And if we expand this out, you can see all it is is a cube, nothing fancy set there. And it has a teleportation area set here. And you'll notice the interaction layer mask is set to teleport, which is very important. You want your teleport to be set to that. And then whatever your collider is, so this box is what...

we want our collider to be, you would just drag it in here and have the collider be that. And so that would determine your teleportation area. Then we have teleportation anchors. We come over here, you set or add a component teleportation anchor, make sure it's on the right interaction layer mask, don't notice that there's no collider here.

So if we expand out, we can actually see we have a few things going on. The big ones that I want to point out is mostly the teleportation anchor, what this is going to be is when you teleport to something. you can actually choose which direction the player is going to look.

So this is actually just an empty game object. There's nothing in here. All it is is a direction.

So if you set this to local, you can see where it's locally pointing. We have the Z axis pointing forwards. We have this pointing sideways and the Y axis is pointing up. And so that means we are just going to be looking this way.

Wherever the Z axis is pointing locally is going to be forward. And wherever Y is pointing is going to be what's considered up. So we could flip this upside down and have the player teleport upside down and really make them throw up.

If you come over to the teleportation anchor, you can see the teleportation anchor transform is set to this anchor right here. Now, you always need some form of collider to interact with. And for this case, what it's actually using is something called a snap volume. So essentially what this does is you put it on as a child of the main object. You set this up to have a...

box collider or any form of collider, set it to is trigger. So you can see it's this little box right here. And then you add an XR interactable snap value.

We have the interactable object as the teleport anchor and then the snap collider to this snap volume box. So what happens is when the interactor, the little ray on our controller hits this, it'll just snap to the center of it. Nothing. It's just a way to really refine your teleportation interactions. Big thing you want to do is, especially when you're using teleportation anchors, it's typically because you want the player to be facing a certain direction.

And so it's not just enough to set the little teleport anchor transform there. You also want to open up this teleportation configuration and make sure you have this match orientation set to the right thing. So this is target up and forward. As I said, that is where the Z is pointing and up is Y.

or green. And then we can change this to either just world space up, target up, or none. So if the player was just teleporting to it, it would just choose to what their default is if they're facing that way.

So with that, we have teleportation anchors, teleportation areas. We do have this new very, very cool guy over here. And this guy's very cool.

This is a teleportation anchor volume. And what it allows you to do is kind of group. teleportation anchors to multiple things. And so instead of having your player have to climb up the ladder, which can again cause motion sickness, you can just have them teleport to the very top of it or teleport to the second level and then the top. So it's just a nice addition.

I'm not going to go into it just because it's more in depth and I want to keep this a little more surface level. So in order to teleport to these, we do need rays shooting out and colliding with these objects, such as the area or the anchor. And you'll find that on the left controller and the right controller, you can see this teleport interactor. And going through here, you see the interaction layer is set to teleport, which is good.

Handedness is left, so that's on the left hand. And there's a bunch of different things we can tweak here and play with. honestly it's really nice the way it's set up now if you want to customize how the line looks you can do that here and if we want to send little clues or little nudges to our players that they're interacting with something that they can then you can find that stuff right here this is a simple haptic feedback it'll send little vibrations and let the player know that they're interacting with something so if they're hovering on it this is amplitude so how strong it's going to be for how long and the frequency of it Now, I'm sure that sounded like a lot to unpack, but it's really not that bad.

I think we should hop over to our practice scene and just make some little teleportations things really quickly. So I'm going to save this scene really quick. I'm going to go over to the practice scene and let's start by adding a teleportation area. Now Unity makes it very simple for us.

All we have to do is right click, go to XR, and then teleportation area. And that should give us a nice little area here. It looks like by default it gives us a plane, and I think that can work. I'm going to zero it out here, but it's going to mesh with our plane that we currently have going on, so I'm going to lift it up a little bit. And let's see if I can find a different material.

Eh, you know what, I'm going to create one really quick. Alright, I'm gonna name it teleportation area. I'm gonna color it turquoise. Why not?

And then I will slap it right on top of there. And you can see here, it should have everything we need. It doesn't have any colliders listed here, but that's just, it only used the default mesh collider here on the plane. And one thing we'll want to make sure we do is make sure we set this interaction layer mass to teleport. Now the other thing we need to do is make a teleportation anchor.

So I'm going to go ahead and go to XR, teleportation anchor, and for some reason it is a plane. Which, I mean, I guess that's okay. Let us reduce this plane down a bit.

Let's see, 0.1 all around, and then I'm also going to slap on the teleportation material onto it just so it looks distinct from everything else. And, you know what, let's lower this down on the Y axis. and then raise it just a hair. All right, there we go. So if we expand this out, it looks like they gave us anchor to work with.

And remember, this is where the Z axis, the blue guy in the Y axis matter quite a bit if you want to make your player look in a certain direction when they teleport to it. So I am pretty okay with that orientation. Let's go through this and make sure we got the right settings. Default, I am gonna set to teleport.

Make sure I turn off everything. Colliders, it should use this mesh collider as the... default and then I want to match orientation so target up and forward I want to teleport to this and then also look straight forward and that looks pretty good there with that all set you know what I do want to play with one last thing here and that's on the teleportation area you know I'm going to set this to match directional inputs so that will allow the user to teleport to an area but then they can use the thumb stick to also rotate the reticle and point in a different direction and with the teleportation anchor I'm gonna set it and just leave it as is and not allow them to rotate or anything and that way when they teleport to it it's just gonna be up and forward we should also make sure that we have a teleportation provider on one of the controllers so I am going to open up And let's see here. Well, we have teleportation providers, but we need to make sure one of the controllers allows us to teleport.

So the left one's set to smooth motion, and it looks like the right one's already set to allow us to teleport because smooth motion's turned off. So yeah, let's press play and see what we got. Okay, and so I'm able to move around with my left controller. In my right controller, I can snap turn, and if I push forward, it sends out a teleportation beam. And if I go over here, I can...

Go onto the teleportation area and then rotate the reticle and point myself in whatever direction I want. But if I go over to the teleportation anchor, you can see here I'm trying to rotate it and it just snaps me into position. So we have some teleporters working here, which is all good.

I say we save and move on to the next thing, which is going to be how we interact with things, how we grab things, how we poke things, how we do all the things with all the objects inside of our scenes. So for interactions, we are going to need three main components. And my VR veterans are going to want to pay attention here because we do have some new interactors that we get to play with in the XR Interaction Toolkit 3.0.

So... the three main components that we need are interactors, interactables, and the interaction manager, which we already talked about here. And I guess you could say the XR UI input module that we have here. I guess you'll need that too.

But primarily, you need interactors, interactables, and an interaction manager. The first one I'm going to dive into is actually the interactors. So these are...

what we find on our controllers. So if I expand out the left and right controller, you can see here we have poke interactor, near far interactor, teleport interactor. We have all these interactors here.

And so these are going to be what triggers on objects saying, hey, I'm grabbing this, or should I be able to grab this or poke this? Now, if you have done VR development before, especially with the XR interaction toolkit, this near far interactor is actually a new guy. And essentially what they've done is they've taken the ray interactor. and also the direct interactor and they've rolled it into a singular component so it's pretty nice do like its functionality and it looks really really good in the scene we'll boot it up in a moment and i will also mention that the direct interactor and the ray interactor they haven't been deprecated they are still in here so let me look one up direct interactor yeah you can find one here so people who are new to vr development and haven't used the xr interaction toolkit What used to be is you'd have a direct interactor and a ray interactor. So the ray would be used to grab objects from afar or interact with UI.

And the direct interactor acted as, well, a direct interactor. And you can still do it that way. But this near far interactor just kind of combines both those functionalities into one. And if you want, you can adjust it.

And so if you want to just be a near or far interactor, it can do that too. A quick breakdown of the near far interactor. Looking through here, you have the Interaction Layer Mask as always.

And I do typically like to add a layer called Grabbable to this. That way it keeps up what I can grab and what I can't grab. So I'm not just picking up whatever I want. But it's just good to know. You can put objects on different layers and allow your user to interact with them at different times based off those layers.

Going back to the NearFar Interactor. So you can play with Interaction Layer Mask. there.

And also down here, this is where you can enable whether or not it is near casting or far casting. So if you want it to be able to grab objects nearby, you want to have this selected to true. If you want it to be able to select objects from far away, you select it to true. And if you want it to be able to do both, just leave them both as true.

Other components associated with the near far. Our interactor is down here. We have the interaction attach controller. So this is going to be what is responsible for how interactable snap or follow the interactor.

You can make a bunch of minor adjustments here. Do you want it to move quickly with it to slow it down? We have a nice moving speed here.

So this is we picked it up from a distance and we start waving it around. You can adjust these and this is how the object will wave around with it. We can increase the momentum, slow it down.

This is just a bunch of customization things with how you interact with your objects. Next we have the sphere interaction caster. So on the direct interactor, what you used to have to do is you used to have a little sphere collider here, and then you set it to is trigger, and whatever enters this sphere would let this XR direct interactor know that something is within range and we should be able to interact with it.

How the near far interactor works is it uses a sphere interaction caster. It's essentially doing the same thing, it's just not using any colliders or anything. Instead, it has this cast radius.

So whatever is within this radius of 0.1 out from the center of the cast origin, so the near-far interactor transform, then it will say, oh, something's here. Should we interact with it? Let's interact with it. Then we have the curve interaction caster.

And this kind of acts like the sphere interaction caster, except this is for the ray portion of the near-far interactor. You'll also notice here, this is where we can put our ray cast mask. So if you only want this... near far interactor to interact with UI. We could turn this off and it would interact with only this UI.

One thing I'll mention is if you test this out and just use that UI, for some reason, these all aren't set to the same layer of UI. And so I'm just going to go ahead and say yes to change the children. Encountered a weird bug and I couldn't interact with it because I set it to only UI.

And yeah, it's just because all the children weren't set to it. So that is the curve interaction caster. If you ever want to adjust how the line actually looks visually, if you expand this out, you can see the line visuals right here.

And that is where you would just things there. If you expand this out, you can see no valid hit properties, this is what it looks like UI hit properties, it changes this kind of gradient color UI press hit, so it turns a little blue there hover. So this is where you adjust all the little visual things.

And like most interactors, this also just has a simple haptic feedback. So if you want to adjust vibrations and how things interact with things to notify the player that they are interacting with something, this is where you send that haptic feedback. And that is the near-far interact. So now that we know how this near-far interactor works, let's look at what it's actually interacting with. And one of the things it's going to be interacting with here is these guys right over here.

These are going to be our grab interactables. Now, a quick rundown of how this works is if you look at this, we have a rigid body attached to it, and then we have a component called the XR Grab Interactable, and then we have the XR General Grab Transformer. But coming back up here to the main component that we care about is the XR grab interactable.

Like everything else, it has an interaction layer mask. Personally, myself, I think you should add a layer here called grabbable or interactable and then set it to that. And then also make sure you set on your near far interactor on each interaction layer mask to the same thing. It's I just think it's better practice. But for now, we'll leave it as default.

we also have colliders here. If I expand out, there's no collider set. And so what it's going to do is it's going to use whatever its native collider is.

So let's see what we have here. The visual is going to be this guy right here. Oh, it's going to be this little mesh collider. And I'm not really seeing any other colliders on here.

So this is it. This is the collider it's going to default to is whatever collider is attached to it. Now, one important thing I want to point out is the movement type. So these are actually pretty important.

because how you choose between instantaneous kinematic or velocity tracking will determine how your objects interact with the world and your player. So I am actually going to boot up and show you what these are because, well, it's easier to see than it is to talk about. So looking at the three of these, first we have kinematic movement. So I'll pick this up and you'll see it kind of tracks the velocity as I move it around, but it turns it to is kinematic on the rigid body. So it will go through this.

And yeah, that's a pretty interesting interaction But when I let go of it, it'll turn is kinematic back on and so that way it interacts with the little table here again Now instantaneous if I pick this up moves instantly with my movements It's it's not doing any velocity tracking it tracks one to one with my controller movement and also makes it is kinematic So it can go through the table. But if I let go boop it can drop but velocity tracking this will both track the velocity so you can see it kind of lags behind and also it runs into the collider and so yeah there you go so the movement type it really comes down to what you need in your game kinematic is pretty good if you want to throw objects but if the player is holding it you don't want it to get stuck on doors and stuff i would say velocity tracking is the best if you want things to be the most realistic so if you're holding a sword and it runs into a wall then it will hit the wall and instantaneous is also really, really good if you want it to track one-to-one with the controller movements. Other settings you'll want to check out here. I mean, you'll want to experiment and play with all of these, but some important ones you want to consider.

Throw on detach. So when you let go, do you want the object to be thrown? How much velocity you can play with? Force gravity on detach. So do you want gravity to slap onto this immediately?

Another one that is new, if you've messed with grab interactables before, this is far attach mode. This is going to allow us to either determine if we want it to be near, far. or defer to the interactor. So essentially, if we want this to snap to the player's hand when they pick it up, then we'd want it to be near. If we want it to remain far when the player picks it up, then we choose far.

And if we don't care either way, we just whatever interactors interacting with it, then it will choose on the fly. So in this case, since we are using a near far interactor and we also have it set to both do near and far interactions, it'll choose the far interaction. That's why it kind of hangs on a string and we can wiggle it around. The next thing we have is use dynamic attach. So essentially, this means we can grab anywhere on this object.

And that's where we will grab instead of using some kind of attach point. And I'm actually going to come over to this demonstration because well, it's the one that demonstrates it. And we can see here we have all the settings here. If I select it use dynamic attach, it's using dynamic attach. And then this one, let's see here single fixed attach.

So we come down here, you can see it doesn't have this set to use dynamic attach, but attach transforms right here. So if I select that, you can see it has an attach transform. So wherever we grab this, it is then going to snap us to this point right here and attach to it. So that's how you would like if you want them to pick up a sword, this is how we pick up a sword.

If you want someone to pick up a sword and have it faced upwards and forwards, then you would use an attach transform just like this. And then we have dual fixed attach. So there's two different attach points that we can attach to.

Let's see here. There we go. And if I scrolled down you see we got this attach point and this attach point. So we have two different ones it'll attach to. And the way this works is it will take the first attach point so whenever we have an interactor interact with it it will attach there first and then it will do the second attach point when we use the second interactor.

And that's how that works. I'll also mention that these all are set up to be near interactions so if even if I use my ray to grab them it is going to snap to my hand. So I'm going to demonstrate.

So first we have the dynamic attach. I can grab it and it snaps to my hand and you can see it just snapped to that one point that I was already pointing at. I can let go and keep grabbing it and it just kind of snaps to wherever I want. If I use the single fixed attach point, you'll see it snaps to a specific spot that I wasn't even aiming at. And then finally the dual fixed attach.

I can grab it with this, but I can also, there we go. I can also grab it with this. And so now it's kind of like a two handed gun and I let go and I'll snap to the first point and then I can grab it with this. And so now this is kind of the leading guy.

Now, the next thing and the last thing I'm going to mention on this subject is going to be UI. So we're going to want our players to be able to interact with menus and things. And so we'll we should probably know how UI works. And it's not too complicated. It's pretty, pretty shrimple.

Important things that you'll want to know or make sure you don't forget. is the fact that the canvas itself exists in world space. It has to physically inhabit the world. It can't just be an overlay.

That's not really gonna work here in VR. So it has to be in world space and actually fill in a position here. You can see it exists within this little world. Another thing that you'll wanna make sure that you do is make sure that your interactor is set to interact with it.

So like I said before, this is all set to the UI layer. And so if we come up here to the near far interactor, It's not going to be this interaction layer mask that matters. If you come down here, it's actually going to be found here. Yeah, this curve interaction caster.

So this is what's going to determine whether or not we can interact with something with our rays. If I have this set to default and UI on the right hand and say this was set to just just UI, it would only interact with the UI and it won't interact with any of these objects. So that's how that works. Now, as always, I think it's good to practice. So I'm going to go hop over to the practice scene really quick.

And in it, we are going to create a quick little tiny canvas and also a grabbable object or two. Now, I did make a canvas in a previous section to this. If you don't remember how to do it, you just come down to XR and then you come over to UI canvas.

And this is going to make it in world space, which is what we needed. And it's going to make sure you have all the components that you need to have a well, XR canvas. That's typically what you want to do when you're creating things like this that have other ways of implementing them. We could come over to UI and just create a canvas there, but then it's going to be in overlay mode and that's not what you want.

So it just makes it easier. Now for the canvas, we need to fit it down into our world space and it's going to be a lot easier if we can see it. So I'm going to go ahead and look for, let's see here, let's find an image and then I will stretch it out across the canvas.

And it is massive. So I'm going to go ahead and reduce that. Let's see. Okay, five by five.

That works pretty well. And you know what, let's make it look aesthetically pleasing. There we go.

And for this, we're going to want to interact with it. And I'm just going to slap a button on there. Well, I chose a button with Tex-Mex Pro, but I don't have it in the project. I'm just going to import it.

Okay, with it imported, I am going to reduce the size of this by quite a lot. Let's go 1 by 0.5. That looks horrible. All right, I'm just going to reduce the size.

Let's say 0.2. No, we can go smaller than that, 0.02. There we go.

That is a button. I'm going to rename it to something really original, like, oh, like this video. Ooh, very creative.

So subtle. All right, well, there's that. And let's make sure that this canvas is set to the UI layer.

This is all set to the UI layer. Cool. That button should work. But before we hop in, I'm also going to create a quick little table here, just a tube.

Let's zero it out. There we go. I'm going to move it over here. And on it, let us create at least one interactable object.

It can be whatever you want. I am going to... Let's do a cylinder. Who doesn't like cylinders?

Move this up a bit, shrink them down. Let's go 0.2. That's cute. That's a cute little cylinder. And then we need to add a XR grab interactable to it.

And you'll see it already added the rigid body so that's perfect. Let's make sure the interaction layer mask is set. default, which is what our hands are set to. The movement type is instantaneous, which I'm okay with.

Let's see. You know, I'm okay with a touch dynamically. This is all the stuff you want to play with and get to understand because the only way you're going to understand this really is not by watching this video. It's going to be, oh God, don't roast me in the comment section for that line.

Look, I'm just, you gotta, you gotta play with it and you gotta practice with it. All right. That's what I'm trying to say.

All right. Don't. Now if I boot into the scene, you can see I can click this button with this controller, I can click it with this guy, and I can also pick up this object.

Which, hooray, it's all working as expected. With those all done, it's time to go back to the demo scene and look over this Poke Interactor and what it does. So it turns out interacting with things in a very specific way is incredibly important in VR because it's part of the immersion.

And so they had to make a Poke Interactor because of how unique. that interaction is. It's not just a simple, I mean, you can do just simple physics colliding with things, but it can get a little iffy and wonky. If you've watched any of my other button tutorials and door tutorials and stuff, you'll understand what I'm saying by wonkiness.

When you play with physics and stuff, sometimes things like to vibrate a lot if you don't lock them down. But this, this system makes it way easier. So first on the left hand controller, we have the poke interactor. Now the poke interactor works well, very easy.

All you have to do is you add an XR poke interactor. Of course, we have our interaction layer masks, our handedness. So which hand is it on? And then the transform. So this is going to be where it says, oh, a poke is being initiated.

So that's very important. You want it to be at the tip of your finger, or in this case, at the very tip of the controller. Now paired with that is going to be these.

buttons over here. So these buttons, if we select it, you'll see how they implemented them. And I'll run through the components that are necessary to make this work.

Obviously, here we have a box collider. So we're going to need that for the interaction. We have an XR simple interactable.

Now this is about as simple as interactions can get. It just allows you to handle selecting and deselecting. Now the other component is a poke filter.

So this allows us to refine the poke interaction. Here it's going to take a poke collider. So it looks like it is going to be the collider here and then it wants a interactable.

So this is the XR simple interactable here. And then this allows us to further refine it and define what the hell a poke is. If you are poking in a direction, say a negative direction, right here it says along what axis and then it will be going down the opposite side. So now this lets you define things. further in the poke configuration.

So this button could be on a wall and so poking it would be a different angle in a different direction than where it is now. Now it just so happens it looks like poking down Y in a negative direction would be pushing this button in. So actually, let me expand this out really quick.

So you can see this is why it's set to negative Y, but we can set it to negative Z, X, or we can just set it into any direction X, Y, and Z would be considered a poke. Now, another thing you'll notice here has enable poke angle threshold. If you start poking towards something in a direction, the user might move their controller in any angle or direction around that.

And so this is a way to say, well, if they move like 90 degrees, they're not really poking straight at it anymore. and it kind of messes everything up and it'll break the interaction. Now, finally, we have the poke follow affordance. So this is where the magic of actually visually moving this button comes from and also determines where it's going to stop. You can see here we have a smoothing speed.

We have an emergency stop offset. So this is going to be the... form that actually moves when the poke interaction happens. See if I move it you can see this is where the button would push and then if we come back here yeah that is what moves when this is saying oh yeah a poke's happening and it's going in this direction.

Now this is also where we're going to be able to set up the max distance and so this is going to be the max distance that we allow the transform to move or for the poke follow affordance to move. So if you look at this we can see that it is doing it based off of this transform. I select it and you'll notice that this transform set at 0.05 practically 5.05 is what I'm going to say.

And if we look at the visual, the visual itself is also not exactly at zero. If it's at zero, it shoots up that high. So you kind of have to play around with this and you'll notice this is actually just an empty parent object. And this is what you want your offset to be.

So if we come back here, you can see there's a 0.045. So when we press play, we'll actually be using that offset and it will stop it. Let's see there. It'll stop it just about there when it gets close to zero.

And so that's what you want to do when you're setting this up. You want to create a parent object, the button that's moving, make it a child of it and have this offset so it visually looks correct. Now finally is putting it all together.

What we have here is a system that uses a few different things. We have the XR Simple Interactable. This is what's going to be used for just signaling simple events.

So this is going to enable a particle system, and that's done through the select entered and select exited. That'll turn these particle systems on and off when we push it in. But how is it going to be notified that select entered has occurred?

Well, that's going to be done with the poke filter. So the poke filter is going to be the thing that says, okay, is a poke happening? We've set these standards of what defines a poke for this button. Is it going in the negative Y direction?

What's the collider that we're associating this poke with? And what's the interaction depth offset in relation to this? So in this case, we are using this box collider and we're saying the interaction depth offset is zero. So what we're saying is when we poke here, this is where it starts is at the top of this collider.

and it wants it to go to at least zero while going negative y. So we'll be pushing down with our finger going negative y, and it's not going to trigger anything until it hits this zero. So it's going to be actually right in the center.

That is what is the center of this object is, well, zero. And if you ever want to change that, you can always increase it and decrease it, but that is up to you. You're going to have to play around with this until it feels just about right.

Now, if it has reached that criteria, if it's going in the negative Y direction, zero is at the right angle and it hasn't broken that angle while going through the push motion. Then it is going to send up to here a little message saying, all right, select entered, activate the particles and don't get it confused. So this XR poke follow affordance is also going on, but that is not what's responsible for signaling to the XR simple interactable.

This is what signals to it. you can see this is where the reference is. And this is actually just a visual aid that we use. So it looks like we're pushing the button.

And that's it. That is how buttons work. So with that, I think it's time for us to implement this ourselves.

So I'm going to go back to starter assets. And I'm going to find our demo scene or sorry, practice scene, I'm going to save the demo scene and hop on over to practice. Coming back into the practice scene here, let's make ourselves a button. And you know what, I'm going to say that I am not too fond of this button solution.

But this is how I found to make it work with the tools that we are given right now. So first, I'm going to start off by just making an empty object. And I am just going to call this the button.

Now with this button, we are also going to create a few child objects here. So I'm going to create another one. And I am going to call this visuals. And with visuals, I'm going to create two more. objects here.

And one is going to be just a 3d cube, which if we scroll back a little bit is going to be way too big. And I'm going to call this base. And then we're going to create another one that's going to be empty. And we're going to call this push button offset.

And so this is going to actually end up being the offset that we use. So the button pushes correctly. And then a child of that is going to be the actual visual for our button. And we could do a cube or a sphere.

you know what, I'm going to go with a cube. And just for the sake of naming things correctly, let's just call this push button. Next, we need to select the parent of all these little objects in here.

And this is going to be the button. First, we're going to need a collider. That's going to be the thing that signals when we've actually started pushing on something.

So I can look up box collider. And you can see it's going to be the same size as this base cube. In fact, you know what, I'm going to turn the mesh renderer off on this so we can get better visuals. There So this is what we have so far. Other components that we need are the simple interactor or XR Simple Interactable.

We're also going to need a poke filter. And we'll need a poke follow affordance. Now I want this button to poke downwards like the other buttons in the other scene.

So I'm going to set this to negative Y. And then for the poke follow affordance, this is going to be the movable thing. So this is going to be this square right here is going to be pushing downwards. And don't worry, we'll shrink it down in a moment. And so what we need to do is we just need to come back over to button and then drag this offset there.

Now this is where the button gets a little funky and honestly. pretty confusing. I don't know if this is the best solution. And I might try to come up with my own solution in the future.

But this is how I got the unity sample solution to work. And so first, what we have to do is we obviously don't want a button that's this massive. So what we can do is shrink it down.

But we can't just shrink it down using the scale. Because if we use the scale, the way this script works, it does not account for scale. So if we did that, the whole calculation falls off and the whole thing. well breaks. So instead what we're going to do is we're going to shrink down the box collider.

Normally we'd want something say scale this down to 0.1 and that looks like a pretty good size for a button if you could imagine. So what we'll do is we'll keep the scale at one but we'll reduce this box collider down to 0.1 across the board. Just so we can see where this collider is at I'm going to go ahead and come into here and just remove these. colliders because they're not really necessary.

And so now you can see the collider inside. And you know what? To get an even better view, what I'm going to do is I'm going to switch this to isometric view. So if I do that, double click the button and you know what? Let's flatten this out.

There we go. Rotate it a little bit. And so now we have what our button looks like. And we can see the collider inside, but we've got to scale this down now.

So this base is too big. The rigid body's at 0.1. So if we reduce this down to 0.1. It should look a lot better. And the reason it doesn't is because we also have a mesh renderer here.

So let me hide that. Oh, and I am foolish. I turned off the mesh renderer. So there we go. This is the tiny mesh renderer.

And if we looked at the collider there, it's also sitting right on top of it. Now, we're also going to want to reduce the mesh renderer here because this guy is also gigantic. So let's try by reducing it by 0.1 across the board. Now I want to see this a little better than just having gray on gray.

So I'm going to duplicate this, control D, and then I'm just going to name this button. And I'm going to change the color to red. And then I'm just going to put it onto the push button.

And so now what I want to do is I want to base everything around what is considered zero when we're pushing in. So this box collider, it's going to start calculating here and then going down here. And this center is what's considered zero. of this object. We want the push button to be up here in the visual for the push button to be up here.

And we want the base to be right down here in meeting up to that point. What we know is the base is at 0.1. So if we bring it down by half, 0.05, we'll see that it's popped up like that. Next, we got to get this offset going correctly. So the way we do that is we are going to say, all right, this is what 0.1 in height.

So since this is sitting at 0.1, let's try putting the offset here at 0.05 as well. And you know what? We should also choose clamp max distance. This will push it up and you'll see it popped up there.

So now the problem we have is this button is sitting up here and the visual is obviously off. You know, we're going to poke here and it won't start calculating until it hits the collider right at this point. And so it looked like our finger is halfway through the button.

So we need to reduce the size of this a little more. So if this is at 0.05, we should probably reduce this by that much as well. So this is sitting at 0.1.

So if I take it and change it to about 0.05, you'll see it chops it in half, which, yeah, that's to be expected. The idea is if we lower this then, just the visual, not the offset, if we lower this offset by half of this, then we should be pretty close to what it needs to be. to look visually correct.

So if we go 0.025. Now the problem with this is when you do that, that means when this pushes all the way in, I can set this to zero really quick, it pushes in all the way and it starts blending into the base doesn't really look good. So what we can do is we can cheat a little bit.

And we can say instead of going all the way, what if we did like point four, five, and so that'll push it just a little bit higher. That way when it zeros out, and we're pushing inwards, you can see there is a little bit poking out overhead. So I'm just going to reset this to there.

And let's just run through this one more time. So we're going to come in, we're going to push with our finger here, this is where I'll start the calculation. and it'll start pushing down but at the same time this visual is using this offset to also push down with it.

So now it's time for the moment of truth it's time to press play and see if this actually works. One last thing we'll add is just swapping out these materials for the base just so we can tell if it's being selected. So if we go to the XR symbol interactive or interactable I should say and go over to select entered and exited we can take the base go over to its mesh renderer and then swap out the material really quick. And let me just find some random one. Let's see.

We'll turn it blue and then we also grab the base again and then do the same thing and just change it back to its color that it was originally, which I think is a gray and medium gray. There we go. All right. Now let's boot it up and see what we got.

Now I've decided to keep it in this view. You can see my controller flying around in the scene. But I wanted to keep it in this view so you can see what's going on with these calculations. And so when I push down, you can see it's following it perfectly. And when we get to the bottom, it finally triggers the event and changes the color.

But when we let go, it turns it back to gray. So that's it. A working button. Likes are a great way to grow the channel.

And if you want to take it a step further, go check out my Patreon, where I'm going to be releasing exclusive content like custom tutorials. And I finally teamed up with a modeler, so I'm going to... have them create a fun little model for me every month for you guys to use in your games and take home with you. To my current patrons, thank you always and forever. I will see you all in the next one.

I am tired. Bye-bye.