in this video we are going to take a
look at for each loops now these are a
special type of loop that is
specifically built to work with arrays
so to really show this off I'm going to
make a very simple array so let's create
a new variable I'm going to call this
robots and let's set it to a string and
we'll turn it into an array so a quick
little ray button and let's compile so
we can give it some default values so
we'll just give it four entries and
we'll do
cambot gypsy oh wait hang on cambot need
to hit tab to make that work there you
go
and then gypsy and Tom servo and crow of
course so we have the names of our four
robots let's go ahead and bring this
into our graph and I'm going to create a
loop to loop through these so I'm gonna
just type for each and the way a for
each loop works is it's simply gonna
take in an array and then for everything
it finds in the array it'll do something
and you can make that really anything
that you want it to be so let's go ahead
and connect this over to pressed and for
the loop body we're going to keep this
really simple let's just do a print
string and we can take our array element
and just plug that straight into the
print string and when we're like we
don't worry about when we're done let's
just grab this whole thing and we'll hit
C to make a comment we'll call this
robot roll call now let's just test this
out so we'll compile jump over to our
map hit play and when I hit F there you
go we get all four of our robots listed
off so that is really the crux of a for
each but I do want to take one moment
because that was actually a really quick
demo if you know how they work now and
you want to go ahead and close the video
off of course you're more than welcome
I'm going to make something just a
little bit more practical so let's
create some sort of elements in our
world that we can kind of look out for
so
we had some of these procedural walls
well actually you might not have
followed along with that video so we
won't won't do that right away let's do
um let's do particles I'm surely we've
got some smoke oh here we got fire and
we got steam oh this is great yeah let's
do some steam and we'll just bring that
into the map like so and let's do some
more let's do just little steam emitters
just sort of all over the place perfect
okay awesome
now if we take a look at the properties
for these guys these are currently set
to auto activate so we can turn those on
and off at any point so maybe we'll play
with that or we could just set rendering
on and off so maybe we'll do that as
well so hang on let's just go ahead and
jump back into our loops blueprint and
let's pick another key let's say the V
key and we're gonna do is create an
array that has all of those particle
systems in it and the way we're gonna do
that is to say get all actors of class
it's gonna ask you what class and we are
specifically looking for let's see we
have emitters boom emitter actors so
what this is gonna do is grab all of the
emitter actors and automatically store
those in an array now from that array
that we get we are going to say for each
we'll run a for each loop now what are
we gonna do as a part of this loop we're
gonna take each one of these particle
emitters and we're going to set
visibility well you could say set actor
hidden in game that would probably work
let's see we have yeah let's just try
that said this will say set actor hidden
in game and I just I'm tempted to try a
toggle do you think we do a toggle this
is let's do to what happens
so now we'll set them all to off that'll
be fine for now okay so let's compiled
and we'll set I'm sorry hidden to true
and then we'll compile and jump over to
our map and hit play and now what
happens we hit V boom all of our steam
disappears if we wanted to change that
system so that the steam reappeared we
could do this we could say connect this
up to a flip-flop and then simply take
is is a might work there I don't know if
that's gonna work listen let's try
storing a variable I feel I will feel
safer if that's a variable so let's just
do show/hide actually well we can call
it whatever we want let's call it show
for now and show should have a default
value of false the first time and then
the first time we run this we're going
to set will say set show to true
actually we could just do that boom boom
so that will just keep setting show for
us I think this should work let's try it
this should create a toggle that loops
through and turns everything on and off
but I really I'm kind of making it up as
I go so let's hit V B there we go I
think it didn't work the first time
actually I think I had to hit it two
times to make it work so let's see if we
took this guy oh yeah yeah so the
default value of show needs to be true
and that should be just fine
so play hide show okay well it does show
the point right so it's just simply
showing that we're marching through each
each index within the array now the last
thing I do want to mention though I'm
not really going to demo it you do have
the option of a for each with break and
that is the same as a for each it just
has the option to break out and stop the
loop if it's running a little rampant or
an under any other circumstances that
you like just make sure whatever it
causes the break to fire is executed
within the loop body so if you're if
you're not doing that then the break
will never actually fire so I'm not
going to demo that
because there is a video specifically
over a for-loop with break and it works
exactly the same way so that is going to
wrap things up for this video thanks a
lot