Inventory for VR Player - Unreal Engine VR Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
we as humans have only two hands now i know this is a huge shocker to some of you but because of this we're only able to carry around two objects one in each hand when wandering around a virtual space but what if we want to be able to carry even more extra tools weapons gadgets or even just that random picture that we find very fascinating sitting over there on that shelf on this tutorial i'm going to show you how to set up a very simple inventory component that can be attached anywhere on a player or even other actors that way players are able to carry around their most prized possessions when wandering around a virtual space but before we go ahead and jump to that if you enjoy this video and want to see more just like this one be sure hit the like subscribe button down below with that let's go ahead and jump right into the tutorial for our inventory system here we're going to need a few things so i'm going to go and get started here we're going to go and open up the content browser i'm going to create a new folder here called interfaces now we're only going to have one interface that we're going to be using here but the only use for this interface is we're going to use this interface or to grab and release objects since anything that we want to go into that we want to be able to go into an inventory will need to be able to be picked up and dropped and this will just kind of help also make sure that we're on the same page we have the same interface we don't have to worry about anything later on so i'm just going to go and create a new interface there and call it grab let me go and open that up and we're going to need two functions here our first one is just going to be called grab and we will need to feed a motion controller component into our grab function here so let me go ahead and set that up and then we'll also need a release function as well this will also need a motion controller in the input as well so i'll just go ahead and add in an input value or an input parameter call it motion controller so now we're all done with the grab interface up here if you want you can go and close that we won't need that open anymore but now let's go and open up our content browser and we're going to go ahead and create another new folder here this one's going to be called blueprints we'll have two blueprints in here so we will have this open for two of our um for an actor and a component i'll get to the component in a second but let's go and start by creating a blueprint class called actor and i'm just going to call this inventory cube so we're just going to be opening this up and i want to just give it a simple static mesh something that we can visually see and and we'll be able to see that's actually being attached to our inventory component later on once we have that set up i'm just going to go ahead and add a static mesh here and i'll just call it i'll just leave it called static mesh but i do want to go ahead and set that as our root component there and i'm going to set this as a 1m cube we will need to scale this down once we import this into the scene but for now that'll work just fine and we also welcome down here we also want to make sure that this is set to overlap all dynamic this will just make it a little bit easier it'll make sure that we're able to find this actor later on when we're checking for overlaps so it'll just make things a little bit easier and that's the only thing you need to do here to this static mesh but we will need to come up here to class settings and we do need to add that grab interface to imp to our implemented interfaces here so that way we can access that grab and release function and we can work with those once you have the grab implement added into the interface we can go and move on to the event graph so i've already gone ahead and deleted the begin play the begin overlap in the tick since we don't need any of those three default functions but we will need to implement both our grab and our release event so let's go and implement both of those and we just need to be able to attach these to our motion controller components as well as be able to reset once we release so this will actually be pretty simple so i'm going to go and grab our motion controller i'm going to drag out i want to promote this to a variable we'll go and leave it called motion controller it's a pretty fitting name to be honest so we'll go and leave it there and we also want to attach the actor to component so let me go and drag that up drag over our execution node and our motion controller is going to go into the parent for our attach actor i'm gonna go and set our location to snap to target as well as our rotation and i'm also going to want to set our scale to keep world to make sure that our scale remains consistent and it doesn't increase or decrease in scale when we grab and release our our actor here so now let's go ahead and come down here and down here for our motion controller first we're going to want to check to make sure that whatever motion control we're releasing with is the same one that's currently grabbing the inventory cube otherwise we don't want to run this release so let's go ahead and check to see if these two are equal go and run a branch up here drag over that execution node and assuming that it is true we'll want to do two things first we'll want to set our motion controller back to null and the second thing we'll want to do is we'll want to detach from actor this will detach from the motion controller that we attach to up here and grab and we want to set all of our rules here to keep world this will make sure that it remains it remains in the same location rotation and the scale remains the same so we'll make sure that all of that is all good to go and that is all that we need to do here for inventory cube so i'm going to close out of that and jump back over here into our vr template here so now that we're back here in the scene let's go ahead and create our inventory component now so i'm going to open up our content browser i'm going to create a new blueprint class and this is going to be a static mesh component you will need to find it down here in all classes since it doesn't show up up here in common so you'll just need to find static mesh component down here and i'm just going to call this inventory component now the reason we're doing things this way is for two reasons the reason we're using the stack mesh component as our parent class is this will give us the option to be able to visually see this inventory component since that can sometimes make it a little bit easier on the player to be able to visually see what is going on so this gives us just the option to add in a sphere maybe a cube maybe you have some other custom mesh that you would like to be able to use here for our static mesh that just gives us that option here the other reason that we're using a component as opposed to just attaching this to our plater is this will simplify things down a whole lot since we might have several different spots where we want to be able to attach actors you know for inventory um you know say for example on the chest maybe on the back maybe you have something on either side of the waist uh the wrist like we'll do in this tutorial so on and so forth this will just kind of make things easier all we have to do is attach this component to our player and drag it to wherever it needs to be it overall simplifies things down a whole lot so um so that's basically the reason we're doing things this way so let's go ahead i'm going to drag this down and we're going to want to do a couple of things here so first i'm going to go ahead and come up here to our begin play we'll use our take here in a second so i'm just dragging that down but we'll come over here to begin play and we want to look up for uh begin overlap now you'll notice here a couple things one we don't have an event to play with um we have a sign on component begin overlap bind on bind and unbind well we have unbind all events and unbind events what we're going to want to do is bind event and we're also going to do the same for end overlap and overlap now in case you've never messed around with blind with binding uh event dispatchers or anything like that what we're going to do here is we're going to create our own custom event that is binded to begin overlap and end overlap this means that it will still act as a typical begin and and overlap would we just don't have a just a standard event that we would typically use so i'm going to go ahead and just drag down our event here i'm going to create a custom event i'm going to create call it begin overlap and you can see it automatically adds in all of our input parameters here that we would typically expect from begin overlap we have our overlap component other actor other component so on and so forth uh we're not going to need all these but it does tie all of our input uh parameters that we would typically get and begin overlap so let me also go ahead i'm going to do the same for our end overlap over here so i'm just going to do another custom event call that and overlap and drag that over and you can see it's the same exact thing we have all of our typical input parameters here so we have our events in place here let's go and get started with our overlap here so i'm going to start here with begin overlap now this will probably be the the longest piece of code that we have here the longest blueprint string that we have here so i'm gonna go and get started by first creating a variable that we can use here i'm going to go ahead and call this grab uh yeah let's go and call it grab actor and i'm going to want to come right over here i'm just going to change this to variable type um inventory cube there we go and this is going to keep track of what com of what actor we're supposed to currently be grabbing and we're going to always assume that it is of type inventory cube which is why i set that to inventory cube so going ahead and grabbing our grab actor here we're first going to want to check to see if this is valid now we want to make sure that this isn't valid in the first place since we want to make sure that we don't we're not currently grabbing something we're not currently attempting to grab anything before we're trying to grab something else so that way we don't have multiple overlapping actors on this single component so if it's not valid we're going to want to take our other actor and we're going to want to cast it to inventory cube so let me go and drag this forward that goes into is not valid here we go let me actually move this around back here so we can try and see this a little bit better i think that'll work there that works a little bit better um so uh now that we have our cast inventory cube here so this will do one of two things uh it will either cast successfully which means that we are dealing with an inventory cube and that will come out this execution node or it will completely fail meaning that this isn't a inventory cube of any type it's not a child of inventory cube so we can't work with it at all which in that case it doesn't really matter what what we do with it we're just going to ignore it so to start out let's go ahead and as inventory cube we first want to get motion controller they may recall we set this motion controller to a component we actually set this motion controller on grab and we set it back to null on release so we first want to make sure that our motion controller is valid now the reason for this is this means that we are currently grabbing this which means we can attempt to grab this actor that we are currently monitoring um if this doesn't have a motion controller component it may mean it's simply sitting on a table maybe it's being thrown through the air or something like that we don't want to attempt to grab this specific inventory cube then we also so what i'm going to do here is actually optional but this is something that i've chosen to do for for some cases is i'm going to go ahead and create another variable here called actor to ignore actually let's go and call this controller to ignore controller to ignore now this is entirely optional what this is going to do is i'm going to set this to a motion controller and because this component can be attached to the hands and we may have it too close to one specific hand especially if we're holding a particularly large object we want to make sure that we won't release and attach it to a inventory spot that's attached to maybe our wrist or something like that so this will just kind of simplify things down make sure that we don't attach something from the same hand this is entirely optional like i said but this is what something that i've chosen to have in so i'm going to go ahead and get this i'm going to check to make sure it is not equal to our current to our current motion controller not our inventory cube there we go there we go let me go and raise this up a bit and we're going to want to check to well let's first check to see if this is valid because we won't want to do one of two things depending on if it is valid and then we'll go ahead and branch over here the branch will only run if this is valid and if this is true then we're going to want to set our grab actor here we also want to start a grab actor if our controller to ignore is not valid because that means we're not ignoring anything so we'll just go ahead and pass that by there we go and then we just need to grab our inventory cube here and drag this right up here to our grab actor and that deals with all of that there we go there now end overlap is going to be quite simple all we need to do is check to see if the grab actor is equal to our other actor so let me go and drag that down and branch that off and assuming that these are equal to each other then we just want to set our grab actor back to null so quite simple not a whole lot to do here end overlap is pretty simple like i said begin overlap is probably the most difficult part of this of this section of the of this tutorial now finally we're going to move on to our event tick now again i don't think that this will be too difficult um it's actually be fairly simple so uh we'll go ahead and fly right through this so i'm going to start by getting our grab actor but first we're going to want to check to make sure that this is in fact valid so let's go ahead and drag that up now assuming that it is we then want to get the motion controller from our grab actor and we want to check to see if this is not valid so if this if we determine that this is not valid this means that we now have a component we've already determined up here in begin overlap that it was being held at one point we've already determined that it was being held we've already determined that something we can grab what we're doing here at this point is we have now determined that it is no longer being grabbed but it is still within range that we should be able to attach it to us and we should be able to consider this something that we can grab so in this case what we're going to want to do is we're going to want to get the grab actor and we're going to want to attach it to uh to our to ourself so let's go ahead attach actor to component bring that down and that's good wannabe on is not valid make sure that let's go and bring down a couple reroute nodes our parent is going to be the self since we are a static mesh component we want to be able to attach to ourself our location rule will go and snap to target along with rotation our and our scale will go ahead and keep world and that finishes off everything that we need here for our inventory component so we are now all good at this point so uh now i'm going to go ahead close this down after i compile and save all that now we're going to go ahead and move over to our player so let me go and open up the vr pawn there we go and let's go and start over here in the viewport so here in the viewport we're going to want to attach that inventory component that we made to wherever we want it so for this example i'm going to attach it to the roughly the wrist of each of our motion controller components so let me go ahead i'm going to get the inventory component you can see it just shows up right there and i'm just going to call this inventory component left and yeah i'll go ahead and set the static mesh to a sphere and we'll go ahead and set to an arcade editor sphere but i will need to decrease that scale quite a bit i think that's pretty good and let me also go ahead and drag this forward a bit now you may not be able to see it too clearly but we have our motion control components right here so i want to just move this down a little bit i find that roughly negative 40 is pretty good right there um and i also want to come down here and i also want to make sure that we are set to overlap all dynamic uh otherwise it can it can collide with the motion controller this may not always be necessary but if we set to overlap ball dynamic um then it'll make sure that it's not colliding with our motion controller and we're not running into any issues there so i'll just set that to overlap all dynamic i also want to change this element there is let me see here there's an element that i personally like to use for testing this kind of stuff here it is disk material it's something that's semi-transparent here so we can somewhat see when something is inside of it so we i i personally like to use something like this where it's somewhat transparent like this and then i'll go and copy this and move this over to our right everything can pretty much stay the same i'm just going to rename this to inventory component right and uh we can't set controller to ignore here so we'll go and do that in the event graph as well so let's go ahead and jump over here and i'm gonna go and grab each of these set come uh controller to ignore there we go and we're just going to drag over our motion controller this is the right one hold on controller right and then we'll just want to do the same for our inventory component left set controller to nor there we go there we go so that will make sure that our correct motion controllers will actually ignore be ignored by our uh inventory components that we if we have something in our right hand it won't automatically snap to the right inventory component once we release it for holding something in the left in our left hand it won't be able to snap to our left inventory component it'll be completely ignored so we don't have to worry about that now the final part of all this is we just need to be able to grab and release our inventory cube that we made at the beginning so i'm just this is going to be quite simple i'm going to keep this quite simple so let's go ahead and start by unpressed we're going to want to do a sphere overlap actors go and fix that there and i'm going to go ahead and grab our motion tour left and we're going to base our spear position around the world location of our left motion controller so i'm going to go and drag that up uh the sphere radius i'm going to go in set to 20. i find that's a pretty good starting point personally um so i'll go and start there and we'll go ahead and make our object types here there we go and i want to set that to world dynamic and we don't really need to worry about our actor class filter or actors to ignore here we're all good there so i'll go ahead and on our out actors i'm going to do a for each loop with a break now the reason for the break is rather than checking to see what actors the closest or anything like that we're going to keep this nice and simple we're just going to find whatever the first actor is that is valid that we can actually use and we're just going to use that actor we're just going to break out and use that actor so we're going to want to check to see if it does implement interface grab grab on our loop body uh we'll want to well first we gotta branch this to make sure that this is true but in our loop body let's go and drag that over and then we're just going to want to grab our ray element here we're going to want to grab make sure it's the message there we go uh the motion controller we're going to go and pass through our left motion controller component here and then we also want to make sure that we hold on to this actor for the release so i'm going to go and grab this i'm going to promote this two variable i'm going to change this variable name though here in one second let me go and drag this forward and i'm going to call this grab left actor just like that and then we'll just go ahead and bring this back around to the break go and bring that up so we can more easily see that see that a little bit better there we go and finally we're just going to want to on our release we want to grab our left actor i'm going to bring that back up here and we'll just go ahead and release here there we go again we're going to want to bring our motion controller left into our input variable there and we also want to make sure that we set our grab left actor back to null uh and that is all that we need to do here um so i'm gonna go ahead and copy all of this oh i hit the caps lock go and copy all this bring this up here uh feed through our press feed our release and now we just have to change from most controller left to motion controller right go ahead and delete that i'm hitting all the wrong buttons today motion controller right don't grab that our target here however we need a grab right actor so let's go ahead i'm going to create a new one called grab right actor i'll make sure that this is of type actor so i'll go ahead and drag that in there we'll need to set our grab right after here and then just coming down here we will need to first grab our motion controller right here there we go and then we also want to set our grab right actor here and that is all the necessary changes that we need to make here there we go uh so now let's go ahead i'm going to go and compile save that jump into our scene here i'm actually going to close that as well and now i just want to drag in our inventory cube that we had made earlier so i'm going to go and take one drag it in here and let me go and scale this down a bit let's see is point one work uh let's do maybe point two i think point two should work pretty well and we don't have any sort of gravity or anything implemented on this so this will just float in the air i'm not gonna worry about putting a table or anything for now um this is just going to be very basic here so and i'll just leave the one that way we can work with this and i'll go and jump into vr and we can give this a test run you can see i'm now in vr here um so we have our inventory cube here and we have our inventory components here so that these are where this cube will be able to attach to so you can go and reach over and grab our cube here and if i go ahead you can see i can cross over no problem and i can release it and it snaps right to our inventory cube and i can go and just release it as normal and i can do the same with the other hand and no matter what i can drag over while it's released there it will not snap to our inventory component here so we have no problems using this and this can be attached to anywhere else i attach this to the motion contour component since this tends to be a pretty easy place to track um if you have it on like around your wrist or something this actually isn't where my wrist actually is my wrist is actually roughly right here um but this guy gives you a general idea of how you could go about attaching this to your motion controllers or maybe you have a skeletal mesh or something like that that you would like to attach to instead and this just makes things nice and easy and if you'd even like to you could even go a little bit further and have like a full vest or something that's underneath your that's attached to your camera and it's just always below it or something like that so you have a lot of different options of how you can go about using these these little inventory components so uh yeah there we go and with that that's how we set up a very simple inventory component that can be used in any vr game attached to either a player or any other actor that we choose with that i hope you enjoyed this video if you did be sure hit the like and subscribe button down below i also i'll give a quick shout out to my patreon supporters over here on the right and also i'll give a quick shout out to cass who made this really awesome artwork behind hit behind me credits to him are in the description and with that i will see you in the next reality
Info
Channel: VR Playground
Views: 4,096
Rating: undefined out of 5
Keywords: VR Playground, VR, Virtual Reality, Game Development, unreal engine 5 tutorial beginner vr, unreal engine virtual reality, unreal engine vr, unreal engine vr tutorial, unreal engine, unreal engine 5, unreal engine 5 vr, ue5 vr, unreal 5 vr, unreal engine 5 vr tutorial, inventory, inventory tutorial, inventory vr player, inventory vr, inventory unreal engine 5, unreal engine inventory, unreal engine vr inventory, ue vr inventory, Inventory for VR Player
Id: 1jUtN3S_3Ms
Channel Id: undefined
Length: 25min 26sec (1526 seconds)
Published: Fri Oct 29 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.