WEBVTT

00:06.810 --> 00:07.920
Welcome back.

00:07.950 --> 00:14.250
Now, as we mentioned in the previous video, we have a minion classes array and we can fill this in

00:14.250 --> 00:15.900
with classes to spawn.

00:15.900 --> 00:22.950
For example, I can click plus and I can choose my demon Ranger and I can click plus and I can choose

00:23.370 --> 00:25.440
Demon Warrior, for example.

00:25.440 --> 00:31.080
And I'd like to choose from among the classes in this array at random each time I spawn.

00:31.080 --> 00:37.170
So I want a nice blueprint, pure function that we can call that will get one at random.

00:37.170 --> 00:38.580
So let's do that.

00:38.580 --> 00:45.240
I'm going to go ahead and close the editor and we're going to go to awesome and ability and make a blueprint

00:45.240 --> 00:46.260
pure function.

00:46.260 --> 00:53.730
So this function is going to return a subclass of of type A pawn.

00:53.940 --> 00:56.310
That's what our array contains.

00:56.310 --> 01:02.400
And this function will be get random minion class and it doesn't need to take any inputs.

01:02.400 --> 01:11.770
So it's going to get a new function macro with blueprint, pure and category summoning.

01:13.700 --> 01:14.330
Okay.

01:14.330 --> 01:19.700
And this can go up here next to my other spawning related function.

01:20.150 --> 01:25.590
So let's generate this function definition and really it's going to be quite simple.

01:25.610 --> 01:27.380
We're going to.

01:28.520 --> 01:31.130
Make an N 32 called selection.

01:31.430 --> 01:35.660
It's going to be equal to F math randrange.

01:36.350 --> 01:44.570
We're going to get a random integer between zero and our array length minus one, and our array is called

01:44.600 --> 01:45.980
minion classes.

01:45.980 --> 01:52.280
So we're going to say minion classes, dot num minus one.

01:52.430 --> 02:01.550
So our selection is what we'll use to index the array and we're going to return minion classes index

02:01.550 --> 02:02.690
dot selection.

02:04.060 --> 02:06.780
And we'll make selection a constant.

02:06.790 --> 02:13.450
So it's a quite simple function in C plus plus, but it just adds more nodes in blueprint.

02:13.450 --> 02:18.850
So I'd like to just have this to be a blueprint, pure function that gets it for us.

02:18.850 --> 02:23.290
So now that we have this, we can run in debug mode.

02:24.270 --> 02:32.820
And we can open our ability and instead of drawing a debug sphere, we can right click and get random

02:32.850 --> 02:37.170
minion class and then we can spawn a minion.

02:37.170 --> 02:43.650
So I'm going to use Spawn actor from class and we can simply spawn an actor of this class.

02:43.650 --> 02:49.680
So I'm going to right click and use Spawn actor from class passing in our class.

02:50.010 --> 02:58.620
And for the spawn transform, I'm going to take the spawn location, but I do want to raise it a bit.

02:58.800 --> 03:02.010
And the reason is well, we'll see in just a second.

03:02.010 --> 03:05.970
Actually, before we raise it, let's just spawn it at this location.

03:05.970 --> 03:12.510
I can right click on Spawn, Transform, split the struct pin and pass that location in.

03:12.510 --> 03:18.690
And instead of drawing a debug sphere, we're going to spawn the actor and then continue on our way

03:18.690 --> 03:19.950
in the algorithm.

03:19.950 --> 03:25.480
We're also going to set collision handling override to always spawn ignore collisions.

03:25.480 --> 03:32.950
That way we'll spawn whether we're colliding or not, and then we'll see why we'd like to raise that

03:32.950 --> 03:34.270
spawn location a bit.

03:34.270 --> 03:35.530
So I'm going to press play.

03:36.890 --> 03:38.560
And there we go.

03:38.570 --> 03:42.680
We see that we're spawning in some enemies now.

03:42.680 --> 03:43.770
They're not moving.

03:43.790 --> 03:49.010
They're also spawned in side the ground there, which is a problem.

03:49.010 --> 03:52.880
So for one, let's take care of that in the ground problem.

03:52.880 --> 03:56.420
We want to raise this spawn location a bit.

03:56.420 --> 03:59.530
So how much do we want to raise it by?

03:59.540 --> 04:02.690
Well, for now, let's just add an amount to it.

04:03.630 --> 04:05.100
We're going to use plus.

04:05.460 --> 04:07.020
And what are we going to add?

04:07.020 --> 04:07.830
Something in the Z?

04:07.860 --> 04:08.510
Right.

04:08.520 --> 04:14.220
Let's add perhaps 70 and we'll use that for the spawn transform.

04:14.220 --> 04:15.570
Let's see how that looks.

04:17.760 --> 04:19.110
That's better.

04:19.650 --> 04:20.190
Okay.

04:20.190 --> 04:27.990
Now for the other problem, which is they're actually not moving towards the character.

04:27.990 --> 04:29.400
They're not chasing me.

04:29.700 --> 04:30.060
Okay.

04:30.060 --> 04:32.800
So why are they not chasing the character?

04:32.820 --> 04:39.840
Well, that's because when you spawn a pawn manually in the world at runtime, it does not automatically

04:39.840 --> 04:43.020
get a controller assigned to it.

04:43.170 --> 04:47.040
We have to assign a default controller.

04:47.040 --> 04:53.910
If we drag off the return value and type default controller, then we can use spawn default controller

04:53.910 --> 04:54.540
here.

04:58.990 --> 05:00.670
So if we do that.

05:02.070 --> 05:03.390
And press play.

05:04.500 --> 05:08.340
Now they're all coming at me nice and hostile.

05:09.360 --> 05:10.260
Now.

05:10.440 --> 05:17.130
Yes, we're spawning a huge army, and that's because we're activating this quite frequently.

05:17.160 --> 05:23.030
What I'd like to do is limit how much our shaman can spawn enemies.

05:23.040 --> 05:23.640
Right.

05:23.640 --> 05:29.220
But before that happens, I'd actually like to play that summon montage.

05:29.250 --> 05:33.020
So that way, you know, it actually looks cool.

05:33.030 --> 05:37.380
Like our shaman is actually casting a spell to summon these.

05:37.410 --> 05:45.060
So now that we've got this working pretty nicely, we'll work on that montage in the next video and

05:45.060 --> 05:46.830
we'll polish things up a little bit.

05:46.860 --> 05:50.730
We don't want all of our enemies spawning with the zero rotation like this.

05:50.820 --> 05:55.550
It'd be nice if they were spawned sort of facing outward away from the enemy.

05:55.560 --> 05:58.240
So we'll work on that as well.

05:58.260 --> 05:59.430
So great job.

05:59.460 --> 06:01.290
I'll see you in the next video.
