Welcome to your next quest.
For this quest, you're going to add attribute points to the player state as a member variable.
Now, make sure you handle all the things that are associated with that.
This is something that will need to be replicated, for example, and broadcast a delegate when the
points change.
Now, since we're broadcasting delegates, we're going to need to receive those delegates.
So receive that delegate that you're going to broadcast in the attribute menu widget controller.
That way we can broadcast up to our widgets and as a bonus, add a spell points variable and handle
everything related to that as well.
Perhaps you can knock these both out at the same time.
Pause the video and conquer this quest.
Now.
Okay, so I'm in my player state class and I'm going to need attribute points.
I'd like to just knock out attribute points and spell points at the same time.
So I'm going to add both of those.
So this one I'm going to rename to attribute points and the rep notify will be on rep attribute points
and I'm going to start it off with a value of zero and the next one will be spell points.
And this will use a rep notify on rep spell points.
Now I can create those rep notifies.
I'm just going to copy on rep level and paste it twice and this one will be on rep attribute points.
Changing its input there.
And this one will be on rep spell points, changing its input as well.
And I can go ahead and generate definitions for both of these.
So now I have a rep notify for both.
I do need to add both to get lifetime replicated props.
So if you forgot that step, make sure to come back and do that.
We need to add both attribute points and spell points.
Okay.
Now we're going to want a couple of delegates to broadcast when these change.
Now we have a delegate that broadcasts in 30 twos.
It's called F on player stat changed.
We're going to make a pair of these one for when attribute points change we'll call it on attribute
points changed delegate and we'll have another one on spell points changed delegate And we just need
to broadcast these.
When these values change.
Now we're going to need some setters and getters for them as well.
So I'm just going to go ahead and create those.
I'll have the getters together here.
I'll go ahead and make the getters force inline.
They'll return in 32 first, we'll have get attribute points, const return attribute points.
And another force in line in 30 to get spell points also const and it'll return spell points.
Now I'm going to create add two functions for both of these.
I don't really think I'll need setters.
We'll see if we need them in the future.
We'll add them if we do.
But for now I'm just going to make a add to attribute points function that takes an int 32 called in
points, we'll call it and a void function add to spell points.
Which will take in in 32 called in points as well.
And I'll go ahead and create definitions for both of these.
And these are going to just add to their corresponding variables attribute points.
We can use plus equals in points and spell points will take spell points plus equals end points.
And we can broadcast delegates for when these change.
So we're going to take our on attribute points change delegate call broadcast, and we'll go ahead and
broadcast the value of attribute points and we'll take on spell points, change, delegate and broadcast
the value of spell points.
Now I'm just noticing that these definitions were created inline, so I'd like to cut them and paste
them into or a player state CPP.
I'd like them down here and I'm going to remove that inline keyword and I'm also going to make sure
that the delegates are broadcast and the rep notifies.
So handling the delegate broadcast for attribute points and it's on rep and handling the delegate broadcast
for spell points and it's on rep.
And with that, we're now broadcasting when our spell points change.
We just need to listen for these in our widget controller and handle it there.
So I'm going to go into UI and I actually think I'll go straight to the private folder into attribute
menu widget controller, CPP.
Now here in the attribute menu, we haven't actually bound anything to our player state.
So what I'm going to do is get my player state.
We'll do this at the bottom of bind callbacks to dependencies.
So I'm going to do basically what I did in overlay widget controller so I can go to overlay widget controller
If I want an example of how I got my player state, I basically use cast checked with Player State,
so I'm going to copy that line and paste it here.
An attribute menu widget controller and I'll use alt enter to include or a player state the header file.
So now that we have the player state, we can bind to one of its delegates.
I want to bind to its attribute points change.
Delegate this one here on attribute points change delegate So here in the attribute menu widget controller
I'm going to take or a player state get on attribute points change delegate and I'm going to bind a
lambda to it.
So using add lambda, I can put a lambda here.
And what is my lambda going to do?
Well, my attribute menu widget controller can simply broadcast the value of my attribute points, so
it's going to need a delegate to broadcast.
Now let's see what we're broadcasting in our overlay widget controller for our level.
I'm going to go to its header file all the way up to the top and take a look at the delegates we have
here.
We have on player stat change signature.
Now, this is something that we can reuse in attribute menu widget controller and if we're going to
reuse it there, well both attribute menu and overlay widget controllers inherit from a widget controller
so we can simply declare this delegate there and use it in both child classes.
So I'm going to control X to cut that and go into aura widget controller.
This is the CPP file.
I need to go to the header file and an aura widget controller dot h.
I'm going to declare on player stat change signature here and then I can simply use this in attribute
menu widget controller.
So after making that change, I'm going to close Aura widget controller and go back to attribute menu
widget controller and open its header file and make a blueprint assignable delegate of this type on
player stat change signature and I'm going to call this attribute points changed delegate and make it
blueprint assignable.
Now, I do want to make sure that this is not the same name as the delegate here on the player state
and the player state has on attribute points change delegate our attribute menu widget controller just
has attribute points change delegate.
So that's fine.
And all I want to do in this lambda is broadcast my new delegate attribute points change delegate dot
broadcast and I want to broadcast the value and this lambda should be capable of receiving an 32 we'll
call it points here, and the square brackets should capture this and we can simply broadcast points.
So now our attribute menu is receiving the attribute points when they change and broadcasting that.
So now that we've set all this up, we can do several things.
Next, we need to actually add to the attribute points.
When they change, we need to receive that change in our widget and update that in the HUD.
We should broadcast our initial values for it in the HUD and we should add to those values when we level
up.
So we'll do those things.
Next, I'm going to close out of the editor so I can do a quick compile.
And with that, I'll see you in the next video.