alright so in the last video I showed
you how for loops work and that was
really cool but really all we were doing
is printing stuff out to the screen what
I want to do now is take just a second
kind of as an added bonus and show you
something pretty cool and pretty
practical that you can do with 4 loops
so I'm doing this completely off the top
of my head with no notes I'm gonna
right-click make a new blueprint make an
actor and we're gonna call this
procedural wall we're gonna make a
procedural wall system and it's gonna be
amazing and you're gonna be really happy
about it so let's see here we are in our
components list the first thing I'm
gonna do is add a scene component this
is honestly this is it for the most part
just habit for me and we'll call that
route now over in the content browser I
have the starter content so I'm gonna go
under architecture and I'm gonna grab
this pillar here so it's a little fifty
by five hundred pillar and I'll drag
that into my component list and we'll
call this base wall and what we'll do is
we'll just copy this over and over again
in order to make our wall actually
happen so there we go that should be all
we need
let's go ahead and jump over to the
graph and I'm gonna show you more things
than just loops so we're gonna do
something that's kind of sort of fancy
we're gonna create a new variable and
we're gonna set its type over to a
vector and we'll call this end point and
we're gonna set it to be editable and
we're going to show its 3d widgets and
let's give it a tooltip let's say this
is the end of the wall with an
exclamation point because that makes
tooltip superior okay so if I drag this
out of the way and let's go over to our
blueprints list blueprints folder excuse
me we can bring in procedural wall and
it has that little endpoint variable
which we can click on and we can move so
that's the literally the value for that
endpoint right there okay cool now we
need to make that do something what I
want to do is drive everything inside
the construction script that way we can
move that endpoint around and make our
wall get bigger and smaller right there
live in the editor now the first thing I
want to do is
bring in my endpoint I'll get a getter
because I want to pull some information
from it and we're gonna make sure that
it is not equal to zero so I'm just
gonna hit the exclamation point and grab
a not equal node and if it's not equal
to zero let's fire off a branch I can
plug that into the construction script
really all we're doing here is we're
saying if we are not equal to zero then
we're gonna do stuff if the end point is
equal to zero then it hasn't moved and
we don't really need to do anything so
it's kind of a check and balance to make
sure we're not doing anything we don't
necessarily have to also I'm gonna take
the end point and we're gonna drag a
wire out from it here and we will
multiply it by another vector and I'm
going to multiply it by one for X 1 for
Y and 0 for Z because I don't really
want the vertical side of it to even be
calculated I don't I don't care about
the vertical elevation for that little
endpoint so again we're just we're gonna
leave that plugged into the first entry
for not equal two and there we go ok so
now next thing if our branch is true
then our little endpoint has been moved
somehow because it is no longer sitting
in relative zero zero zero so now we
want to run a loop and this must be a
regular for loop we're not gonna worry
about what the loop does yet we're gonna
worry about how we figure out the loop
now as a reminder my little pillar that
I used my little pillar it is it has
dimensions of 50 by 500 so we know that
it's 50 in width and 50 in depth and
then it's 500 tall so let's use that to
our advantage what we're gonna do is
grab the endpoints so let's get another
copy of that I'm certain that ctrl-c
ctrl-v it'll just keep wires from going
everywhere and I'm going to get the
vector length there's a node that will
do that and that is just going to return
a float value that represents the length
of this vector which is perfect that is
exactly what we need we are then going
to divide this
by 50 which is we what we know is our
dimension for the pillars now if that
needed to be a variable like if that had
to be influx you could make that a
variable and you could set that to be
like the bounds of another mesh or
something we're gonna keep this simple
we know our pillars 50s or just gonna
divide by 50 then we need to round this
down and the easiest way to do that well
we're kind of just gonna truncate it so
let's just run a floor on it and that
will output an integer so if we had a
value that was like three point seven to
nine we're just gonna get three and that
can become our last index we'll take our
first index and just set that to one all
right so that's looking pretty good so
far
now I need to figure out what we're
gonna do to create our wall well we need
to start making static meshes so let's
see do we have our little pillar over
here selected it looks like we do so
let's right-click and we will add static
mesh and you'll see there's add pillar
50 by 500 as static mesh component boom
perfect now we do a couple of fancy
things we're gonna connect that to the
loop body because each time the loop
runs we want it to create another one of
these and we're going to set it to be
manually attached that means we need to
okay well I guess I should step back
this is being added as a static mesh
component literally a part of this
blueprint another component we're gonna
set it to manual attachment which means
we must manually parent it to something
else in our blueprint components so
let's go ahead and do that next so here
is the component that just got created
so we'll say attach and there's an
attached to node so that's what we want
the in parent is going to be the base
wall that is that first little wall that
we created that's already there the
attach type it almost doesn't matter but
I'm gonna set it to keep world position
anyway now the last thing we need to do
is move this into place so we've created
it we've parented it to the baseball now
we need to move it into its appropriate
position that should be fairly easy
because we know that it is 50
it's wide now we can take that 50 units
and we can multiply it by our current
index of the loop because the first time
the loop runs the index is gonna be 1
the next time it runs it's gonna be 2
and 3 and 4 and so on and so forth so
let's just start by multiplying integer
by float and we're gonna multiply this
by 50 the reason I chose a float is that
that's automatically going to convert my
final value to a float that's super
useful for me because I'm going to use
this and make a vector and we'll use the
x value there then we're gonna take the
result of this vector and use it
actually let's just take our return
value here off of our add static mesh
and we will say set relative location
I'll plug that in that'll be the last
thing in our chain and this can be the
new location now this should already do
something we should probably go ahead
and test it you see it's fairly simple
so far hasn't been too hard to put
together let's compile I window out
actually you know what let's put this up
here on the tab I can just jump between
the two that'll be nice and easy and
it's already doing something let's take
our end point and as I drag it out check
that out we're getting more and more
wall segments depending on how far away
we move the end point which is cool but
it would be nicer if the wall was
actually rotated to snap to the end
point so let's fix that next so jump to
the back of the procedural wall and we
could comment all of this we could say
all this and then hit C and creates new
wall segment based on distance of
endpoints
now once the loop is completed by the
way if you see an error on your loop
always hit compile because it may may or
may not be a real error so we'll go
ahead and when we're completed the last
thing we want to do after we've finished
creating and parenting and doing all
that fun stuff is then we'll handle our
rotation so what we're gonna do is
rotate the base wall so let's get that
and we will actually just drag a wire
off of that and we'll say set world
rotation like so and we'll just plug
that in now what are we gonna set it to
that's the real question well we need to
figure out the rotation that is
represented from the start point of the
actor to the end point that way like
what would we have to rotate to if the
end point was moving around like so how
would we make that happen well the good
news is that's pretty easy to do we just
need a little bit of vector math we're
gonna start with the actor location so
we'll say get actor location and then we
need the end point and from the the
actor location we can say find look at
rotation so you can literally feed that
a start point and end point it's kinda
like saying stand at the start point and
look toward the target and then feed
back the rotation required to to look at
that now for the target we're going to
take the actor location and we're going
to add that to the end point
like so and that'll give us the rotation
that we need then we're actually going
to break that and all we're gonna use is
y'all
we don't want pitch and roll so I'm
gonna take y'all and right now we're
gonna make a rotator so in essence
that's just nullifying pitch and roll
and we'll plug that into our new
rotation and let's compile and let's see
we good oh it looks like it's already
working so now if I take the end point I
can just move it around and I get a
little auto wall that just fits
perfectly into any given location I can
take the original point and I can use
that to position the wall like so so we
can slap that right over here we can
take the end point and let's just kind
of cordon off this section we don't want
anybody coming over there
cool and once that's ready we can hit
play and check it out we have a wall and
it looks just like a regular wall boom
can't move through it it's pretty
awesome you see there's a couple little
shadowing things with this approach like
as you get distant you can kind of see
the gaps in the shadows but yeah it
shows how you could go about doing this
honestly if I was creating a setup like
this I'd do it for like a picket fence
or or something like a railway I
wouldn't necessarily do it with a solid
wall like this but it is pretty cool cuz
for a solid wall you could just scale
the object right and that would work
just fine but this is a nice way to kind
of go about proving the point so I guess
one other thing we could do just cuz
that yeah okay I want to show one more
thing let me jump back into the
blueprint you can't close the video now
if you really want to if you feel like
you've learned everything you need to
learn let's go back into components and
I'm gonna swap out the base wall with
another mesh let's do the one that has
the doors in it we go under there we go
so wall door 400 by 300
let's see 400 by 400 I like the tall
ones better so we'll do that and then
let's go back over to our graph and that
is also adding in that guy so
static mesh oh well I mean go ahead make
sure I select that one so let's jump
over to Architecture and 400 by 400 make
sure we have that selected and then over
in our blueprint we can right click and
say add static mesh boom and I'm just
gonna replace this guy we're gonna say
you go there you go there you go there
and you go there then I can remove this
one out altogether make sure we reset
manual attachment now we do need to
update our width so we know that's 400
so I'm just gonna hard code that's 400 I
mean at this point probably you gotta
just set that to a variable so you could
adjust it later but you know the drill
at this point all right cool and it's
already working so now as I take my
endpoint and I increase it out we get
more and more copies of the wall that
have doors in them which is actually a
little cooler to show off in this case
because you can use those gaps right so
you can run in and out of each one so
now you've seen a practical approach to
using for loops to create procedural
elements for your levels that is going
to wrap things up for this video thanks
a lot