Welcome back.
Now if we go to our load menu and we click plus for new game, we have this nice enter name widget.
And we can enter in a name and click New Slot.
And we switch to the next slot which is great, but we're not showing that player name.
In this video, we're going to bind that player name to a property on our view model.
And to do that we have to go back to C plus Plus and go into our load slot view model here and change
player name in a very specific way.
We have to make this a field notify.
That's right.
A field notify is how we can make this something that can be linked with the widget using this view
model.
So this is where the magic of view models is really going to come into play.
Now I'm going to have my player name and the rest of my field notifies beneath the load slot name and
slot index.
And I'll just go ahead and put a comment here that says field notifies.
And here's how I can make player name a field notify.
First of all, I'm going to make it edit anywhere.
I'm going to make it blueprint read write I'm going to give it full access here.
And then we're going to set this variable to be a field notify with field notify.
Now if we give it field notify we have to specify whether we want to give it a setter and a getter.
So if we give it a setter and a getter then we must now define setter and getter for this.
And they have to be specific setters and getters.
We have to have void set player name.
It has to be set with that variable name.
So set player name and it has to take in an F string called in player name.
The input parameter name is an important, but the function name is and we'll see in just a second why
this is important.
And we also need a getter f string.
Get player name const should be const return player name.
Now the setter.
I did not define right here on the same line.
And that's because I'm going to do something a little more involved than just setting it.
Not much more involved.
We're going to use a macro.
Now this macro is something built into the mVVM system in unreal and it's Yui mVVM.
Take note of the underscores set property value.
Now we give it the name.
Player name.
And we give it the value in player name.
Now we do get red squiggles, but if we compile.
We compile successfully.
Now, that's not typically something you see with Ryder.
You see it with Ves all the time.
Visual studio gets those false red squiggles all the time.
But Ryder, it's a little more rare.
But again, this is in beta at the time, so it's possible by the time you're watching this it might
be fixed, but this macro is how we can make a broadcast to our widgets.
And if we go to it.
We'll see what it does.
It's calling set property value.
And set property value is making a broadcast broadcast field value change.
You get the idea.
These are delegates.
This is just a system in place.
Making things supposedly easier I don't know, you be the judge.
Is this easier than just creating a widget controller like we've done earlier in the course?
I'm not so sure, but hey, it's a system for you, right?
And this is going to broadcast to widgets that have bound to this variable.
So that's the next step is to bind to the player name so that whenever we make this broadcast with this
macro, then we'll see that change reflected in the widget.
So our next step is to make that binding link.
So opening up our well we have our load screen game mode I don't really need that open I'm going to
close that.
And I'm going to go to blueprints UI load menu and find my load screen taken.
Because this player name right here is what I want to bind.
I'm going to check is variable first and I'm going to set it.
And it's called text player name.
And I'm going to bind this.
How do we bind it.
Well there's a couple of ways.
One way is to find it right here.
Find what we want to bind and choose bind right here.
And we can bind to our load slot view model and choose.
Now this way is still a little bit buggy as again this is in the beta.
So you got to bear with it.
But this way is a little bit buggy.
But it works consistently.
If we go down here to view bindings and click Plus Add widget.
And here's what we need to do.
We need to choose first of all from the dropdown here which widget we want to bind.
We want to bind our text player name right.
So let's find it text player name.
Here it is.
We select that and right here we take that text player name widget and choose which of its properties
we want to bind.
We want to bind its text right.
We need to select that text.
And here it is.
It's pink because it's an F text.
We select that okay.
Now this arrow in the middle is what determines which direction information can flow.
Do we want it to flow to our widget into the text value from somewhere else, say a ViewModel.
Well, yes.
Then we want that arrow pointing to the left.
But if we want to change it here somehow at runtime and when it changes, make that change apparent
to whatever's here on the right, say a ViewModel.
Then we would want to change this to go the other way, one way to ViewModel.
And then of course it can be two way.
It could be set up so that information can flow back and forth.
But for this we just want the ViewModel to send the information to the text.
So we're going to have it pointed to the left.
One way to widget.
And we're going to select from the dropdown our ViewModel.
And the ViewModel is going to be our load slot ViewModel.
The BP version.
Now here's the thing though on our ViewModel we only have an F string, and this is an F text.
We can't bind an f string to an F text, but what we can do is click the dropdown for these conversion
functions.
In fact, we don't have to click the dropdown.
We can just click on conversion functions.
And we want to convert from a string to a text.
So we use two text in parentheses string.
Select that.
And now that we're using a conversion function the string that we can give this can come from our view
model BP load slot view model player name.
We can select that.
And now we've successfully bound the player name on the view model through a conversion function to
the text in our player name widget.
It's kind of a rabbit hole right?
But that's what this binding means.
And you can also uncheck it to turn off that binding.
But what this means now, because the information flows one way to the widget, it takes the player
name as an F string from the load slot view model, converts it to text from string and sets the text
on the player name text block.
Okay, I think you get the point.
So now that we've done that, and also because we're broadcasting a value whenever we call set player
name, when we set the player name, we should see that change reflected in the widget.
We just have to set the player name.
We have to call this.
And when are we going to call it.
Well we can go to our load screen view model whenever we click the new slot button.
As we save the slot data and we call initialize slot, we can call that function on the load slot view
model called set player name.
And that's going to broadcast this to that bound variable.
So as soon as we know this player name it's that entered name.
We're going to take that load slot with load slots of slot.
And we're going to call set player name.
Instead of setting the player name variable directly we have to call the setter.
So we make that broadcast.
Like this.
So now we no longer need to set the player name directly.
We're going to call that setter that makes the broadcast.
So now that we're doing that and we have our binding here in the blueprint, we can compile and launch.
So we're going to save and close.
And now when we click the new slot button not only are we saving to disk, we're also setting the load
slot that our load screen view model has.
We're calling set player name on it, which is going to make a broadcast to our widget which has bound
of variable to it.
Let's see how this works.
Okay.
So.
Here's our load slot.
Here's our player name.
We know that we've bound the text on player name to the player name, and we're making a broadcast when
we click.
A button.
Let's click that button.
Not in this level.
We have to go to maps Load menu and open this.
So we can click on any one of these and enter a name.
I'm going to enter Stephen and click New Slot.
And look at that.
It says, Stephen.
Because of that binding, the binding magic is working.
Okay, so this has nothing to do with saving to disk.
This just has to do with the fact that we called that macro to broadcast over here in our mVVM load
slot.
We called you mVVM Set Property value.
This was called in response to our load screen view model calling set player name there.
So this happened before we even saved data to disk.
So we could have tested that before even creating a save game object.
That's okay though, because we're also saving to disk, which is good.
And whenever we save to disk, we need our slots to know we need them to have a status.
They need to know whether or not they've got valid data.
So at the beginning, when we first go to the level, we're showing the correct thing in the widget.
So we need a status and we're going to implement that in the next video.
I'll see you soon.