‫Hello and welcome.
‫In this lecture, we are going to be accessing the overlapping actors in something called an array so
‫that we can be printing out the actors that we see inside this volume entirely from C++.
‫Let's dive in and see how it's done.
‫So as in previous analogies, let's imagine that a type or a variable is a box in which we put a value.
‫Now, what happens if we don't know how many values we want to store?
‫We might create lots of variables.
‫If we knew that we were going to have five, we might make five variables.
‫But what if we had something that is unpredictably many, such as the number of actors we have in our
‫level, or the actors that are overlapping with a particular trigger volume?
‫In this case, we need to use a new data type called a T array in Unreal and basically a T array of
‫a certain type.
‫Here again, we're seeing these angle brackets that are, as we said, previously, compile time parameters.
‫And this time we're taking in, again, a type that is telling us what type we can store in our array.
‫An array is like a variable, except that it has multiple boxes and the number of boxes that we have
‫can be different when we're playing our game.
‫It can change.
‫We can add more or less as we go through the game.
‫As things start to overlap, we'd add more boxes as things that leave the overlapping zone.
‫We'd take them away.
‫And as I said, this is a parameter within these.
‫Angle brackets.
‫And so we could have a tray of ints, for example, which would store different integers in those boxes.
‫We could have a tray of actor pointers, and this would actually store the pointers in the boxes, which
‫would point to actors out in the world.
‫And as you can see, they could even overlap.
‫So some of these pointers point to the same actors.
‫Now, in practice, that wouldn't be very useful, but it's certainly possible.
‫So I want to revisit the documentation of the primitive component, because what I'm looking for here
‫is a function called get overlapping actors.
‫And if you have a look at the get overlapping actors function, there's a couple of versions of it.
‫But the one that's most interesting to me is the second one.
‫It doesn't have a return value, it's a void return value.
‫But you can see that the first parameter here is a t array of actor pointers with an ampersand at the
‫end, meaning that this whole thing is a reference to a t array.
‫Now notice it's not a constant reference, so we can assume that this parameter is actually an out parameter.
‫It gives us the result of the overlapping actors and it tells us which actors are currently overlapping
‫with our primitive component.
‫Now it just so happens that our box component is a primitive component.
‫So our trigger component is also a primitive component.
‫And who would have access to this function?
‫There's a second argument here, but we don't need to worry about that because it's actually got a default
‫value if we use it.
‫So let's go ahead and try and get hold of and populate a tray of actor pointers.
‫We're going to go into the trigger component.
‫CP We're going to go down to the tick component.
‫And in here we're going to create an empty t array that we can populate using this function.
‫So it's the syntax is t array open angle brackets a actor star to say that we're having a t array of
‫actor pointers, close the angle brackets and then we can give this variable name as actors.
‫Then we would call to get overlapping actors and we would pass in the actors array.
‫Now.
‫I don't know why they don't just pass this out as a return value, but.
‫There you go.
‫It gives us an opportunity to use those parameters a little bit more.
‫Now, that's all well and good.
‫We've got some actors in an array.
‫There's a variable length of them.
‫There might be quite a few.
‫There might be zero.
‫What do we do with arrays like this?
‫Well, we can query how many items are in the array.
‫You can use array, dot num parentheses and that can return an integer telling you how many items are
‫in the array.
‫So in this particular array we could say that there are five and then we can access the items inside
‫that array by using these square brackets.
‫And then the number that you pass into the square brackets tells you which item to get.
‫And it's a usual convention in a lot of programming languages that we start counting from zero in arrays.
‫So the zeroth element of an array is the first one, the one element of an array is the second, etc.
‫And so you end up with the last element always being one less than the number of elements in the array.
‫So how can we use this knowledge?
‫Well, for example, we could only print the overlapping actors if there is more than one of them.
‫So how would we do this?
‫We would put an if statement saying that if the actor's dot num parentheses is greater than zero, then
‫we can do something in here, such as get access to our actors zero element because we know that if
‫it's greater than zero, there must be at least one element in there.
‫So the zeroth element of this array must have something in.
‫We couldn't guarantee that the first element, the one element of the array has got anything in or the
‫two element has anything in.
‫We would have to check whether we have enough items in the array in order to do that, but we definitely
‫know that there is the first one here.
‫So let's challenge you to print the first overlapping actor from that array.
‫Use the array to get the pointer using those square brackets.
‫Then you're going to use that pointer to call, get actor, name or label, and then you're going to
‫print that out, pause the video and have a go.
‫Hey, welcome back.
‫So we can get we have got hold of the pointer here using this square brackets.
‫And I'm then going to get hold of the name straight way by using the arrow operator and calling get
‫actor, name or label.
‫And I'm going to put that in an F string variable called actor name.
‫Then we're going to do a U log, which we're going to call the overlapping colon.
‫And then percent s.
‫And then the second argument here should be asterisk, actor name.
‫Then we can recompile, hop into our output log docket in the layout.
‫Then we're going to open up the BPP secret wall because I don't want to be printing this string that
‫confuses things.
‫In Blueprint, we're doing this now from C++, so let's go over in to the dungeon level hit play.
‫And obviously nothing is overlapping that actor right now.
‫So what happens if we go and step inside?
‫You can see that it instantly starts printing, that we're overlapping the beep player.
‫Fantastic stuff.
‫What if we were to go and get the gargoyle instead?
‫Take it over to the alcove, stick it in and there you go.
‫It says it's overlapping the gargoyle statue.
‫Great stuff.
‫So we have learned how to use a t array to get a list of actors and to find out how many things are
‫in that list and how to get hold of a particular item from that list.
‫In the next lecture, we're going to be looking at some programming structures that allow us to deal
‫with variable numbers of things to do a variable number of tasks.
‫I'll see you there.