in this video we're going to talk about
creating your own custom types of loop
now this is not something you may need
to do very often and I want to throw out
a general disclaimer in this video I'm
going to modify an asset that is inside
the engine you do this at your own risk
uh if you follow along with what I'm
doing you shouldn't break anything but
if you do for some reason that is
entirely your risk so make sure you're
making a backup of things uh just in
case you get a little bit overzealous so
what I'm going to do for starters is
show you something what if we wanted a
loop that had a delay uh Loops can't
DeLay So if we had something like a
while
loop and as part of the loop body we
wanted it to uh stop and wait a few
seconds before it uh fired off the next
uh part of the loop body we can't do
that that's because a loop has to
complete everything
in between ticks what we can do however
is leverage the fact that all of these
Loops uh are macros in and of themselves
if you double click on a
loop you jump down inside the actual
blueprint uh graph that makes that Loop
possible so a while loop is really just
a branch and a sequence that are fired
off inside of a macro now I'm going to
talk specifically about macros a little
bit later in a separate video uh for for
now we're going to keep things really
simple we simp we have an input and we
have a condition the branch checks the
condition and if the condition is true
it fires off a sequence the sequence
first triggers the loop body and then it
wraps back around and checks the branch
again so the branch will continue
checking the condition and so on and so
forth eventually the condition will read
false unless you've made an infinite
while loop and then it fires off false
and that hits your completed output so
that is in a nutshell how the while loop
works now since that is within the
standard macros there's nothing stopping
us from making one of our very own so
I'm going to close this and let's get
this out of the way for just a moment
I'm going to go over to the content
browser and we're going to go under view
options and turn on the show engine
content
checkbox now with that uh let's go into
the engine folder and we'll search for
standard macros now I could have just
used what was already there I just
wanted to make sure I showed you how to
access these on your own so now we are
looking at the list of standard macros
I'm going to add a new macro and I'm
going to call this while loop with
delay so pretty simple so far now I'm
going to add some inputs to this so
we'll create a new input which will be
an execution input so it has its own
execution pin and we got to give it a
name so uh we could just call it space
and that that makes it blank so it looks
a little bit more like most of the other
inputs that we have now we need some
other inputs as well so let's click the
new button again and this one we will
call delay this is going to be how long
we want the delay to exist between Loop
executions this needs to be a float
value we'll add another input as well
and this will be the input for our
condition and we'll give this a type of
Boolean so really just a straightforward
will we run the con the uh the loop yes
or no now for outputs we're going to add
a new output which we will
call Loop body
and this needs to be an execution pin
and another one called
completed which is also an execution pin
all right now it's easy so uh let's
Branch off from our execution pin on the
input and we'll do a branch the branch
just needs to check our
condition if the condition is true then
we run the loop the loop is going to
consist of a
sequence and that sequence is first
going to fire off the loop body and then
normally it would just wrap back around
a branch but we're going to do instead
is create a delay and if you just try to
create a delay with context sensitivity
on you won't be able to so turn off
context sensitivity and suddenly it's
there boom there's a delay and we're
going to take that delay input and plug
that into the
duration now we'll take when uh once the
delay is completed we'll wrap that back
around to the branch and then once we
hit false on the branch we'll run to
complete it so it's it's a lot of
overlapping wires lots of stuff going on
here I'll try to kind of separate it out
a little bit make it a little easier to
see but yeah kind of a tangle so with
that we can go ahead and save let's jump
back over to our Loops we don't need our
little while loop here anymore but now
if we um actually let me show you
something else real quick before you run
away if we take a look at the while loop
entry here you'll notice it has a
category of utilities pipe symbol flow
control let's just copy that uh and then
we'll go back to loop with delay and
we'll paste it
in and for description we'll say while
loop that has a set delay between Loop
executions there we go now we'll save
once again so if we
rightclick and we jump down to
utilities and there's flow
control we will now see a while loop
with DeLay So we have have our very own
custom Loop so let's fire that off we'll
just hardcode a delay value of 2
seconds and for the loop body we're
going to do something really simple
let's just do a
print and I it can just stay hello
that's fine and I'm not going to
actually ever tell it to stop uh because
now that we have a delay in there it
doesn't have to keep executing in
between each tick so I can now get this
out of the way we can hit play and when
I hit the F key it says hello
and it looks like hello is never going
to go away actually let me change my
delay a little bit uh that's because
right as it goes away we spawn the other
ones so um let's do every one
second and we'll compile that and hit
play so when I hit F we just start
getting a little stack of hellos and
they're slowly rolling so the one on the
bottom disappears and scoots up and
another one Pops in beneath it but the
nice thing is that we have a while loop
that is running ramp ly it's just never
stopping however we are still able to
play the game because of that delay
because in computer time a second is an
eternity that's a whole lot of time so
that's a quick look at creating your own
Loops to do special things um they're
just under the standard macros if you
like any of the flow control elements
and you'd like to uh work on them or
make your own version of them you can do
that so like we could take uh just a
regular for loop with break
or there's the four Loop of break right
there so there's the uh the script that
makes that possible so nothing stopping
you from uh making your own version of
that if you wanted to so again that's uh
just what I wanted to show you a way to
make your own custom Loops that'll wrap
things up for this video thanks a lot