Welcome.
Now, this lecture is all.
Quest You're going to make callbacks for the mana changes, just like we did for health changes.
So create the callbacks just like we did for health.
And after you do that, you're going to bind the callbacks, just like we did for health.
So do that and change the effect.
Actor so that when we get the potion, it'll subtract from mana as well as health and then play test.
So go ahead, pause the video, tackle this quest and set up your system to respond to manage changes.
And don't forget, you may have to go into Blueprint and do some things there as well.
And guess what?
There are a number of other steps involved in this challenge that I'm not going to tell you outright.
This is going to be a little bit more of a challenge to see if you can remember all the different things
involved and create those things, add those things, implement those things.
So this one is going to be stretching your brain just a little bit.
All right.
Best of luck.
Pause the video and conquer this.
All right.
So first we need some callbacks.
Let's go into overlay widget controller and make those callbacks.
Now, these are going to be for when mana changes, so I'm going to make void Mana changed and it'll
have the same exact function signature.
So I'll go ahead and paste that there and I'll also have a void.
Max Mana changed and again with the same exact function signature as the others and I'm going to go
ahead and generate the definitions for these like so and we're going to need some delegates to broadcast.
So let's go up to where we declared these delegates and we're going to do the exact same thing only
instead of on health changed signature, I'm going to make an on mana changed signature and this will
be float new mana and the next one will be on max mana change signature and the float will be called
New Max Mana.
And we'll make these delegates right here just like we did for health.
So I'm going to go ahead and paste them and change this to on Mana changed signature and I'll call this
on Mana changed and this one will be on max Mana changed signature called on max Mana changed.
So now we have the delegates.
Okay so now in the CPP file for mana change and max mana change, we want to broadcast these.
So we're going to say on mana changed dot broadcast and we're going to get data dot new value.
Simple as that.
And for max mana change it'll be on max mana changed dot broadcast data dot new value and now we'll
be broadcasting those values whenever our mana changed and max mana changed functions are called.
Well, when are those called?
Well, they're called in response to the mana changing.
As long as we bind them to the delegates on the ability system component here.
So we need to do that as well.
So I'm going to copy these lines.
Paste And the attribute is going to be get mana attribute.
That's the accessor we're calling and the callback will be mana changed.
So that's for when mana changes.
But we also want to do this for max Mana, so we'll paste it and instead of mana attribute we're going
to get max mana attribute and we're going to bind to max Mana changed, right?
So there's a few moving parts to this whole thing, but it's actually quite simple when the attribute
itself changes the ability system component broadcast a delegate which are widget controller subscribes
to.
So in response, our widget controllers callbacks will be called, and in those callbacks we broadcast
a delegate of our own to which our widget can subscribe.
So we're going to go ahead and subscribe to that in the widget blueprint.
Now, before we set all that up, let's just go into our aura effect actor wkRP, and we want to set
our mana.
So I'm going to copy this line where we're setting the health equal to its self plus 25.
I'm going to call set mana as well.
So set mana equal to get mana and we'll subtract 25.
So now our aura effect actor should subtract from the mana and we're just about ready to set up our
stuff in blueprint.
But we do also want to make sure that our widget controller will broadcast the initial values for the
mana.
So in addition to on health change and on max health change, we should also broadcast for our mana
as well.
So we're going to say on mana changed dot broadcast.
Or an attribute set and we'll call git mana.
And we can say on Max Mana changed broadcast.
Or attribute set.
Get Max Mana.
So now that way it should start at the appropriate value.
And just quickly checking the attribute set, it starts at 50 and its max is 50, so it should start
off full so I can go ahead and hit debug and we can tie this all together in blueprint and we should
be able to see a full mana globe.
And when we hit that health potion we should see the mana go down by 25.
But we do need to subscribe to the delegates in the Mana Globe widget blueprint.
So we're going to do that now so we can go into Blueprints UI Progress Bar WP manage Globe widget Blueprint.
And here what we have to do is use event widget controller set.
At this point we know our widget controller has been set.
We can get that widget controller.
We can cast it to BP Overlay widget controller.
That's the kind we need to cast to in order to get those delegates we want to bind to.
And I'm going to go ahead and promote that to a variable.
Called BP Overlay Widget Controller.
Just like we did over in the health globe.
And I'll comment this and say set widget controller and we'll put that up here.
I'm going to move these things over.
And I think I'd like to make a sequence just like I did in the Health globe.
So I'm going to use a sequence and I'm going to take my BP overlay widget controller drag off of that
and search for manage changed.
And I'm going to assign on manage changed here.
So I'll drag that out.
And while I'm at it, I'm going to duplicate this and add a then to and from my duplicate of the widget
controller.
I'm going to search for Max, manage changed and assign an event to that.
So we'll go ahead and hook that up as well.
And this will be similar to what we did in the health globe.
Namely, we want to promote these mana values to variables, right?
So when mana changes, my unmanaged changed event will be called.
I'm going to promote the value broadcast from the widget controller and call this mana.
And when Max mana changes, I'm going to promote the value passed in and call it max mana.
So now we have mana and max mana and now we can simply call that inherited function set progress bar
percent.
Which takes a percent.
We're going to divide mana by Max Mana.
So here's Mana.
Here's Max Mana.
I'm going to do a safe divide.
And hook that in.
I'm going to copy these.
Paste them down here.
Actually, I can copy the function call as well.
Ctrl D there and pass that in like so.
And now we're setting our mana.
Whenever it changes, we can compile that.
Excellent.
Let's go ahead and save all and press play and I see a full mana globe just as I expected.
And as I pick up the health potion, we should see health go up to 75% and mana is at 50.
Right.
It has a max of 50.
It's at 50.
We're subtracting 25.
It should go down to halfway.
So let's pick it up and it goes down to halfway.
Health still goes up to 75%.
We can show debug ability system and see that man is 25, max, man is 50.
Things are working so excellent.
And if you got through this whole challenge on your own, congratulations.
And if you didn't, don't be hard on yourself.
This was a bigger challenge.
And these challenges, some of them are easier and some of them are harder.
Do not get discouraged when you hit one of the harder ones.
If you can't figure it out on your own.
That's the whole reason why I'm going through the solution with you after you try it yourself.
So do try them yourself, but don't get discouraged if you can't figure them out.
It's okay if you can't.
All right.
So great job.
We now know how to respond to attribute changes.
We know how to show those changes in the HUD.
We're now ready to move on to the more interesting stuff in the gameplay ability system, such as gameplay
effects, and we'll learn how those work as well.
And by the way, if you were curious, you could change the number of players to two and change the
net mode to say, listen, server and press play just to make sure that things work in multiplayer.
So you can have two characters here running around and each of them, they have their own attributes
changing in response to things happening in the game.
So we'll test more in multiplayer as we continue developing the course.
So great job and I'll see you in the next video.