hey guys welcome back so in the previous
video we did our first bit of blueprint
scripting inside the level blueprint uh
which I still have up here at the moment
and inside our level blueprint we set it
up so that when the game is started uh
we toggle the visibility of a point
light that we've placed in our level so
here's our script and when the game is
started we call the event begin play
node anything that is connected to it
also gets executed which is our toggle
visibility and it's targeting our light
component and our Point light so in
essence when the game is started if we
simulate here our light comes on uh just
as we expect so uh I think that's a good
first step uh as our intro to blueprint
scripting we're going to take this a
little bit further though in this video
uh we want to add a little bit of
interactivity with our blueprint here so
that whenever the player enters our
little room here the light will turn on
and when they exit our room the light
will turn off uh just to make it a
little bit more interactable than having
it uh turn on automatically when the
game is started so let's go and do that
I'm going to close the level blueprint
here for a second uh because we need to
set it up to determine when the player
has actually entered our room so we have
no way of defining that just yet so we
need to set that up fortunately we can
do that with the use of a volume and a
volume is basically a three-dimensional
area of space uh but the the good thing
about volumes in u4 is that they are
aware of when something enters or exits
it which is ideal for our situation here
uh we're going to place a volume inside
of our room here when the player enters
our room he's entered the volume and
when they exit then we can uh we can be
notified through the events of our
volume that the player has exited the
volume so that's perfect for what we
want to do so let's hop over to the
modes panel and there's a section for
volumes that has all kinds of volumes
that we could add but for our purposes
we're going to stick to the basic
volumes so if we go to the basics tab
down at the very bottom we have a box
trigger and a sphere trigger these are
both volumes but they're just labeled as
triggers as these These are usually what
these volumes are used for uh generating
overlap events uh that can fire off
other scripts uh and things inside
blueprint so if you look at the tool tip
here it says a box shaped trigger used
to generate overlap events in the level
and that generate overlap events is the
important takeaway there of that tool
tip if I open our level blueprint again
here really quickly uh we are using an
event to start the to
visibility uh or to start our script and
call the toggle visibility node so we're
going to use a overlap event instead of
our event begin play to toggle
visibility so uh let's add our box
trigger going to go to the basics uh
basic section again in the modes panel
just going to left click and drag a box
trigger into our level here I'm going to
place it inside of our little room like
so and going to position it somewhere in
the center something like this should be
good I think that's good good enough uh
we're going to need to scale it up
because it is super tiny right now so
let's hit r on our keyboard to enter
scale mode let's grab the white box in
the center so that we get all of our
axes here and I'm going to drag to the
right to kind of scale it up in size
like so I'm actually going to select
this first wall here so our wall piece
here over in the world outliner I'm
going to hide that momentarily so I'm
going to click this I icon here to hide
it just so we can see our uh volume a
little bit better and it looks like it's
kind of penetrating our wall a little
bit which is fine uh so let's make sure
that our trigger is still selected so
I'm going to reselect it and continue
scaling it so I'm going to drag along
the X here and just scale it out to the
side something like this it's kind of
going into the wall again perfectly fine
is it going through the wall yet no I
think that's fine so I think this is
good that's good enough we could hit W
and kind of move it over a little bit so
it clips into the wall like so
and we can also drag it up a little bit
along the Z here so let's drag it up
into the air like so something like this
and I think that's good I think that is
pretty good we could actually if we
wanted to we could move it back a little
bit more so that it kind of is flush
with the edge here but I think this is
fine if you want to you can go ahead and
do so but I think this is fine the
player is in the door frame and not
necessarily in the volume like so they
won't necessarily trigger it but I think
I think that's good let's go ahead and
continue uh so I'm going to go back to
the world outliner here and I'm going to
unhide our wall door here so that we can
see it
again and now we can start working on
the blueprint script for uh the events
that are fired when the player enters or
exits that volume that we just placed so
uh let's go ahead and make sure that in
the world outliner the trigger box is
selected and then let's open our level
blueprint again if you recall it's from
the blueprints option under level
blueprints let's go ahead and open our
level
blueprint and with it open just as we
did with our Point light now our level
blueprint is aware that we have our
trigger box selected so if we right
click in the graph it's going to give us
some options here right at the top uh
that pertain to this uh trigger box it's
going to give us the ability to uh
create a reference to it uh call
functions on it but at the very top it's
going to give us the ability to add
events for it which is exactly what we
want so let's go and click the uh little
expand icon here to expand this section
and there's a couple options in here
we're only focused on collision and
collision is used to determine when we
collide with objects in the world so
when we collide with our volume so go
and select that and there are the two
overlap events that we want to add
there's a third option here for on actor
hit we're not going to worry about that
for now we're only focused on the begin
and end overlap so let's start out with
the on actor begin overlap so go and
select this one here it's going to add a
new node to our graph instead of our our
graph here let me actually make this
just a little bit
bigger so uh we have our new note on our
graph and I kind of wanted to explain
something here really quickly or not
necessarily explain it but point it out
if you haven't seen it noticed it
already look at our on actor begin
overlap node here and look at our event
begin play they both have this red
border across the top of the node this
signifies that these are both events so
anytime you see a node with a red border
across the top it is an event so it's
just blueprints way of kind of help
helping you visually understand what's
happening inside your graph uh from a
glance there if you look at the toggle
visibility node if I zoom in a little
bit has the blue border and it also has
an F next to it this lets you know that
this is a function node so uh just
wanted to point that out in case you are
saying well why are some red why are
some blue uh these two nodes are events
so uh let's go ahead and continue let's
actually select the event begin play
here we're actually going to delete this
because we're no longer going to be
using it so going to delete it going to
take our on actor uh begin overlap here
I'm just going to move it up here just
left click and drag and move it up here
like so and going to take the executable
out just left click and drag off of it
and plug it into our toggle visibility
making sure we get that green check mark
and believe it or not our script is done
whenever we enter our trigger volume now
we will toggle the visibility of the
light we can compile here and before we
test this I kind of wanted to point
something out in case you were wondering
what this other actor pen is uh this
will allow us to determine what actor
actually overlap the trigger volume so
if we got into a more advanced version
of this blueprint we could determine say
the type of actor that will only be able
to trigger visibility for example we
could have if our character could fire a
projectile and whenever they fire fire a
projectile they are spawning an actor in
the world that could potentially overlap
this trigger volume now we don't
necessarily want the projectile to
toggle visibility so we would drag off
this other actor here and run a check to
see is it the character that overlapped
the uh trigger volume or is it something
else if it's the character then go ahead
and toggle visibility if it is not the
character then we would not toggle
visibility so I kind of wanted to point
that out in case you were wondering what
this was uh that's what that other actor
pin is
for so our script is set up uh let's
actually I'm G to drag this down just a
little bit kind of try to keep it in
view here working with the limited one
screen space that I have uh before we
play inside the level here I want to
select our player start here and just by
left clicking and I'm going to grab this
Green Arrow and just drag him back a
little bit so he's not starting inside
the room so uh if we play in the editor
now what we should see is our light is
off by default as soon as we enter our
room the on actor begin overlap node
will fire turning on our light if we
exit the room because we have not set up
the script yet the light will stay on
which is fine for now if we went back
into the room however the on actor began
overlap we get called again and toggle
the visibility ility thus turning the
light off at that point so let's go and
test this uh let's click the drop down
here uh from the play option and let's
play in the selected
viewport and our light is off and if
you're watching our screen here uh watch
the nodes at the bottom uh of our screen
here as we enter our room so I enter our
room the on actor begin overlap gets
fired and turns on our light soon as we
exit nothing happens because we haven't
set that up yet but once we enter our
room again the on actor begin overlap
will get fired again turning our light
off so our script is working we are
about halfway there now so uh let's go
ahead and continue and finish off this
portion of script here so I'm hit
escape and kind of minimize this or
stretch this out just a little bit more
us a little bit more room uh let's make
sure that our trigger box is selected
inside the
level and inside of our graph we're
going to right click again and we're
going to add another event for the
trigger box under collision and this
time we're going to add the on actor end
overlap so let's go and select this like
so again there's that red event
node let's take the executable and let's
plug it in left click and drag and plug
it into our toggle visibility now we can
plug both of these events into this
toggle visibility because only one of
these are going to happen at a time as
soon as we enter our volume this will
get fired and call the toggle visibility
uh as soon as we exit this this will get
fired and again call our toggle
visibility so our script is complete we
are set up and ready to go let's go
ahead and compile uh before we uh test
this there's one thing that I wanted to
point out uh really quickly especially
if you're coming from a ue3 background
uh regarding uh events and kind of an
order of operation thing uh explanation
uh with blueprints so going go ahead and
hop off screen for just a second um
bring up my quick little PowerPoint it's
only two slides it's very short promise
so uh what I wanted to talk about really
quickly here is in ue3 in Kizmet you
could create a event similar to what
we've done just now uh and this event
could be entering a volume and turning
off so you can turn off on and off a
light Etc uh in u3 you can have an event
that fired off multiple actions at once
so this one event would call a bunch of
different actions uh to occur the
problem with doing it this way though in
u3 is that there was no guarantee in the
order of operations in which these are
performed so any one of these scripts
could get executed uh in a particular
order that could be problematic
especially if you're trying to do
scripted sequences and you want things
to flow in a logical order or in
sequential order so say for example we
wanted this action to uh fire first so
when our event is fired we want this one
to fire first we want this one to fire
second and we want this one to fire
third there was no guarantee in u3 that
it was going to uh function that way
whenever this event was called and that
was problematic so that brings us to
blueprint uh in
ue4 uh the way we do things in blue in
Blueprint to get that functionality is
uh first of all I changed the name from
action uh to functions because that's
what they are in u4 they they were
there're still actions under the hood I
guess but we call them functions because
that's just the more standardized way of
of referring to them uh what we would do
is we would set it up in a logical
manner here from left to right we would
have our
call our first function and then after
that first function is done we would
call our second and our third Etc this
is the the natural flow the uh I guess
the sequential flow is the best word I
can describe it uh for blueprints in ue4
in order to get that functionality you
would have to set it up in this manner
so that the event is fired the next
function that you want to happen would
occur and then the next then the next
and so on there's no way to uh set up an
event that fires off multiple functions
at the same time everything in u4 in
Blueprint is sequential firing so I did
want to mention that now there is a
special node that we're not going to get
too much into we probably not going to
touch it in this video series uh there
are some other blueprint quick shots out
there uh that we cover uh this
particular node and in using it there's
a sequence node where you can kind of
change up you can Define the sequence as
the node suggest uh in which you want
your scripts to fire uh we're not going
to be touching that in this video but I
did want to mention that traditionally
and and I'd say most of the time uh when
working inside of blueprints your
scripts are going to fire sequ you want
to set them up so that they fire
sequentially so that your order of
operations flows in this particular
manner so kind of wanted to touch on
that really quickly in case uh uh you
start working with blueprints a little
bit later you have this frame of
reference when setting up your
blueprints uh to to keep in
mind so let's hop back to u4 here and
let's actually test this uh
our uh setup here so I'm going to hit
play play in the editor and keeping our
uh blueprint on screen here so when I
enter our light comes on there's our
light and when I exit the on actor in
our laap should fire as well which it
does and it turns our light off so uh
our script is working we can turn it on
and off as we enter and exit our room
now there's one more thing that I wanted
to do before we wrap this uh video up
here let's see we are about 15 minutes
in so let's do one more thing before we
close out this video and and finish
working inside the level blueprint so
what we're going to do now is our light
turns on and off but we want to add a
little bit of a delay before uh it turns
on and off and again blueprint is pretty
smart it Prett kind of knows what you
want to do so uh what we could do is
let's let's take our on actor begin
overlap here and let's drag off of this
wire this executable left click and drag
and you see we can place a new node off
of this so let's drag drag off and
release and inside the executable
actions here uh let's search for delay
because we want to add a delay and right
there under flow control we have a
couple options we have a retriggerable
delay but we also have a standard delay
as well uh let's go ahe and choose the
normal delay here we could use a
retriggerable delay for more complex
blueprint but for our purposes the
standard delay will work just fine now
when we select this function again
there's that F next to delay when we
select this function watch what happens
to our graph uh inside the level
blueprint it adds our node for us and it
automatically reconnects it to our
toggle Vis toggle visibility so it's
created a node in between those two
blueprint says oh I see what you were
doing you're trying to add something
before this happens so I'll let you add
it and then I'll reconnect uh the rest
of your network so we have our delay
node now and it's currently set to a
duration of 0.2 seconds that's a little
little too fast let's set this to say
0.5 so about half a second so when we
enter our trigger box we'll get a half
second delay and then we'll toggle the
visibility let's do the same thing for
the end overlap I'm just going to slide
this over here and I'm going to select
our node here make sure that our delay
is selected going to hit control C and
down in our graph here I'm going to
click in a left click in an empty space
and hit contrl V so you can copy and
paste nodes inside of blueprint as well
so we have our second delay here and I'm
just going to reconnect these so I'm
going to take the X executable plug it
into the delay and take our completed
and plug that back into our toggle
visibility so uh let's compile and let's
test this now we should now get a delay
uh for triggering our light when we
enter our room here so I'm going to
play and again you can see in our graph
down there at the bottom you'll be able
to watch this in real time so if I enter
our room it gets fired and a delay
happens and then it triggers our
visibility as I exit gets fired a delay
and and then it fires our visibility
again toggle visibility again so one
more time we go in the delay and we exit
and a little bit of a delay as
well so there we go that is uh that's
going to do it for this video uh again
we've been working inside the level
blueprint and wanted to mention it one
more time just to kind of drive it home
before we stop working uh inside the
level blueprint here the level blueprint
is excellent for scripts that need to
consist within a single level uh any
that you want to do uh in multiple
levels uh you're going to be want to be
you're going to want to be working
inside of a class blueprint for that uh
and we're going to get into that in the
next video uh because the level
blueprint is self-contained anything
that we do here is going to reside uh
anything that we do inside the level
blueprint is going to reside in this
particular level so this whole setup
that we've just set up right now our
triggerable light and little room here
uh if we wanted to duplicate this in
another level we would have to copy all
these assets over to that new level uh
which we could do uh but uh we would
probably want to set this up as a class
blueprint so that we can drag and drop
this in any level that we want and it
will just work and we're actually going
to start doing that in the next video so
uh let's go ah and pause here and we
will pick it back up in the next video
when we start working with class
blueprints uh thank you guys for
watching and we'll see you then