Welcome back.
In this video, we're going to learn another way to initialize our attributes.
So far, we're just calling these init functions, and that's not my preferred way to do it.
And as I mentioned, there are multiple ways to do it.
Now the way that we're going to do it in this video is not my preferred way either, but you should
know about it just because it's an option that's there and that's to initialize the attributes with
a data table.
Now, my preferred method is through a gameplay effect, and that's the method I see most commonly.
But for educational purposes we're going to cover how to do it from a data table.
And to do that, I'd like to add some more attributes to our attributes set because this project is
going to involve more than just health and mana.
So I'm going to open my aura attribute set header file, and before I do that, I'm going to close all
other tabs except for the CPP file and then head on over to the header file and let's just go through
the boilerplate steps to add a few more attributes.
Now these are my vital attributes, at least what I'm calling vital attributes.
So I'm going to add a multi-line comment here that says vital attributes and the attributes that I'd
like to add.
Now I'm going to categorize a little bit differently.
I'm going to call these my primary attributes, and these are going to be my RPG style attributes,
strength, intelligence and what have you.
Now I'm just going to have four primary attributes, and I understand that many RPGs have more than
four.
You can even have less than four primary attributes.
Really, it depends on your design, but I'd like to have four primary attributes and those four primary
attributes are going to be strength.
So I'm going to have an gameplay attribute data called strength.
And I'm going to have the same view property specifiers as my other vital attributes.
Except we're going to need to change a couple things, right?
For one, I want my category to say primary attributes and strength needs its own rep.
Notify called on rep strength.
So I'm just going to type it here even though it doesn't exist yet.
And then I'll make the rep notify in a second.
But I also want to use my attribute accessors macro for strength.
And I'm going to change this to say strength instead of health.
And I'll go ahead and make my rep notify.
I'm just going to copy one of the others.
Paste it here and call this on rep strength.
And its input will be old strength and I'm going to generate the definition.
And use the same macro gameplay attribute rep notify.
It's going to be the strength attribute and it's going to take in old strength as well.
Okay.
That's not the only thing we need to do, is it?
We also have a couple other steps.
One of those is to go all the way up to get lifetime replicated props and add strength.
I'm going to add a space between the vital and primary attributes.
In fact, I'd like the primaries to be at the top, so I'm going to put those above everything else.
And this will be the strength attribute.
So there's that step.
So there are a few things that we need to remember when we make these new attributes.
Now what I can do is copy these three lines and paste them, and I can highlight these and control H
to replace strength with my next attribute name.
So I'm going to find strength.
And I see that it's used in the en rep.
The rep notify it's used for the name of the attribute and it's used in attribute accessors here.
Now, my next primary attribute is going to be intelligence.
So I'm going to hit replace all.
And I also need my rep notify so I can come down to my rep, notifies, copy the one for strength,
and I'm going to highlight the line.
See that I have two strengths.
I'm going to click Replace all and don't even have to type anything else up there and back here in the
CPP file I'm going to copy do rep lifetime and highlight this line Ctrl H.
Replacing strength with intelligence, and then it's going to try to do it to my on rep strength.
That's not what I want.
I want to implement on rep intelligence.
Copy the gameplay attribute and then highlight this line and replace strength with intelligence.
There we go.
Okay, so I have two more that I'd like to make.
So I'm going to copy these lines and make my third one.
Now my third one, my third primary attribute is going to be resilience.
So again, I'm going to replace strength with resilience.
And in fact, I copied intelligence, so I need to replace intelligence actually.
So I have it three times here.
I'm going to replace all and we can make the rep notify.
For resilience.
So I'm going to highlight this replace intelligence with resilience.
I'm going to generate the definition.
Get my boilerplate macro.
And I'm just going to manually replace intelligence with resilience here.
And then finally back up to Git.
Lifetime replicated props.
I'm going to add one for resilience and one more.
I'm going to have one more primary attribute, and I'm going to call this fourth one vigor.
So I'm going to do the same steps again, and this time I'm going to replace resilience.
With vigor.
And we need the rep notify.
There we go.
We need the definition.
Looks like it created an inline function definition.
That's not what I wanted.
I think I hit generate inline definition.
No, it didn't.
It just gave me one.
So I'm going to cut that and just paste it in my CPP file.
Get my gameplay attribute rep Notify and replace resilience with vigor.
And we'll add it to get lifetime replicated props replacing resilience with vigor.
Okay, so we have four new attributes and I'm seeing that on Rep vigor is not implemented.
So that means I have a typo down here.
No, no typo.
It is implemented.
And I'm just going to compile just to force writer to catch up.
Yes, there should be no squiggles there, so we're good.
Okay, so we have four new attributes.
I'd like to initialize these attributes with a data table just to show that way of doing it.
And to do that, we have to expose our ability system component to blueprint so that we can set a specific
asset, a data table on that component.
So I'm going to open my player folder in my public.
Folder here and open or a player state where my ability system component variable is and I'm going to
add visible anywhere to the view property and then I'll go ahead and compile and launch the editor so
that we can see the details panel in the ability system component.
So you might have tried to look at the ability system component in the player state blueprint or perhaps
in the enemy blueprints and seeing that the details panel is empty.
And that's because we didn't expose our ability system component to the blueprint.
But now that we have, we can go into our player folder, into Aura Player State, open the full Blueprint
editor and choose ability system component.
And now we can see the details panel and all of the properties.
Now, if we want to use a data table to initialize some attributes, we have to add an element to this
array under attribute test called default starting data.
If we click plus, we now have this index and you can see that it has an attributes property with a
dropdown where you can choose an attribute set and a default starting table where you can choose a data
table.
Now you can't just choose any data table.
It has to have the correct row structure.
So we're going to make a data table that has that correct row structure right now.
I'm going to go ahead and create a folder for this.
Let's go to blueprints.
And where can we put this?
We can go to Ability system, right click new folder and make data.
And here in data we'll make a new data table by going to miscellaneous.
Selecting data table And which row structure do we want?
Well, it's going to be attribute metadata.
That's the structure that it has to be.
Now we can click okay and we can call this DBT underscore initial primary values.
And we can open it up and we can start adding some rows to this.
Now, if I click plus Add, you'll see that we have new row with base value, minimum value, maximum
value derived attribute info and can stack which is a boolean.
So what do we fill this in with?
Well, we can change the row name and if we change the row name we have to specify the attribute.
And the way that we have to do so is first by specifying the attribute set name, followed by a dot,
followed by the attribute so we can say ora attribute.
Set dot strength, for example, and we can specify a base value.
So I'm going to say ten for the strength.
Save and go back to our player state and set the properties on this index for default.
Starting data for attributes.
I'm going to choose aura, attribute set and for default starting table.
I'm going to choose initial primary values, compile, save and let's press play.
Let's do our show debug.
And now look at this.
We have lots of other attributes and strength is set to ten and it's showing our attributes more than
once.
But that's okay.
The point is that strength is set to ten and we can go in here and add a new row for the other attributes
as well.
We can say aura, attribute set dot intelligence.
We can set intelligence to a base value of 17.
Our character is a sorceress, after all, and we can click add.
We can do Aura attribute set dot.
I'm going to copy that.
And this one will be resilience.
This has to be spelled correctly.
Obviously, we'll set this to 11 and we'll have a new one.
We'll name this aura attribute set dot vigor and this will be nine.
Save that press play show debug and we see that our strength, intelligence, resilience and vigor now
have default values and that's great.
So this is one way to initialize your attribute values and you'll see that we have min value and max
value as well as some other stuff here.
Derived attribute info is not something that's exposed in this struct.
And then of course we have can stack.
Now what do these other things do?
Well, I'm going to go ahead and save all and close and open up the attribute set class.
So right click on you attribute set, I'm going to go to declaration or usages and I'm going to search
for attribute meta data.
And here's the struct.
It says Data table that allows us to define metadata about attributes.
Still a work in progress.
Now I'm not sure how long it's going to be a work in progress, but really the only thing this is useful
for is setting the initial value for our attributes.
It's not going to implement any sort of functionality for a minimum or a maximum.
All it does is initialize the values.
And for that reason, I'm not the biggest fan of using this method and it's not the method we're going
to end up using for our primary attributes.
I just wanted to show it to you because for some cases it is pretty handy.
You can just fill out that data table and the ability system component is just going to fill in those
values initially for you and that's great.
But the preferred method that I like to use and that most people I've seen like to use is by applying
a gameplay effect as soon as the game starts, for example, and that gameplay effect will set these
and all of our other attributes and that's what we're going to end up using.
But now you know this method and hey, the more you know, the better.
So great job and I'll see you in the next video.