Welcome back.
Now we'd like a behavior tree specific to the shaman, but for the most part, I want things to be pretty
much the same.
We're just going to change a couple of things.
So the first thing I'm going to do is duplicate this enemy behavior tree.
I'm just going to right click on it and choose duplicate and I'm going to call this BT Behavior tree
underscore Shaman.
Really, it doesn't have to be that specific.
We can make it elementalist as we could have other enemies that are elementalists that are not shamans.
So now that we have this behavior tree, I'd like to go into my shaman and change the behavior tree
to the Elementalist version and just make sure that this still works.
Now all it's doing is trying to activate abilities with the attack tag, and our shaman doesn't have
an ability with the attack tag.
It just has the summon ability.
So I'd like it to have that ability so we can see it attack.
So we're going to go into blueprints, ability system data, the character class info and go into our
elementalist and make sure that it's startup abilities not only has summoned ability but also the attack
ability.
So g A and this is going to be the actually firebolt ability.
But we need enemy firebolt the one specific to enemies, right?
So now it has summon and enemy firebolt.
And since it's using the new enemy behavior tree, which is just a duplicate of the old behavior tree,
we should see the same behavior that we saw before we made our summon ability.
In other words, our shaman should launch fireballs at us.
So let's save all and press play and see if that's the behavior we get.
And we do.
Now we have an issue here.
It looks like we're getting a premature explosion.
It looks like we're exploding a little early here.
So let's go ahead and see what it is we're hitting.
I'm going to go into our actor folder and open ora projectile and we'll just place a breakpoint right
away in on sphere Overlap.
Let's see what it is that we're hitting.
I'm going to press play.
And right away we can check other actor and I see that it's one of the tiles.
So we might actually be spawning that projectile a little bit too close to the ground.
So I'm going to remove that breakpoint and resume and let's see if we can tweak things a little bit
so that we don't get that overlap.
I'm going to open Blueprint's ability system or a abilities fire and Firebolt and open up Firebolt.
Let's take a look at its sphere.
It's a little bit large.
I like that it's large, but we can make it a little bit smaller and see if that fixes the problem.
Let's just see.
And it looks like that fixes the problem.
And even though it's a little bit easier to miss, I think that that's okay.
Our little shaman guy is just so close to the ground, it's hard to have such a large sphere there.
An alternative is to disable collision on the sphere for the first, say, 0.5 seconds or so.
That way it kind of passes through everything for the first bit of time before moving on.
That might be something we could try.
We could go to our event graph and an event begin play.
We could set a timer of sorts and enable collision then.
And then our sphere could be set to no collision from the start.
Let's see if that works.
Let's go to collision enabled.
We want it set to query only shortly after spawning.
Right.
But we can set it to no collision first and set it to query only here after a short delay.
So we could say delay.
We'll leave it at 0.2, maybe 0.5.
And then we can set the collision enabled for the sphere.
So set.
Collision enabled.
We can set it to query only.
And I'd like to see exactly where the fireball is in relation to its spawn point at this point in time.
So I'm going to draw a debug sphere.
And I'm going to draw it at the location of this actor.
So get actor location.
And I'm going to get the sphere.
And get sphere radius.
That's going to be the radius for my sphere that I draw.
I'm going to make it red.
I'm going to let the duration be five seconds and let's just see what happens here.
Now, compiling isn't going to work because Sphere is not blueprint visible.
We have not exposed it to the event graph.
So just really quickly, we have to close the editor and go into Aura projectile dot H and we have to
expose the sphere.
Now that means we either have to move it into the protected section or get around having the private
variable with a meta specifier.
Here's what I mean.
If we wanted blueprint read only and we want to keep Sphere in the private section, we'd have to say
meta equals allow private access.
Equals true.
That's how you get around having a blueprint read only and a private section.
But rather than doing that, I prefer to just move it into the protected section.
And that way we don't have to make it private in C plus plus but exposed in blueprint.
We're just going to make it a protected variable.
So now that the sphere is exposed, we can now launch the editor and use it in the blueprint.
So we'll go ahead and open up that blueprint.
We see that it compiles just fine and let's see what happens.
Okay, so that half a second is a bit long because if I'm closer than that, that fireball passes straight
through me.
So this is kind of a long delay.
Let's try 0.1 seconds and see how that looks.
That should be a fifth shorter.
There we go.
So if we're too close like this.
Close.
Then it should pass through us.
I guess we're still going to get hit.
So that's still okay.
Now let's see.
I hit stop and we get a blueprint.
Runtime error attempted to access sphere via properties Sphere but sphere is not valid pending kill
or garbage.
And this is in draw debug sphere.
So that's going to be for draw debug sphere.
We can always avoid that kind of error by doing a validated get.
So we can right click on sphere, we can convert to a validated get.
And this is like checking if a pointer is not null or rather checking is valid.
So even if it's not null but still pending kill we won't make it past this.
Okay, so things still work.
And if I'm really close to the enemy and I fire over there, well, I guess that's kind of beyond the
reach of it.
But this is looking good.
So again, we're attempting to access sphere when it's not valid and that's only when drawing the debug
sphere.
But before we get rid of the debug sphere, I'm going to take my sphere and increase its radius.
That way we can see if we can have a bigger radius without worrying about a premature explosion.
Let's see this happen in action.
Great.
So now it's not so easy to miss and we still have a little bit of a delay.
Excellent.
Okay.
So I'm going to remove that draw debug sphere.
We don't need that anymore and we now have a slight delay before enabling collision for the Firebolt.
Okay.
So all of that just so that we could have the same behavior as we had before, right?
We have a firebolt wielding shaman and really, you know, that's really all it does is launch firebolt.
But we want it to summon as well.
So what we need to do is we need to put some custom functionality in our behavior tree specific to the
Elementalist and we'll do that in the next video.
It's a great job.
I'll see you soon.