in this video I want to talk a bit about
arrays now arrays are a special variable
type that is actually more of a list
than it is a single value they're very
easy to create we're going to talk about
how to create them here in just a few
minutes but I want to get a few rules
down about arrays before we move in so
we've got probably one of the most
important things is that all entries or
all um all elements in within an array
must be of the same type and the reason
for that is that an array is really just
a single variable that has a bunch of
pieces of information in it an easy way
to think of an array is like a series of
mail boxes so we could just draw out
some really quick boxes here and I'll
try to keep this simple and we'd have to
give this array a type and we already
talked a bit about variable types in
earlier video so let's say this was a
string array and it could have names in
it so we could have like Bob and Tom and
Bill and cat and I don't even know so
Zach because I have to be in there
somewhere and Reggie because you know
because it's Reggie so all of these must
be at the same time these would all have
to be strings it's not like you could
remove Zach and have an object value in
there like you couldn't stick some
blueprint in there it would have to be
actually a string value now so they must
all be the same type next rule is that
arrays are dynamic what that means is
you can't set any any locked number of
boxes or entries into your list that can
change during gameplay so right now I
have six names in my string array but
there's nothing saying that during
gameplay I couldn't add another box if I
wanted to and put another name in there
there's also nothing saying that I
absolutely cannot remove an entry and
have
one fewer box so the number of entries
within an array is not a locked thing so
that makes them dynamic also arrays have
index values and that's kind of like a
way for the computer to know what entry
in the array you're talking to now these
are zero based which is important to
keep in mind so in an array like this
we'd have zero one two three and four so
if you asked the array hey what's in
entry 3
you'd get cat in this case so those are
some rules to keep in mind about arrays
now let's talk about how we create them
so I'm going to jump over to unreal and
I've got a very simple actor blueprint
here that I'm going to create an array
within so let's go ahead and click on
the new variable button because again an
array is just a type of variable so
create that and let's give this a name
we'll call this my string array and I'll
set the variable type over to string and
it's really this button right here at
the very end that looks like a little
colored grid line that is going to
determine whether this is an array or
not so when you see the little grid
there that means it is an array if we
compile this we can take a look down at
the default values and we can start
adding elements to the array so there
you can see it has zero elements at the
moment so we can hit the plus button add
one so let's do let's see let's do some
names again we'll do something totally
unique that you've never heard of before
and in no way is meant to represent
anything you've ever heard of and we'll
add another one
all right so we have cambot gypsy Tom
servo and crow again two four totally
unique names we've probably never heard
of in your life so what I'm going to do
now is bring my array into the graph and
I just want to show you a few things
about working with arrays because again
this is not a single value this is a
list of multiple values that means a lot
of the functionality a lot of the things
that you typically do to single values
will not work on an array unless you
know how to work with them I'm going to
talk briefly about that I'm going to do
something a little bit hacky here I'm
going to jump over to my defaults make
sure that auto receive input is sets
player zero just so that I can press
buttons and make stuff happen let's
right-click and I'll tap F and we'll
make some things happen when I press the
F key so let's drag out a wire into
space and I'll type log and that's going
to create a print string now this is a
string array so at the top of your head
maybe you might be thinking I should be
able to just plug this in but the answer
is no because the system has no idea
which entry in the list you actually
want to print out if you wanted to print
everything then you would need to run a
loop on this array looping is something
that I'd like to talk about separately
so we're going to keep things fairly
simple for now I'm going to drag a wire
off into space if you take a look under
utilities and then under array you'll
see that we have a for each loop and a
for each loop with break again looping
is something we're going to handle a
little bit separately so jump under
variables default and there's the entry
for your actual array and then we can
also call some functions so if you go
under call function expand utilities
there's some array functions here and
this is where you can really start to
work with your arrays and make changes
to them so the tooltips are going to
help you understand what each one of
these things does for the array so you
have things like a depend array which
would again add an entire array to the
end of your existing array some things
that are probably really important for
you to know would be like add and get so
that will actually get a value from the
array
there's also last index versus length
we'll talk about that a little bit more
once we get into looping but a lot of
folks want to know how many entries are
in their array that would be length
if you want to know the index value for
the last entry in your array that would
be last index so if you played with
looping before perhaps in code or in
scripting you would understand why you
might actually want to use last index
because it keeps you having to do length
minus one when you're trying to perform
a loop you don't get that don't worry
that's something we'll talk about
separately now I do want to mention
you'll see that the little F's for
function are color-coded in this case
that has to do with pure versus impure
functions so a green function is going
to be pure a blue one is going to be
impure all that means is that a green
function is not actually going to affect
the array while a blue one or an impure
one really will so let's keep this
simple we're going to grab a get and I
want to unplug this for just a second to
show you something notice that this node
is completely gray it's not grayed out
it's not like it's just not going to
work for you the color coding on it
disappears because this is actually a
wild card value now you'll only see
these really for the most part within
arrays you see there's a the tooltip
says array wildcard what that means is
this is waiting for whatever type you
plug into it and then it's going to work
with that type really quickly I'm going
to add a new variable and we'll call it
my int array and I'll set its variable
type over to integer and we'll just drag
that into the scene really quick let's
connect this up and you'll notice that
my node turned that teal color
so again this is just waiting for
whatever type you plug into it now let's
plug in a value between zero and three
again we have four entries in our array
right now so let's set that to three and
we'll plug that into print string
compile and we have a copy of the blue
print in the level so I'll go ahead and
hit play and if we hit F there you go
you see we are printing out kro at the
very end now that's about as far as I
want to take things in this lesson just
keep in mind that at any point you can
drag out a wire and if you take a look
under call function utilities array
you'll see all the different things you
can do to an array what I guess one
other thing I could mention is there are
several functions that you will perform
that will output arrays and it's
important to know that so as a really
fast
kind of
way to wrap that up let me bring in
several static meshes so here's a static
mesh and we'll make a duplicate of that
and a duplicate of that and let's grab
all three of these guys and we'll make
even more duplicates so we've got a
total of six now meanwhile back over
here in our graph let's nuke this stuff
out we don't really need it and I'm
going to right click and let's say
actually let's do get all actors of
class so we're going to say get all
actors of class and what class are we
looking for let's do static mesh actor
and notice the output of this get all
actors of class is an array so that's
important to know because right now if
we wanted to do anything to that array
we'd have to get something out of it so
we could say get and we could get
something say at index 3 and now we have
access to whatever mesh was in the third
index there I will also point this out
very very briefly before we go when when
you have lists of actors like this or
actor arrays you have a certain degree
of functionality that you can perform on
a for each basis so if we take a look
actually let's go under our function
suit so you can see call function for
each and there's several different
things we can do for example if we go
under utilities and orientation we could
say take the actor's local rotation and
notice that was listed under for each
that wasn't just listed under functions
let me drag that out again so you can
see that just to make sure so you have
call function and you have call function
for each and let's just take our delta
rotation I'm going to drag backwards and
say random rotator like so and just to
show you what this is going to do I'm
going to compile let's also make sure
that here in our scene before I try
anything that I set all of the mobility
of these actors over to to mobile or
moveable instead of static and now when
I play if I hit F you see they all get
random rotation
that's because you're performing that
function for each not all things not all
things you might want to do not all
functions have a for each version but I
do want to point that out that that is
available on certain output so that's
all I want to talk about in this lesson
over arrays thank you very much