Welcome back.
Now, as we mentioned in the previous video, we have a minion classes array and we can fill this in
with classes to spawn.
For example, I can click plus and I can choose my demon Ranger and I can click plus and I can choose
Demon Warrior, for example.
And I'd like to choose from among the classes in this array at random each time I spawn.
So I want a nice blueprint, pure function that we can call that will get one at random.
So let's do that.
I'm going to go ahead and close the editor and we're going to go to awesome and ability and make a blueprint
pure function.
So this function is going to return a subclass of of type A pawn.
That's what our array contains.
And this function will be get random minion class and it doesn't need to take any inputs.
So it's going to get a new function macro with blueprint, pure and category summoning.
Okay.
And this can go up here next to my other spawning related function.
So let's generate this function definition and really it's going to be quite simple.
We're going to.
Make an N 32 called selection.
It's going to be equal to F math randrange.
We're going to get a random integer between zero and our array length minus one, and our array is called
minion classes.
So we're going to say minion classes, dot num minus one.
So our selection is what we'll use to index the array and we're going to return minion classes index
dot selection.
And we'll make selection a constant.
So it's a quite simple function in C plus plus, but it just adds more nodes in blueprint.
So I'd like to just have this to be a blueprint, pure function that gets it for us.
So now that we have this, we can run in debug mode.
And we can open our ability and instead of drawing a debug sphere, we can right click and get random
minion class and then we can spawn a minion.
So I'm going to use Spawn actor from class and we can simply spawn an actor of this class.
So I'm going to right click and use Spawn actor from class passing in our class.
And for the spawn transform, I'm going to take the spawn location, but I do want to raise it a bit.
And the reason is well, we'll see in just a second.
Actually, before we raise it, let's just spawn it at this location.
I can right click on Spawn, Transform, split the struct pin and pass that location in.
And instead of drawing a debug sphere, we're going to spawn the actor and then continue on our way
in the algorithm.
We're also going to set collision handling override to always spawn ignore collisions.
That way we'll spawn whether we're colliding or not, and then we'll see why we'd like to raise that
spawn location a bit.
So I'm going to press play.
And there we go.
We see that we're spawning in some enemies now.
They're not moving.
They're also spawned in side the ground there, which is a problem.
So for one, let's take care of that in the ground problem.
We want to raise this spawn location a bit.
So how much do we want to raise it by?
Well, for now, let's just add an amount to it.
We're going to use plus.
And what are we going to add?
Something in the Z?
Right.
Let's add perhaps 70 and we'll use that for the spawn transform.
Let's see how that looks.
That's better.
Okay.
Now for the other problem, which is they're actually not moving towards the character.
They're not chasing me.
Okay.
So why are they not chasing the character?
Well, that's because when you spawn a pawn manually in the world at runtime, it does not automatically
get a controller assigned to it.
We have to assign a default controller.
If we drag off the return value and type default controller, then we can use spawn default controller
here.
So if we do that.
And press play.
Now they're all coming at me nice and hostile.
Now.
Yes, we're spawning a huge army, and that's because we're activating this quite frequently.
What I'd like to do is limit how much our shaman can spawn enemies.
Right.
But before that happens, I'd actually like to play that summon montage.
So that way, you know, it actually looks cool.
Like our shaman is actually casting a spell to summon these.
So now that we've got this working pretty nicely, we'll work on that montage in the next video and
we'll polish things up a little bit.
We don't want all of our enemies spawning with the zero rotation like this.
It'd be nice if they were spawned sort of facing outward away from the enemy.
So we'll work on that as well.
So great job.
I'll see you in the next video.