Welcome back.
Now that we know we can choose a player start, we need to know which player start to choose.
And if we just created a new character slot and we're loading in for the first time, we should have
a default player start.
And we're identifying these by the player start tag, which is really just an F name.
Now if we're loading in a fresh new character.
Let's say we go to the load menu.
We press play, we click new game.
We put our name in.
We choose new slot.
Right.
Well, as soon as we select that slot and click play, we know we're going to the first dungeon.
Well that first dungeon, that map is going to have a player start that we designate as a starting point.
But it isn't necessarily the only player start in the level.
In our case it is.
But you may wish to have multiple, and you may wish to spawn in at the designated starting point for
that dungeon.
Well, in that case, we need to know what that player start tag should be.
And if we press play and we go to that dungeon, we're now loading in, all actors are calling Begin
Play for the first time, including the game mode.
And the game mode is not going to know which player start to choose.
It needs to know that right away, because choose player start is called quite early in the level.
So we need to figure out what we want to do, whether we want to load in that data from disk or what.
Well, we don't actually have to load in that data from disk.
We can save it to any class that's persistent from level to level.
And one of the fundamental classes that is persistent from level to level is the game instance.
If we have a game instance and we set a property on the game instance such as a variable, we add to
it for the player start tag.
Then we can check that in any level that we load into and whatever it was set to last.
That's the tag we can use.
So I'd like to make a custom game instance class, and I'll start with the C plus plus side of things.
We're going to go into Aura Public Game and let's make a new C plus plus class based on the game instance.
Now we can go to all classes and search for game instance.
And here it is.
It's just game instance.
We're going to select that and call this aura game instance.
So this can go in the game folder.
Let's create this class and go ahead and close down.
Our Editor and Aura game instance is going to be quite simple.
It's going to store any persistent data that we want to persist from one level to another.
And that can be our player start tag.
It can also be our slot name and index if we want to load in data from disk.
Once we get to another level, which we will want to do that.
So we're going to go into our new class in public game or a game instance, and we're just going to
put a couple of variables in here.
It's not going to be very elaborate.
We're just going to have a public section.
And first of all we're going to want a F name called player start tag.
And we're going to give it a U property.
And in addition to that, I'd like an F string called load slot name.
Now we can start these as empty.
I'm going to make this one an empty F string, and I'll make player start tag an empty F name.
And these are all getting you properties.
We want them participating in the garbage collection system.
And I'll have one more.
That's an INT 32 called load slot index.
And this will be zero.
So the player start tag.
That's obvious why we would want that.
If we load into a new level, we want to know which player start to choose right?
And the load slot name and slot index allow us to load in data from disk, because when we load data
from disk, if we look at our game mode base, we can remind ourselves how that's done.
Get save slot data calls, load game from slot, passing in the slot name as an F string, and the slot
index.
That's how we identify saved slots.
So our game instance can know this as soon as we've loaded it in in the load screen, we can set this
on the game instance.
And then when we load into a new level, we'll know which data to load in from disk.
But for now we're just concerned with the player start tag.
We're going to set that, which means we're going to need to have a default player start tag that is
designated for any players that have just created their character, they've just created a new slot.
There needs to be a default slot to set this to.
So we need to set this player start tag, and we can start by going to our load screen ViewModel.
Because as we go and create a first slot, our new slot button pressed is called right here.
We need to specify that first player start that we should load into.
In other words, we should get our game instance and tell the game instance what the player start should
be.
And while we're at it, we can tell it what the slot name and slot index are.
So down here at the bottom, let's get the game instance.
It's going to be you or a game instance.
We'll call it or a game instance.
Now I need to include this type.
So we'll go ahead and add an include for it.
And we're going to call or a game mode get game instance.
And because this returns just a game instance we're going to cast.
So we'll cast to you or a game instance.
And as long as we're using the correct Oragame instance, this should be a valid pointer and we can
take our game instance.
And we can set its load slot name because we have our slot, we have load slots indexed with slot and
it has a slot name.
It's called load slot name.
And we can set or a game instance.
Load slot index.
By getting our load slots of slot and getting the slot index.
And then we can set the player start and the player start, which we called player start.
Tag needs to exist in our first level, so that's something we can keep track of where we're setting
that first level, that default level that would be on the game mode.
So if we go into aura game mode base, along with the default map name and a default map, we can have
a default player start as well.
So this can be an F name called default Player start, and we'll call it default Player start tag,
and we'll give it a U property.
And it defaults only.
And we'll have to set this in the game mode.
And now we can use this in NVM load screen.
We can set or a game instance player start tag equal to or a game mode default player start tag.
Now our player start is going to have the proper value when we've created our first slot.
So now that we're going to be setting that or a game instance player start tag, then our aura game
mode base can get that tag from the game instance and choose Player Start.
What we can do is first thing get our game instance which we're already getting in load screen.
It's this line here.
We can use that in or a game mode base up here.
We do have to include our A game instance, but we also don't need to use or a game mode because we're
in the game mode here.
So we can just get game instance.
Now we have our A game instance here, and when we're checking the player start tag, we can check it
against or a game instance.
Player start tag, and whatever that player start tag is set to, that's the player start that we'll
start at.
Now we can test this out.
We can run in debug mode.
And we have a couple things that we need to do right away.
First, we have to go to our game mode class, and I'm going to go into the game folder and open up
or a game mode and set that default player start tag right here.
Now it's going to be for our first dungeon.
So I'm going to call this dungeon one player Start one.
And that's the tag that we're going to set on our game instance, provided that we're now using the
aura game instance, which we need to make a blueprint for.
And I'm going to do that here in the game folder.
So new blueprint or a game instance.
We'll choose that.
Call this BP or a game instance, and we're going to make sure that our project uses this game instance.
Let's go to Project Settings and search for game instance.
And here's the game instance class.
For our project we need to now choose BP or a game instance.
Now we'll be using that.
And now we should be able to load in at the correct player start.
And just to remind ourselves, if we look in BP or a game mode, we named it to dungeon one player start
one.
I'm going to copy that.
And I'm also going to make sure that Load Screen game mode has that set as well.
So that way when we retrieve it from the game mode, we'll get the correct value.
Now we just need a player start that has that tag.
I'm going to go ahead and duplicate this player.
Start and move it on over to here.
And give this player start that tag.
Dungeon one, player start one.
So now this level has a player.
Start with that tag.
Now here's the thing.
We have to save all and go back to our load screen our load menu.
And we have to press play and delete these slots.
We had to make a new slot because as soon as we create that new slot, that's when that player start
tag will be set on our game instance.
So I'm going to call this Steven.
New slot should be First Dungeon if we select it and click on play.
Now I go over to the correct spot.
Our correct player start way over there.
So we saw that we loaded in at the correct slot.
Right.
But the game instance only gets that player start tag set whenever we create a new slot.
If we come back in, select the slot and press play.
Well, we don't get spawned at that player start tag because we're not actually setting the game instance
player start tag to that.
What we need is a way to keep track of what our last player start was.
So if we're loading in for the first time, this is fine.
Over here in MVVM load screen, when new slot button is pressed.
That's cool.
We can set our player start tag on the game instance to the default one.
But we need a way to save where we last were.
So whenever we exit the game, for example, we need to save our last player start.
So we need to figure out when exactly we should save our last player start.
In other words, we need a sort of checkpoint fdname that we can save.
So this is great that we're setting our game instance player start tag the first time we create a slot.
But what about when we select a slot that's already existed for a while?
We're going to need to save our last player start that we were at.
In other words, we need a sort of checkpoint player start tag.
And that way when loading in a saved slot that's not brand new, we'll know what to set our game instance
player start tag to, and that's something we'll do in the next video.
So a great job.
Save your work and I'll see you in the next video.