WEBVTT

00:06.800 --> 00:07.840
Welcome back.

00:07.850 --> 00:13.760
So we have our elementalist behavior tree, and it's the same as our regular behavior tree for all of

00:13.760 --> 00:14.990
our other enemies.

00:14.990 --> 00:17.210
But we're going to want a few differences here.

00:17.210 --> 00:19.930
For one, I'd like my attack to be different.

00:19.940 --> 00:26.870
I want an attack that checks to see our number of minions, and if it's below a certain number, then

00:26.870 --> 00:31.340
I'd like to activate the summon ability to summon minions.

00:31.340 --> 00:38.420
For this reason, I'm going to double click on my ranged attack task node and browse to the folder that

00:38.420 --> 00:42.350
has this task so that I can duplicate this attack.

00:42.350 --> 00:48.410
I'm going to right click, I'm going to duplicate it and call this BT attack underscore Elementalist

00:49.100 --> 00:51.110
So we have an elementalist attack.

00:51.110 --> 00:55.160
Now I can close BT attack and open the Elementalist version.

00:55.160 --> 00:59.150
Now this version is going to be more specific to the Elementalist.

00:59.150 --> 01:04.730
And what I'd like to do is check right here before activating abilities.

01:04.730 --> 01:09.840
I'd like to pass in a tag that depends on some conditions.

01:09.840 --> 01:16.140
I want to see how many minions the enemy has and then we can try activate abilities with the tag that

01:16.140 --> 01:17.310
we set.

01:17.310 --> 01:20.520
So I'm going to make a tag for summoning.

01:20.520 --> 01:22.080
So we have an attack tag.

01:22.080 --> 01:26.010
I want a summon tag as well, so I'm going to add a new variable.

01:26.010 --> 01:28.170
I'm going to call this summon tag.

01:28.740 --> 01:33.600
It's going to be a gameplay tag, so we'll change it to gameplay tag for its type.

01:34.240 --> 01:39.580
And I'm going to compile so I can give this a default value of abilities dot summon.

01:39.820 --> 01:44.470
And then I'm going to make another variable called ability tag.

01:45.190 --> 01:50.050
And this one will not be set until we check some conditions.

01:50.050 --> 01:54.250
So I'd like to check some conditions after we set a combat target.

01:54.280 --> 01:58.630
Now, I really don't like this controlled pawn wire coming across here.

01:58.630 --> 02:01.090
It's making me feel like this is very messy.

02:01.090 --> 02:06.010
So I'm going to take my controlled pawn and I'm going to promote it to a variable called controlled

02:06.010 --> 02:07.240
pawn right here.

02:07.600 --> 02:12.700
And then we'll just use that variable instead of having these reroute nodes.

02:12.850 --> 02:16.270
So we'll put that there and we'll put it here.

02:18.700 --> 02:21.490
And then I'm going to delete these reroutes.

02:22.180 --> 02:25.130
So that's making me feel a little bit better.

02:25.150 --> 02:27.760
And I'm just going to straighten a couple things out.

02:28.330 --> 02:28.870
Okay.

02:28.870 --> 02:32.590
So we need to set our ability tag based on some conditions.

02:32.620 --> 02:39.640
I'd like to check the number of minions for our controlled pawn, so I'm going to right click and type

02:39.640 --> 02:40.360
get.

02:41.570 --> 02:42.980
Minion count.

02:43.160 --> 02:50.450
Now, this is on our combat interface and it needs to know the object that is supposedly who implements

02:50.450 --> 02:51.390
this interface.

02:51.410 --> 02:54.470
We're going to pass in our controlled pawn here.

02:54.800 --> 03:01.370
So after we get our minion count, we have something we can check and we can check against a number

03:01.370 --> 03:02.240
of minions.

03:02.240 --> 03:07.970
That should be a sort of threshold, and I think that can be a member variable of our attack task.

03:07.970 --> 03:13.340
So I'm going to add a new variable and call this minion spawn threshold.

03:14.570 --> 03:19.670
I'm going to change this to an integer compile and give it a default value.

03:19.670 --> 03:23.190
But we could change this if we check the eye icon to expose it.

03:23.210 --> 03:30.530
I'm going to set this to two and if we go down below to in other words, there's one minion left.

03:30.560 --> 03:32.720
Then we should spawn minions.

03:32.720 --> 03:34.880
We should activate the summon ability.

03:34.880 --> 03:37.970
So I'm going to check this minion count against our threshold.

03:37.970 --> 03:44.820
We're going to say if the minion count is less than our minion spawn threshold, which is two.

03:44.850 --> 03:51.450
So if minion count becomes one, then what we need to do is we need to spawn.

03:51.570 --> 03:56.150
We're going to have a branch here and we're going to spawn minions.

03:56.160 --> 04:03.210
In other words, if it's true, I want to set my ability tag here and I want to set it to my summon

04:03.210 --> 04:03.900
tag.

04:05.120 --> 04:06.590
So that's what we'll do.

04:07.340 --> 04:13.580
Now, if it's false, we're going to set the ability tag to the attack tag and that way we won't summon,

04:13.580 --> 04:15.180
but instead we'll attack.

04:15.200 --> 04:22.040
So in the true case, we're setting it to summon tag and the false case, we're setting ability tag

04:22.040 --> 04:24.410
to the attack tag.

04:26.240 --> 04:29.840
So all we're doing is setting the tag based on our condition here.

04:29.960 --> 04:31.400
I'm going to make some room here.

04:31.430 --> 04:37.790
Now, regardless of which one, both of these are going to go into the same try activate abilities by

04:37.790 --> 04:41.570
tag so they'll both go into that same node.

04:42.240 --> 04:48.120
The only difference is which tag we're going to use for trying to activate an ability.

04:48.940 --> 04:51.550
And that depends on minion spawn threshold.

04:51.640 --> 04:53.350
Now, here's the thing, right?

04:53.350 --> 04:58.990
We need to keep an updated minion count every time we spawn in a minion.

04:59.020 --> 05:02.160
That should increase our minion count.

05:02.170 --> 05:04.420
And what does get Minion count do?

05:04.450 --> 05:07.990
Well, we implemented this on the base character class.

05:07.990 --> 05:08.530
Right?

05:08.530 --> 05:13.570
Which means that we're returning a simple integer on the base character class.

05:13.570 --> 05:15.520
We're never actually updating that.

05:15.520 --> 05:22.420
So every time we spawn a minion, we need to set that minion count or at least increment it, right?

05:22.420 --> 05:29.890
So we should have a function on the combat interface to set the minion count, or at least increment

05:29.890 --> 05:30.820
the minion count.

05:30.820 --> 05:31.270
Right.

05:31.270 --> 05:32.940
Incremented by one.

05:32.950 --> 05:38.200
So I'd like to make that function and make sure we're updating our minion count before continuing.

05:38.200 --> 05:44.650
So I'm going to close the editor saving everything and we're going to go into our combat interface and

05:44.650 --> 05:49.040
let's just make a function to increment minion count.

05:49.040 --> 05:54.380
So I'm going to make it a void function and I'm just going to call it increment.

05:55.230 --> 05:56.460
Minion count.

05:56.640 --> 05:59.770
We're just going to increment it by one.

05:59.790 --> 06:04.780
Although we could pass in an integer if we want to increment it by more than one.

06:04.800 --> 06:10.910
And if we want to increment by one, just pass a one in there just because that's slightly more versatile.

06:10.920 --> 06:11.880
I'm going to do it.

06:11.880 --> 06:19.290
I'm going to have an int 32 called amount and we can override this and or a character base.

06:19.290 --> 06:25.410
So where we have our get minion count, we're also going to override increment minion count.

06:25.560 --> 06:34.320
So virtual void increment minion count implementation override.

06:34.350 --> 06:43.260
Let's generate the definition and we're going to take our minion count plus equals amount.

06:43.500 --> 06:52.200
So now we have the ability to increment our minion count and we could pass in a negative value if we

06:52.200 --> 06:55.030
need to decrement that minion count.

06:55.030 --> 07:00.460
And that actually raises a question how are we going to decrement the minion count?

07:00.490 --> 07:03.730
How are we going to lower that minion count?

07:03.760 --> 07:04.330
Right.

07:04.330 --> 07:06.580
So that's a question we have to think about.

07:06.580 --> 07:13.840
But here's another question, and this is something that some developers feel a lot more strongly about

07:13.840 --> 07:14.560
than others.

07:14.560 --> 07:22.300
But if increment minion count can take a negative value and decrement the minion count, well that goes

07:22.300 --> 07:24.040
against the name, right?

07:24.040 --> 07:32.020
If we use this function to decrement the minion count by passing a negative value in this really grinds

07:32.020 --> 07:33.700
some developers gears.

07:33.790 --> 07:39.640
Some would say that increment minion count should only be able to increment the minion count and there

07:39.640 --> 07:44.800
should be a decrement minion count that should only be able to decrement the minion count.

07:44.890 --> 07:50.770
Now, if you were a mathematician, you would say that, well, you could add a negative value and that's

07:50.770 --> 07:52.330
the same as subtract.

07:52.330 --> 07:57.520
So increment by a negative value means subtract means decrement.

07:57.880 --> 08:06.700
Now, whatever philosophy you subscribe to here, by all means do what makes you feel is better.

08:06.700 --> 08:12.040
Here, make two functions, one for incrementing and one for decrementing if that's what you want to

08:12.040 --> 08:12.790
do.

08:12.790 --> 08:19.330
Or you could just say add to minion count and you can add a negative value and then it doesn't necessarily

08:19.330 --> 08:24.220
restrict you to incrementing or just have a setter set minion count.

08:24.250 --> 08:25.960
It's really up to you.

08:26.230 --> 08:31.780
I'm going to keep increment minion count and if I need to decrement it, I'm going to pass a negative

08:31.780 --> 08:32.950
value in there.

08:33.010 --> 08:40.270
I'm really sorry if that upsets you, but feel free to implement your naming conventions differently.

08:40.870 --> 08:46.180
Okay, so the first thing we should do is increment our minion count when we spawn a new minion.

08:46.180 --> 08:50.080
So let's launch the editor and make sure we're at least doing that.

08:52.070 --> 08:56.630
So we can go back and open up our ability.

08:56.780 --> 09:04.220
So we'll go to blueprints, ability system, enemy abilities and open up our summon ability.

09:04.220 --> 09:08.820
And every time we call Spawn actor, we should increment the minion count.

09:08.840 --> 09:12.050
So I'm going to go ahead and move these nodes forward.

09:12.650 --> 09:17.690
I'm not really needing my draw debug sphere anymore, so I'm going to remove that.

09:18.680 --> 09:24.050
And I'm just going to tidy this up real quick, like so.

09:24.200 --> 09:33.440
And just after spawning an actor, I'm going to right click and call increment minion count.

09:37.820 --> 09:38.780
For the target.

09:38.810 --> 09:42.260
We're getting the avatar actor from actor info.

09:43.170 --> 09:50.250
Passing that in and the amount is going to be one because we have now spawned a single minion.

09:51.800 --> 09:54.110
So we're incrementing the minion count.

09:54.140 --> 09:55.760
How do we decrement it?

09:55.790 --> 09:58.340
Well, we'll get to that in just a second.

09:58.340 --> 10:06.850
But first, I want to see if this is working by using my new BT attack task for the Elementalist.

10:06.860 --> 10:10.160
So I'm going to go not into my enemy blackboard.

10:10.160 --> 10:13.130
Actually, I don't know why my enemy blackboard was open.

10:13.130 --> 10:21.290
I want my behavior tree, but for the elementalist and instead of BT attack, I'm going to drag off

10:21.290 --> 10:29.360
and go to my tasks and get BT attack Elementalist instead and replace this attack with this one.

10:29.360 --> 10:35.540
Now we do need to change the combat target selector to target to follow.

10:37.230 --> 10:39.420
Just like our other attack here.

10:40.200 --> 10:48.150
We're going to change the node name to Elementalist attack and we're going to leave that minion spawn

10:48.150 --> 10:52.080
threshold at two and we're going to remove the old attack.

10:52.080 --> 10:54.440
So now we have an elementalist attack.

10:54.450 --> 11:00.690
We're going to replace that here and we're going to replace it here for the melee attack just in case

11:00.720 --> 11:05.340
our ranged elementalist finds its way into this one.

11:05.340 --> 11:12.990
So dragging off getting our attack elementalist here, removing the melee attack.

11:12.990 --> 11:20.040
And then this one is going to be combat target selector will be target to follow and we'll give the

11:20.040 --> 11:23.400
node name elementalist attack.

11:23.880 --> 11:29.250
So let's just really quickly see if we get the behavior we want.

11:29.280 --> 11:36.420
Now, what I expect is my shaman will first summon things because it's going to go into this task.

11:36.420 --> 11:41.050
It's going to check the minion spawn threshold and it's going to check the minion count, which will

11:41.050 --> 11:41.920
be zero.

11:41.920 --> 11:44.710
So it will first activate the summon ability.

11:44.710 --> 11:52.030
After that, it's going to have five minions, at which point it will then hit the false side of this

11:52.030 --> 11:54.430
branch and activate the attack tag.

11:54.430 --> 11:58.030
So we should get Firebolts after that, let's press play.

11:59.570 --> 12:01.220
And we don't see a summon.

12:02.500 --> 12:04.360
Let's find out why.

12:07.730 --> 12:09.950
I'm going to print my minion count.

12:11.360 --> 12:12.200
Here.

12:15.000 --> 12:16.770
And it's zero.

12:16.830 --> 12:17.690
Okay.

12:17.700 --> 12:26.880
As expected and zero is less than minion spawn threshold, which means we want to activate the ability

12:26.880 --> 12:28.020
with the summon tag.

12:28.020 --> 12:32.520
Oh, and of course we're activating abilities using our attack tag.

12:32.520 --> 12:35.520
We actually need to use the ability tag now.

12:35.520 --> 12:39.990
So that is why we saw the attack ability.

12:40.020 --> 12:42.780
Now we're going to activate with the ability tag.

12:42.780 --> 12:44.790
Now we should see that summon first.

12:44.970 --> 12:46.200
There it is.

12:47.580 --> 12:51.150
And we have our attack now.

12:51.360 --> 12:58.620
Interestingly, we got our minions spawned and I assume they were spawned over here for some reason.

12:58.650 --> 13:00.160
Let's go and find out why.

13:00.180 --> 13:01.950
We'll go to our summon ability.

13:02.740 --> 13:04.060
To spawn actor.

13:04.060 --> 13:06.310
And it looks like I broke something here.

13:06.340 --> 13:10.830
This should actually have our spawn location.

13:10.840 --> 13:15.910
We're going to spawn the actor at our chosen spawn location.

13:15.910 --> 13:16.500
Right?

13:16.510 --> 13:19.180
So we're going to get our spawn locations.

13:20.060 --> 13:21.560
We're going to get a copy.

13:23.680 --> 13:26.500
And we're getting it at our spawn location index.

13:27.180 --> 13:28.110
Right there.

13:29.200 --> 13:31.990
And we're raising it by 70 units.

13:33.980 --> 13:34.640
There we go.

13:34.640 --> 13:36.110
That's what we wanted to see.

13:36.350 --> 13:39.140
And after that, we get the fireball.

13:39.920 --> 13:42.050
Okay, so this is looking great.

13:42.080 --> 13:43.280
Now there's an issue.

13:43.310 --> 13:46.100
We're never decrementing that minion count.

13:46.100 --> 13:49.420
So I can kill some of these minions here.

13:49.430 --> 13:54.660
But if I do, that's not going to subtract one from the minion count.

13:54.680 --> 14:01.040
So really, we're never going to get more minions once I get down to one minion left, which is the

14:01.040 --> 14:02.180
behavior I want.

14:02.330 --> 14:07.970
So in the next video, we're going to work on how we can decrement that minion count when one of our

14:07.970 --> 14:09.030
minions dies.

14:09.050 --> 14:11.180
So great job and I'll see you soon.
