Welcome back.
So we have our elementalist behavior tree, and it's the same as our regular behavior tree for all of
our other enemies.
But we're going to want a few differences here.
For one, I'd like my attack to be different.
I want an attack that checks to see our number of minions, and if it's below a certain number, then
I'd like to activate the summon ability to summon minions.
For this reason, I'm going to double click on my ranged attack task node and browse to the folder that
has this task so that I can duplicate this attack.
I'm going to right click, I'm going to duplicate it and call this BT attack underscore Elementalist
So we have an elementalist attack.
Now I can close BT attack and open the Elementalist version.
Now this version is going to be more specific to the Elementalist.
And what I'd like to do is check right here before activating abilities.
I'd like to pass in a tag that depends on some conditions.
I want to see how many minions the enemy has and then we can try activate abilities with the tag that
we set.
So I'm going to make a tag for summoning.
So we have an attack tag.
I want a summon tag as well, so I'm going to add a new variable.
I'm going to call this summon tag.
It's going to be a gameplay tag, so we'll change it to gameplay tag for its type.
And I'm going to compile so I can give this a default value of abilities dot summon.
And then I'm going to make another variable called ability tag.
And this one will not be set until we check some conditions.
So I'd like to check some conditions after we set a combat target.
Now, I really don't like this controlled pawn wire coming across here.
It's making me feel like this is very messy.
So I'm going to take my controlled pawn and I'm going to promote it to a variable called controlled
pawn right here.
And then we'll just use that variable instead of having these reroute nodes.
So we'll put that there and we'll put it here.
And then I'm going to delete these reroutes.
So that's making me feel a little bit better.
And I'm just going to straighten a couple things out.
Okay.
So we need to set our ability tag based on some conditions.
I'd like to check the number of minions for our controlled pawn, so I'm going to right click and type
get.
Minion count.
Now, this is on our combat interface and it needs to know the object that is supposedly who implements
this interface.
We're going to pass in our controlled pawn here.
So after we get our minion count, we have something we can check and we can check against a number
of minions.
That should be a sort of threshold, and I think that can be a member variable of our attack task.
So I'm going to add a new variable and call this minion spawn threshold.
I'm going to change this to an integer compile and give it a default value.
But we could change this if we check the eye icon to expose it.
I'm going to set this to two and if we go down below to in other words, there's one minion left.
Then we should spawn minions.
We should activate the summon ability.
So I'm going to check this minion count against our threshold.
We're going to say if the minion count is less than our minion spawn threshold, which is two.
So if minion count becomes one, then what we need to do is we need to spawn.
We're going to have a branch here and we're going to spawn minions.
In other words, if it's true, I want to set my ability tag here and I want to set it to my summon
tag.
So that's what we'll do.
Now, if it's false, we're going to set the ability tag to the attack tag and that way we won't summon,
but instead we'll attack.
So in the true case, we're setting it to summon tag and the false case, we're setting ability tag
to the attack tag.
So all we're doing is setting the tag based on our condition here.
I'm going to make some room here.
Now, regardless of which one, both of these are going to go into the same try activate abilities by
tag so they'll both go into that same node.
The only difference is which tag we're going to use for trying to activate an ability.
And that depends on minion spawn threshold.
Now, here's the thing, right?
We need to keep an updated minion count every time we spawn in a minion.
That should increase our minion count.
And what does get Minion count do?
Well, we implemented this on the base character class.
Right?
Which means that we're returning a simple integer on the base character class.
We're never actually updating that.
So every time we spawn a minion, we need to set that minion count or at least increment it, right?
So we should have a function on the combat interface to set the minion count, or at least increment
the minion count.
Right.
Incremented by one.
So I'd like to make that function and make sure we're updating our minion count before continuing.
So I'm going to close the editor saving everything and we're going to go into our combat interface and
let's just make a function to increment minion count.
So I'm going to make it a void function and I'm just going to call it increment.
Minion count.
We're just going to increment it by one.
Although we could pass in an integer if we want to increment it by more than one.
And if we want to increment by one, just pass a one in there just because that's slightly more versatile.
I'm going to do it.
I'm going to have an int 32 called amount and we can override this and or a character base.
So where we have our get minion count, we're also going to override increment minion count.
So virtual void increment minion count implementation override.
Let's generate the definition and we're going to take our minion count plus equals amount.
So now we have the ability to increment our minion count and we could pass in a negative value if we
need to decrement that minion count.
And that actually raises a question how are we going to decrement the minion count?
How are we going to lower that minion count?
Right.
So that's a question we have to think about.
But here's another question, and this is something that some developers feel a lot more strongly about
than others.
But if increment minion count can take a negative value and decrement the minion count, well that goes
against the name, right?
If we use this function to decrement the minion count by passing a negative value in this really grinds
some developers gears.
Some would say that increment minion count should only be able to increment the minion count and there
should be a decrement minion count that should only be able to decrement the minion count.
Now, if you were a mathematician, you would say that, well, you could add a negative value and that's
the same as subtract.
So increment by a negative value means subtract means decrement.
Now, whatever philosophy you subscribe to here, by all means do what makes you feel is better.
Here, make two functions, one for incrementing and one for decrementing if that's what you want to
do.
Or you could just say add to minion count and you can add a negative value and then it doesn't necessarily
restrict you to incrementing or just have a setter set minion count.
It's really up to you.
I'm going to keep increment minion count and if I need to decrement it, I'm going to pass a negative
value in there.
I'm really sorry if that upsets you, but feel free to implement your naming conventions differently.
Okay, so the first thing we should do is increment our minion count when we spawn a new minion.
So let's launch the editor and make sure we're at least doing that.
So we can go back and open up our ability.
So we'll go to blueprints, ability system, enemy abilities and open up our summon ability.
And every time we call Spawn actor, we should increment the minion count.
So I'm going to go ahead and move these nodes forward.
I'm not really needing my draw debug sphere anymore, so I'm going to remove that.
And I'm just going to tidy this up real quick, like so.
And just after spawning an actor, I'm going to right click and call increment minion count.
For the target.
We're getting the avatar actor from actor info.
Passing that in and the amount is going to be one because we have now spawned a single minion.
So we're incrementing the minion count.
How do we decrement it?
Well, we'll get to that in just a second.
But first, I want to see if this is working by using my new BT attack task for the Elementalist.
So I'm going to go not into my enemy blackboard.
Actually, I don't know why my enemy blackboard was open.
I want my behavior tree, but for the elementalist and instead of BT attack, I'm going to drag off
and go to my tasks and get BT attack Elementalist instead and replace this attack with this one.
Now we do need to change the combat target selector to target to follow.
Just like our other attack here.
We're going to change the node name to Elementalist attack and we're going to leave that minion spawn
threshold at two and we're going to remove the old attack.
So now we have an elementalist attack.
We're going to replace that here and we're going to replace it here for the melee attack just in case
our ranged elementalist finds its way into this one.
So dragging off getting our attack elementalist here, removing the melee attack.
And then this one is going to be combat target selector will be target to follow and we'll give the
node name elementalist attack.
So let's just really quickly see if we get the behavior we want.
Now, what I expect is my shaman will first summon things because it's going to go into this task.
It's going to check the minion spawn threshold and it's going to check the minion count, which will
be zero.
So it will first activate the summon ability.
After that, it's going to have five minions, at which point it will then hit the false side of this
branch and activate the attack tag.
So we should get Firebolts after that, let's press play.
And we don't see a summon.
Let's find out why.
I'm going to print my minion count.
Here.
And it's zero.
Okay.
As expected and zero is less than minion spawn threshold, which means we want to activate the ability
with the summon tag.
Oh, and of course we're activating abilities using our attack tag.
We actually need to use the ability tag now.
So that is why we saw the attack ability.
Now we're going to activate with the ability tag.
Now we should see that summon first.
There it is.
And we have our attack now.
Interestingly, we got our minions spawned and I assume they were spawned over here for some reason.
Let's go and find out why.
We'll go to our summon ability.
To spawn actor.
And it looks like I broke something here.
This should actually have our spawn location.
We're going to spawn the actor at our chosen spawn location.
Right?
So we're going to get our spawn locations.
We're going to get a copy.
And we're getting it at our spawn location index.
Right there.
And we're raising it by 70 units.
There we go.
That's what we wanted to see.
And after that, we get the fireball.
Okay, so this is looking great.
Now there's an issue.
We're never decrementing that minion count.
So I can kill some of these minions here.
But if I do, that's not going to subtract one from the minion count.
So really, we're never going to get more minions once I get down to one minion left, which is the
behavior I want.
So in the next video, we're going to work on how we can decrement that minion count when one of our
minions dies.
So great job and I'll see you soon.