Welcome back.
Now we've added some native gameplay tags.
We have montage attack, left hand, right hand and weapon.
So my goal is to be able to get the montage as well as its associated montage tag so we know which socket
to look for for that montage.
And then we can have attack montages for left hand or right hand weapon, whatever, and we'll know
which one corresponds to which gameplay tag which corresponds to a socket.
For that reason I want a struct that links up a montage and a gameplay tag.
Something called a tagged montage.
We can use a struct for that and I'd like to define it in my combat interface because then I could just
call a function on the combat interface for retrieving any tagged montages.
There may be multiple.
Perhaps we'd like an algorithm to pick one at random.
So we're going to make a struct that contains a montage and a gameplay tag and we're going to define
it in the combat interface, and then we'll add a function to retrieve them in the combat interface
so that we can get the montage here and we can know what gameplay tag to listen to and we can send that
gameplay tag in our montage.
So let's get to it.
I'm going to go into my public folder, into interaction, into combat interface, and we're going to
define a new struct here.
This will be all the way up just below the includes we're going to say struct f tagged montage.
This will be a use struct.
We're going to make it a blueprint type and give it a generated body and it's going to get an anim montage.
We're going to forward declare you anim montage.
It's going to be a pointer called montage initialized to a null pointer.
We're going to give it a new property with edit defaults only and blueprint read only.
Now combat interface shows that you anim montage doesn't have to be forward declared.
That's redundant, so I'm going to go ahead and remove that and we'll also have an gameplay tag.
So f gameplay tag, we're going to call this montage tag and we'll also make it edit Defaults only.
Blueprint Read only.
Now that means we need to include gameplay tag container.
So let's include gameplay tag container.
And we now have a tag montage struct.
So now that we have a tagged montage struct, we need an array of these on our character for all attacks.
We're going to call these attack montages.
So we're going to have an array of this, which means we're going to include the combat interface in
our base character class or a character base.
Let's go up to the top to our includes.
We already have combat interface.
Let's go ahead and add a T array.
I'm going to add it in the public section here and it's going to be a T array of type F tagged montage.
Called attack montages.
It's going to get a new property with edit anywhere.
Categorycombat.
And now that we have attack montages, this is something that we'll go ahead and set on a character
by character basis.
So I like the combat interface to have a function that can easily retrieve these attack montages and
perhaps even retrieve a selection from among them at random.
For now, let's just have a function that retrieves the attack montages.
So here in combat interface, we're going to make a function that returns a t array of F tagged montages
called get attack montages.
I'd like this to be blueprint callable and a blueprint native event.
So we're going to copy the U function from get Avatar and we'll implement this in a character base.
By overriding it here, we're going to override virtual t array f tagged montage, get attack montages,
implementation, and here in the definition, we're just going to return attack montages.
So now that our interface has this function, we can retrieve the attack montages from Blueprint and
we can link up any montages with the appropriate tag.
Let's go ahead and compile and launch the editor.
Okay.
So back in the editor, we're going to open up.
Let's open up our Goblin Spear, shall we?
We're going to go to Content Blueprints.
Character.
Goblin, Spear.
Open up, Goblin Spear and search for attack montages.
Here they are.
And our Goblin Spear only needs one element here.
If we expand the dropdown for it, we see that we can choose am attack Goblin spear and for the montage
tag we want montage attack weapon.
That way we know which socket to look for.
So back in the melee attack, instead of just hard coding in that montage, we can get that montage
along with its tag using our static function on the combat interface.
Since this is a blueprint native event get attack montages.
Now this requires the target, which is basically this avatar actor from actor info.
We can go ahead and use that and attack montages retrieves an array, right?
So really we just need to pick one of them.
So if there are more than one, what we should do is pick one at random and it'd be nice to have a built
in function or maybe a blueprint function library function that can just do this for us, get one at
random.
It would do something like this.
It would take the array and get the length of it.
That would be the number of elements in the array.
It would subtract one from it.
Because arrays are indexed starting at zero, and then it would get a random value between zero and
this number length minus one.
So we would say random int in range, random integer in range between zero and this value.
And then it would retrieve an element from this array.
So we could use get and we can get a ref.
So this would be a random selection from that array.
And this random selection is a struct that we can break.
We can break the tagged montage.
Let's make some more room here.
And for the montage we can hook that into montage to play and we can hook this up.
And the montage tag is going to be the tag now that we listen for instead of this one.
So I'm going to take the montage tag.
I'm going to add a couple reroute nodes here.
And hook that into wait gameplay event.
The only thing now we have to do is go into that goblin spear attack.
Let's browse to that and open it up and change the tag that it's sending instead of this one.
It's now going to be a montage attack weapon.
So now that that's happening, our melee attack will be listening for that.
Now we're not taking care of switching which combat socket we're looking for.
We're always looking for the combat socket on the weapon.
But at least now we're getting the montage from the actor using our combat interface function.
And after a little bit of blueprint randomization, if that array of montages has more than one, well,
we'll get one at random.
So, so far, we shouldn't see anything different.
We should be able to get attacked.
And we're being attacked by that melee attacker.
And that's good.
But we are one step closer to having something that will work with other types of enemies, because
now that it's up to the enemy character class itself to have montages and link those up with tags,
then those montages can broadcast that given tag and then we can use that tag to identify which socket
to look for and get combat socket location.
So our next step is to change get combat socket location so it takes a gameplay tag and returns the
location of the correct socket based on that tag and we'll do that next.
So great job.
I'll see you soon.