Alright, everybody. This time we're gonna do something fun and we're going
to take the basic VR template and I'm going to show you how to make a very
simple menu for navigating or doing whatever you want in virtual reality
virtual reality has some special concerns so we're gonna do a menu that's
specific for that and I've already set up some things basically for my menu
button I'm just gonna put this sphere which is this sphere here I just dropped
it into my scene and then you can see I put a simple trigger box around it
another thing that I did was I took the motion control or BP and I added to it a
pointer if we go into it b.p motion controller and go into the viewport you
will see there's the VR hands but what's different about what I've done here is I
added a static mesh element and it's a child of the hand mesh if I turn it on
if I go to pointer make it visible that's what it looks like I think it's
20 feet long and it's just right there in the hand
can of course add your own static mesh by going here to add component static
mesh right there and you can child it to whatever object you want by dragging and
dropping it okay so I'm not gonna keep that one I named this one pointer so I
can find it easily I want it invisible to start with so
that's what I did here to modify the BP motion controller which is standard with
the VR template okay over here what I've set up is just a box trigger and I have
my button here you need to make sure that the sphere static mesh has a
collision on it right so you can see my collision there and you need to make
sure that also the pointer that we add to the motion controller has a collision
on it I set this one if I go into the blueprint and look at the sphere we set
it to collision preset of trigger make sure it generates overlap events okay so
these are basic setup things so that when we point our hand that's attached
to the motion controllers at this trigger box that lays
Poynter will turn on and also it will know this sphere will know when we're
hitting it with the laser pointer as well which will enable us to navigate
our menu so right now I have it set up I'll show you an example and then I'll
tell you how I did it so if I hit play
okay here's my right hand I will navigate over to here and as you can see
as I point inside the trigger box my laser pointer comes on letting me know
that I can select something over here and as I hit the button it changes
materials okay so I'll take us to that point with scripting and then we'll make
it actually do something right now if I click nothing happens I'll show you how
to do that as well okay so the coding that we did the blueprints that we did
are going to look like this if we turn this into a blueprint and then go into
edit blueprint go into event graph here's everything I did I will delete it
actually let's look at it for reference it's just detached attach detach so
there's the amount of code that we did and I'll go I'll walk through it all
with you right now so that we can figure it out together so the first thing we
need to do is get a reference to our controller so that we can grab the
pointer which was there and then just set its visibility and we did a few
other things too I'll show you that as we go so first we get all the actors of
a class which returns to us an array of all actors of a certain blueprint type
motion controller pawn is what we want as our blueprint and that will give us
an array right here of all the motion controller pawns of course there's only
one so we'll take that out of there take out of our array and say get index
number zero which is the first one in our array and there's only one so again
that is the motion controller in our scene that's what we want from there we
will say get right controller because that is the right hand motion controller
that's the one we want and that's the one we want to be able to select our
menus that's the one that love the laser pointer showing okay so from there we
say get another component of this variable get static mesh no get pointer
because we named it pointer so we could find it again
so now we've got a perfect reference to the pointer that's within that motion
controller pond if I look in the motion controller pond you'll notice that there
is a variable in here at left control and right controller and those are the
ones that we were referencing so that is just a blueprint motion controller
called right controller and it's set to be the right hand so all we did here was
nope not here this one all we did was grab that variable right controller and
then grab the the pointer component of it which is the reference that we want
exactly and then we say set visibility of the pointer check it to be on and
then we can just drag this executable to right there so now we're setting the
visibility of that pointer to be on and the target object is got gotten here
through the motion controller BP okay perfect the only other thing I want to
do is check to make sure that that is the right object that is overlapping
because we're saying when it overlaps with the trigger box turn on this laser
pointer we want to make sure it's actually the laser pointer that's
overlapping and not some other object because we wouldn't want to like throw a
ball at that trigger box and it turns on our laser pointer right so right here we
have the actor that is overlapping that's a reference to it right there we
can drag it out check that it is equal by doing the equal object check that it
is equal to this right controller here okay make sure those two things are
equal so we're saying okay it's got to be the right hand some some element of
the right hand that is intersecting and if it is then make it this happen so we
actually need a branch in here branch and we're checking the condition that
both of these are true or both of them are equal to each other you
that is true if they are both equal to each other then we'll set the visibility
okay there we go now the only other thing we need to do is when it's not
overlapping anymore wait we did this all in the end overlap that is not what we
want we want begin overlap obviously so let's rewire that to be like that and
on end overlap all we're going to do is copy this visibility execute turn off
visibility and then the target is going to be the same target we have here so we
can just drag it like that so now when we overlap that pointer will turn on as
long as we're overlapping with the right objects and when we stop overlapping it
will turn off again so compile and save let's make sure that's still working
perfect okay so the next thing is the sphere which I showed you how the basic
setup was let's go into the blueprint of it and what we did here I won't show you
how to do this because it's very simple all we do is say event begin overlap we
take the static mesh component here well let's show you real quick okay this
should happen automatically you just say set material drag out and say set
material and it gives you in parentheses the static mesh component of this
particular blueprint which of course is the sphere right there okay and we said
I set it to something that comes default in the VR template and it's called M arc
end point it's that glowing blue material okay so there you go and then
on overlap on end overlap we did the exact same code except change it back to
basic shape material okay so as that pointer is overlapping and we could
again set it to make sure it's the laser pointer that we want that is doing the
overlapping but I'm not going to worry about that here we can just leave it
simple make it so that when anything overlaps this thing it changes to blue
and when it's not being overlapped it changes back to white so compile and
save we know that one working okay now how do we click that
button let's do it a really simple way by setting up a variable in this button
that when it's overlapped when it's glowing blue like we were just seeing it
sets off a variable to say true and then in our motion controller pond what we'll
do is say if we pull the trigger while that variable is true then take us to
another level or quit the game whatever we want our menu to do okay I think
that's a pretty basic and simple way to do it so let's go ahead and do it that
way of course you can get much more complicated if you have a bunch more
buttons but I'm gonna show you basic functionality here so button blueprint
let's go into it and we'll say we're not only going to set the material but we're
gonna set a variable we create a Barret variable here let's call it button is
overlapped okay and we will make it a booming right there and we'll set it to
if you compile then you can set the default value of it we'll say the
default value is not overlapped right so it's not true it's false here we will
set it to be actually that's just drag and drop it in here set okay as that
thing gets overlapped with the laser pointer we will set it to true button is
overlapped and here we will set it to false again okay so when we're not
overlapping it goes back to false when you are overlapping it goes to true okay
there you go now we need to call on this from our motion controller and say when
we pull the trigger on the right motion controller check this variable and if
it's true I want you to do something okay so compile and save this go to the
motion controller pond just kidding I don't think it's in the motion
controller pond weight hander handle controller input yes it is right here
input grab right okay we already this is all the default stuff okay so we already
have input grab right that's going to be the trigger button for the right motion
controller right now it's grabbing an actor and releasing an actor when
let go so we want to keep all this but we want to put a branch in here to say
if this variable is true then do something else so first we need to get a
reference to that variable we can do that in a couple different ways let's
let's detach these and then just go from here we can go to the button get all
actors of a class again now this is where it could get complicated if you
have multiple buttons but we're just grabbing a reference to the one button
what did I call that thing button what is called button blueprint button
blueprint okay so that's grabbing the one reference to that one button in our
scene and making an array of one so let's get index zero obviously the first
one the only one and then we need to get that variable get button but ten is
overlapped okay we need to get that reference right there and then we need
to just put a branch out of here to check if that thing is overlapped if
it's true then we want to do something if it's false we can just grab an actor
like normal right and the released one can always remain without a branch okay
branch if it's true let's just say quit game that'll give us a very obvious
feedback whether our button is working or not so quit game if that is true okay
button is overlap quick game true file save let's go see if that works okay
everything's still working let's try and pull the trigger okay it looks like we
quit the game everything worked perfectly now obviously you can make
that button do whatever you want and we made it quit and it worked so that could
be a quit button it could be a take you to the next level button it could really
trigger any blueprint that you want so it could make an object over here
explode if you wanted to but the the important part is the laser pointer I
think and the ability to click buttons in VR as
you're just navigating around your scene that's pretty cool and obviously you can
get a lot more complicated when you have a whole bunch of buttons so you'll have
to grab them in different ways than just grabbing an array of one like we did but
uh the simple functionality of creating a VR menu isn't really that complicated
so hopefully that's helpful to you guys hopefully you take it and run with it
and create all sorts of cool menus and buttons and navigation thanks for
watching