Welcome back.
Now we know how to create an instant gameplay effect, and applying that gameplay effect is relatively
simple, and we applied it using a blueprint callable function which we're calling here in response
to an overlap.
Now before we move on to different duration types for gameplay effects, we should visit how to apply
these gameplay effects directly here in Blueprint without having to call a blueprint callable Cplusplus
function and our cplusplus function here in Aura actor involves getting the ability system component
for the target simply so we can use it to make an effect context and apply a gameplay effect after making
an effect.
Spec.
This is actually quite simple to do here in blueprint as well.
We can take our other actor and we can call get ability system component and if we hover over this we
see target is ability system, blueprint library and that's the function we ended up calling here you
ability system blueprint library get ability system component which takes a target actor.
Here we have the input actor and the return value is the ability system component.
Now once we've gotten that ability system component, we take it and make an effect context with make
effect context.
We can do that here in blueprint.
We can drag off of the return value and type make effect context.
And this function returns a gameplay effect context handle structure.
Just like make effect context here in c plus plus returns a gameplay effect context handle struct same
thing.
Now here in C plus plus we're calling this Add source object function.
Now, if we go to the definition of this, we'll see here that it exists in gameplay effect types and
it's right here inside of scrolling up our gameplay effect context handle.
But we see that this function is not blueprint callable, so we can't call this from blueprint.
We also have get source object which is also not blueprint callable, but here in Blueprint, if we
type in source object, we see that we have a get source object.
So how can we call this in blueprint if it's not blueprint callable?
Well, this is not a function on this struct, it's a function on ability system blueprint library.
So these static libraries are a great way to expose to blueprint certain things that you can only do
in C plus plus.
And later on in the course we'll be making our own Blueprint library that we can use to expose certain
utilities to the blueprint side like this.
So while we can't call Add source object, we could make a static function library, a blueprint library
of our own, and create a static function that could take in an effect context and call a function such
as add source object, for example.
So that's one of the limitations of doing this from blueprint, but closing gameplay effect types and
going back into aura effect.
Actor The next thing we did was we made an outgoing spec this gameplay effect spec handle.
This is a function on the ability system component.
So from here in Blueprint we could drag off and type make outgoing spec and notice that make outgoing
spec requires a gameplay effect class which we have one here we have instant gameplay effect class.
If I duplicate that node and plug it in, that will satisfy it.
We can also set the level in C plus plus we set it to one and it takes a gameplay effect.
Context handle structure.
That's what make effect context returns.
So we could simply plug that straight in there.
And we now have an outgoing spec.
Now the last thing we did here in C plus plus was call apply gameplay effect spec to self on the ability
system component.
Here in blueprints we can take our ability system component and call apply gameplay effect spec to self.
We see that there are other options here as well, but if we choose apply gameplay effect spec not effect
but effect spec to self, then we see that we can plug in a spec handle.
That's the return value from make outgoing spec.
So as you can see this looks a little bit cleaner in blueprint as here in C plus plus we had to get
the effect spec handle and get the data which is a pointer wrapper.
We had to get the raw pointer and dereference it in order to pass in that object.
Here in Blueprint, we don't have to do any of that.
We just call a handful of functions that are exposed to blueprint and it's a little bit easier, a little
quicker to do, but you can do it either way.
And we've seen that on the C plus plus side.
We do have more options as not everything in C plus plus is exposed to blueprint.
And another benefit is we did all this work in C plus plus right here in our blueprint callable function.
So the end result is that our blueprint is cleaner as we only have a single node and as things get more
complex, we'll be able to implement those in C plus plus.
But really using one versus the other is really not going to result in, say, a significant performance
difference, at least in this case, as we're doing simple things here.
But to make sure that this works, we could bypass our blueprint callable node and we can simply call
apply gameplay effect spec to self and simply destroy the actor after that, like so.
And if we wanted to make sure that this only works for an actor that has an ability system component
here we can add an is valid to the ability system component we can say is valid here.
Use the one with the question mark and run it through the is valid node first like so.
And we can tidy this up just a little bit.
This does get a little bit messy in blueprint.
Another reason to opt for the C plus plus option as blueprints can get a bit out of hand.
And ideally this could be collapsed into a function of its own and cleaned up even further.
But let's just make sure that we can prove to ourselves that the blueprint option works.
Let's go and pick up the health potion.
That's the one that we changed and we see that it works and we're not using the C plus plus function
anymore.
Now we're using the blueprint option.
So two options for you, and I'll just leave those nodes there for now.
But we're using our C plus plus function.
Okay, great.
Just moving that out of the way.
Now for the topic of this lecture, and I'll just vocalize it.
I hooked up, destroy actor and everything's back to how it was there.
Now the topic for this lecture is the different types of duration policies for our gameplay effects.
We have a G potion heal, which is an instant gameplay effect.
Our potion mana is also an instant gameplay effect, but instant is just one of three choices.
We also have infinite and has duration.
In this video I'd like to discuss has duration and see how the has duration type works.
So to showcase the has duration gameplay effect, I'd like to make a new one.
I'm going to right click here and create a new blueprint class.
I'm going to search for gameplay effect.
Choose that class and call this one g.
Underscore core and this will be the duration based heal.
So I think I'd like to use something other than a health potion.
The assets folder in this startup project has a crystal, so I'm going to say crystal heal and we can
make maybe a healing crystal, for example.
So I'm going to open up crystal Heal.
And here in the Details panel, I'm going to scroll down to the duration policy and change it to has
duration.
Now that it's has duration, we need to specify the duration magnitude.
Essentially, how many seconds is this effect going to be applied before it removes itself?
So for the duration magnitude, we have scalable float attribute based custom calculation class and
set by caller.
So far we only have experience with scalable float which as we know we can hardcode a value in and we
can also scale it by a table.
Now we haven't created a table yet.
Don't worry, we'll get to all these features, we're going to cover them all.
But I'm going to set a scalable float magnitude of two, and this is in seconds.
So this effect will be applied for two seconds, after which it will remove itself.
And if we have any modifiers here, those modifiers will be undone.
So, for example, if I want to modify one of my attributes, I can add a modifier with the plus icon
and I can select the attribute.
Let's say I want to select Max Health.
And for Max health, I'd like to add to it and for the modifier magnitude expanding that, I'm going
to set the scalable float magnitude to 100.
So in other words, the max health will be added to by 100.
Now the max health is already starting at 100, which means it will be now 200 for two seconds.
And the result of that is we should see the health globe actually appear to go down because the amount
of health, the current health value.
Health is going to be the same.
But, Max, health will be larger, which means the percentage of health will be the same value divided
by an even larger value for max health.
So we should actually see that health globe go down.
It'll look like you have less health.
You really have the same amount of health, but the max health has changed.
So we have this crystal heal, right?
And we want to apply this duration based effect.
And we can easily do that by creating a new blueprint based on our aura effect actor and setting its
effect.
But we called our effect instant gameplay effect class.
We should add a new variable for a gameplay effect that has a duration.
So what I'm going to do is I'm going to save all.
I'm going to close the editor and we're going to add one more variable to aura effect.
Actor We'll go ahead and rearrange these here.
I'm going to close out of the files I'm not using and just under instant gameplay effect class, I'm
going to add another subclass of holding a gameplay effect and this one will be called Duration Gameplay
Effect class.
So we'll have a different variable here.
So what we can do is now we can make a blueprint for the health crystal that actually applies the duration
gameplay effect and not the instant gameplay effect.
So that's what we'd like to do.
And that's going to be your quest.
I'd like you to create the health crystal blueprint.
You can call it BP health crystal, if you like.
And you're going to set that duration based gameplay effect on this blueprint and then go ahead and
apply the effect.
You can use our blueprint callable function we created or you can get some practice doing it all in
blueprint.
Go ahead and make that choice.
So pause the video and conquer this quest now.
Okay, so now that I have my duration gameplay effect class, I'm going to go ahead and run this in
debug mode so I can make the blueprint and test it out.
All right.
So back here in the editor, I'm going to make a new blueprint.
Right click Blueprint class, and I'm going to base it on aura effect actor.
Choose that.
And I'm here in the potion folder, and this is a crystal technically, but that's okay.
I'm just going to keep it here in the potion folder.
It's basically another type of potion.
And I'm going to call this health crystal.
I'm going to open health crystal and I'm going to need a mesh and some kind of overlap volume.
So I'll do that.
First, I'll select the root component, create the static mesh.
Simply call this mesh.
Actually, I'll call this crystal mesh and I'll search for Crystal.
And it looks like we have a static mesh called health Crystal, and it's quite large, so I'm going
to scale it on down by about 0.2 in each dimension and I'll add a collision volume.
And for this one, since I can, why not?
I'll go ahead and add a capsule.
So I'm going to get that capsule in here.
I'll just leave it named capsule and I can adjust its size a little bit like so.
And the center of my crystal isn't perfect, so I'm going to take that crystal mesh and just move it
a bit so it's centered without snapping on.
Like.
So if I wanted to be precise, I could go from perspective to left.
And move it more precisely.
And go to right.
And move it more precisely.
All right.
Looking good.
I'm going to make sure my crystal mesh has no collision.
Some of those things you typically do for things like these pickups.
I'm going to go to my capsule collision settings here and it's set to overlap all dynamic.
I'll just leave it at that.
That's fine.
It's set to generate overlap events.
Perfect.
And I'll go to Health Crystal Self and search for duration.
And here's duration gameplay effect class.
I'm going to choose my crystal heal.
And now we have that set and instant gameplay effect class I'm going to leave on set and in the event
graph I'm going to take my capsule and use on component began overlap.
And I can either use my blueprint callable function to apply the effect or I can do everything in blueprint.
I'm going to use my apply effect to target a blueprint callable function and I will plug in other actor
as the target actor and use my duration gameplay effect class as the gameplay effect and I'll go ahead
and destroy.
So destroy actor after this.
All right, Now all that's left is to test it out.
I'm going to compile and save and drag out a BP health crystal blueprint.
I'll bring it out here.
I'm going to save all and play test.
Now, we should see because our health will be the same value, but our max health will be twice as
large.
This should go down and I can even show debug.
Remember to click in the viewport before hitting tilde key show debug ability system and I see health
is 50 max health is 100.
Let's pick up that healing crystal.
And now we see max health is 200, but now it's back to 100.
Why?
Because this is a duration based gameplay effect and we set the duration to two seconds.
Let's see that again because two seconds isn't a long time.
Here's the health goes down, but two seconds later it comes back up.
Now, this is extremely useful because without that built in capability of gameplay effects, we'd have
to create our own timers and create callbacks for when the timers finish.
And it's all a lot more work.
Whereas all we needed to do was make a gameplay effect and just set its duration and the duration magnitude,
and it was quite easy.
Now setting our max health to what it was, plus 100 for two seconds and then setting it back to what
it was before.
That's kind of silly.
It's not really a gameplay mechanic that you would think up and decide to implement in a game.
This was just for demonstrating how a duration based gameplay effect works, but in the videos to come
we're going to see how we can have a gameplay effect.
Apply changes periodically.
In other words, every so often apply some kind of change, such as healing over time and things like
that.
And those are the type of things that you would see in a game.
So great job.
This video We learned about duration based gameplay effects.
We're still going to make this aura effect actor a little more flexible, so we'll do that in the videos
to come.
Great job.
I'll see you soon.