All right.
So now that we know when an effect is applied and we have the ability to get the asset tags for that
effect and we want those tags to be broadcast over to the widget controller.
We need a delegate.
So I'd like to make a delegate for broadcasting the asset tags.
Let's go into aura ability system components and make that delegate.
Now, I don't plan on binding this from Blueprint.
Our widgets aren't going to bind to this delegate.
It's our widget controller that's going to bind to this delegate.
So what I'm going to do is declare a multicast delegate.
That's not dynamic.
And it's going to have one param.
And that param is going to be the asset tag or if we'd like the gameplay tag container with all the
asset tags, it's really up to us.
Now I'm going to call this F effect asset tags and our single parameter.
Again, it could be a gameplay tag or it could be a gameplay tag container.
I'm going to use gameplay tag container.
So we're going to have a gameplay tag container.
We'll go ahead and make it a const f gameplay tag container reference.
And as we've seen with declare multicast delegate, we don't put the name of this parameter.
We don't say comma followed by tag container or anything like that.
But sometimes what I've seen and this can be a little helpful is making a comment here, an inline comment
to sort of hint about what this is so we could say asset tags.
And so even though that this comment does nothing to the code, it tells us when we look at it, that
that's what this tag container is.
It's the asset tags.
Now, our ability system component needs this delegate.
It needs to be able to broadcast the delegate and our widget controller needs to be able to bind to
it.
So we need to make this public.
So in the public section, we're going to have our effect asset tags and we're going to call this effect
asset tags and we're going to broadcast it.
Now, what we can do if we like, is we can broadcast it here, in effect applied because we know this
gets called and we have our asset tags, we have the tag container.
So all we need to do here is just say effect asset tags, dot broadcast and pass in tag container just
like that.
And then any class who binds to our effect asset tags delegate will receive a tag container filled with
the asset tags.
Pretty simple.
So really quickly to test this out, what we can do is we can go into our overlay widget controller
and bind to effect asset tags if we like.
So let's do it.
We'll go into UI widget controller and overlay widget controller.
But you know what?
I'm going to go into the CPP file directly.
So overlay widget controller TCP and here in bind callbacks to dependencies, I'd like to get our ability
system component and we know that this is a ability system component, but we want the aura ability
system component.
So I'm going to cast to you aura, ability, system component, our ability system component.
And using this, I'm going to get that F effect asset tags called effect asset tags.
Now we know if we're going to bind to this delegate that we need a callback function, right?
Well, not necessarily.
If we hit Dot, we have a lot of options here and one of them is to add a lambda.
Now, a lambda is an anonymous function.
It doesn't have a name.
It doesn't get declared anywhere.
It's not a member function.
It's just a function.
And add lambda lets us define right here in the parentheses whatever functionality we want.
Called in response to the delegate broadcast.
A lambda looks like this.
I'm going to hit enter a couple times and just put it right here.
In fact, I'll go ahead and put my semicolon there and right here this is inside the parentheses to
add Lambda ad lambda requires a lambda.
We're going to make a lambda here.
So first we put square brackets, then we put parentheses and then we put curly brackets.
Okay, so this is the signature for a lambda.
But if we bind anything to a delegate, it needs that signature.
It needs the signature of a function that can take an gameplay tag container.
Well, this lambda has parentheses.
That's where the input parameter list goes.
So we can put a const f gameplay tag container reference and we can call this asset tags.
Doesn't matter what we call it.
So now we have a lambda which is an anonymous function.
And when the broadcast happens for this delegate, this lambda will be called and it has an input parameter
called asset tags, it will receive that from the delegate.
And what happens when it gets called whatever we put in the body here in our curly brackets, I'm going
to put them on a new line to make this a little easier to read.
And we can define what happens here.
So what do we want to happen?
Right.
Because we've just now bound a lambda to affect asset tags on the ability system component.
Well, why don't we just print a debug message and make sure it works?
So back here in aura ability system component, I think we're done with this debug message, but what
I'd like to do is copy it or rather control X to cut it.
So now our ability system component is not doing any debug messages, it's just broadcasting a delegate.
But now our widget controller has a lambda that will fire off in response to that delegate.
Well, I'm going to control V right here and we can paste this code in where we can loop through the
tag container.
Now here inside the lambda, it's going to receive asset tags.
That's the tag container.
So that's what we have to loop through here.
So we have a for loop looping through all the tags in the asset tags container and we don't need this
comment.
And well, we know what these two lines do.
They take each tag in asset tags and add an on screen debug message basically the same thing as we were
doing before.
So the difference here now is that the ability system component will broadcast this delegate in response
to having any effect applied to it.
And it's going to send that tag container and then it's the widget controller that's going to parse
the data.
It's going to loop through the tag container and print it all to the screen.
So if we can run this and it works, then that's actually really cool, right?
Because this means we don't have to go and declare callback functions for all the delegates that we
want to bind to.
Right.
This makes things a little bit simpler.
I mean, look at all these callbacks we had to make for all of these delegates.
What if we could just use lambdas for all of those?
Well, let's make sure this works first.
Okay.
Let's go ahead and hit debug and see if we can get some messages printed to the screen.
Okay.
So we're back.
I'm going to go ahead and let it open up my gameplay effects just to make sure our potion mana gameplay
effect has two tags in its asset tags potion Heal has one and Crystal Heal has one.
So let's press.
Play and get a crystal and look at that.
It's working.
Our lambdas are working.
How about that?
This is great.
Now, if you're skeptical, you can place a breakpoint here.
So I got a breakpoint.
I'm going to press play and pick up the potion.
And look, the breakpoint works even in a lambda.
So a lambda is one of those tools in C plus plus that we have at our disposal that allows us to kind
of avoid having to create a bunch of member functions, especially for things that are simple, right?
If we're going to bind a callback to a delegate and it's pretty simple, there's really no point in
creating a whole callback function for it.
A lambda is cleaner sometimes and it's also kind of fancy, right?
It's kind of cool.
So now that we know how to do that, we just have one more tool in our tool belt.
And if you already knew about Lambdas, maybe you've been using this already, then you already have
this tool in your toolbox.
And I think that's great that you've been taking advantage of it.
So excellent job.
We're now one step closer to our goal.
We have those asset tags here in our widget controller overlay widget controller.
The next step is to get them to the widgets themselves so we can do that next.
In the meantime, I'm going to go ahead and hit the stop button.
We're done with this and I'll see you in the next video.