WEBVTT

00:07.070 --> 00:08.240
Welcome back.

00:08.600 --> 00:14.270
Now that we know we can choose a player start, we need to know which player start to choose.

00:14.270 --> 00:21.410
And if we just created a new character slot and we're loading in for the first time, we should have

00:21.410 --> 00:23.210
a default player start.

00:23.210 --> 00:28.250
And we're identifying these by the player start tag, which is really just an F name.

00:28.890 --> 00:32.520
Now if we're loading in a fresh new character.

00:33.200 --> 00:34.970
Let's say we go to the load menu.

00:35.000 --> 00:37.490
We press play, we click new game.

00:37.490 --> 00:39.200
We put our name in.

00:40.580 --> 00:41.870
We choose new slot.

00:41.870 --> 00:42.440
Right.

00:42.440 --> 00:47.840
Well, as soon as we select that slot and click play, we know we're going to the first dungeon.

00:48.260 --> 00:54.680
Well that first dungeon, that map is going to have a player start that we designate as a starting point.

00:54.680 --> 00:58.040
But it isn't necessarily the only player start in the level.

00:58.040 --> 00:59.030
In our case it is.

00:59.030 --> 01:05.690
But you may wish to have multiple, and you may wish to spawn in at the designated starting point for

01:05.720 --> 01:06.710
that dungeon.

01:06.710 --> 01:10.820
Well, in that case, we need to know what that player start tag should be.

01:11.210 --> 01:17.090
And if we press play and we go to that dungeon, we're now loading in, all actors are calling Begin

01:17.090 --> 01:19.850
Play for the first time, including the game mode.

01:19.850 --> 01:24.560
And the game mode is not going to know which player start to choose.

01:24.560 --> 01:30.290
It needs to know that right away, because choose player start is called quite early in the level.

01:30.290 --> 01:37.160
So we need to figure out what we want to do, whether we want to load in that data from disk or what.

01:37.160 --> 01:41.210
Well, we don't actually have to load in that data from disk.

01:41.210 --> 01:46.430
We can save it to any class that's persistent from level to level.

01:46.730 --> 01:52.700
And one of the fundamental classes that is persistent from level to level is the game instance.

01:53.000 --> 01:58.760
If we have a game instance and we set a property on the game instance such as a variable, we add to

01:58.760 --> 02:00.860
it for the player start tag.

02:00.860 --> 02:06.680
Then we can check that in any level that we load into and whatever it was set to last.

02:06.680 --> 02:08.570
That's the tag we can use.

02:08.900 --> 02:15.680
So I'd like to make a custom game instance class, and I'll start with the C plus plus side of things.

02:15.680 --> 02:23.570
We're going to go into Aura Public Game and let's make a new C plus plus class based on the game instance.

02:23.570 --> 02:27.500
Now we can go to all classes and search for game instance.

02:28.040 --> 02:28.970
And here it is.

02:28.970 --> 02:30.800
It's just game instance.

02:30.800 --> 02:34.730
We're going to select that and call this aura game instance.

02:35.030 --> 02:36.500
So this can go in the game folder.

02:36.500 --> 02:39.500
Let's create this class and go ahead and close down.

02:39.500 --> 02:44.120
Our Editor and Aura game instance is going to be quite simple.

02:44.180 --> 02:49.670
It's going to store any persistent data that we want to persist from one level to another.

02:49.670 --> 02:52.160
And that can be our player start tag.

02:52.160 --> 02:58.220
It can also be our slot name and index if we want to load in data from disk.

02:58.220 --> 03:01.250
Once we get to another level, which we will want to do that.

03:01.930 --> 03:08.920
So we're going to go into our new class in public game or a game instance, and we're just going to

03:08.920 --> 03:11.860
put a couple of variables in here.

03:11.860 --> 03:14.110
It's not going to be very elaborate.

03:14.110 --> 03:17.110
We're just going to have a public section.

03:18.340 --> 03:25.120
And first of all we're going to want a F name called player start tag.

03:27.670 --> 03:29.770
And we're going to give it a U property.

03:30.550 --> 03:36.340
And in addition to that, I'd like an F string called load slot name.

03:38.680 --> 03:41.290
Now we can start these as empty.

03:41.290 --> 03:46.300
I'm going to make this one an empty F string, and I'll make player start tag an empty F name.

03:47.050 --> 03:49.660
And these are all getting you properties.

03:51.340 --> 03:54.400
We want them participating in the garbage collection system.

03:54.730 --> 03:55.810
And I'll have one more.

03:55.840 --> 03:59.170
That's an INT 32 called load slot index.

03:59.470 --> 04:00.700
And this will be zero.

04:03.730 --> 04:05.290
So the player start tag.

04:05.290 --> 04:07.330
That's obvious why we would want that.

04:07.330 --> 04:12.340
If we load into a new level, we want to know which player start to choose right?

04:12.340 --> 04:19.570
And the load slot name and slot index allow us to load in data from disk, because when we load data

04:19.570 --> 04:24.550
from disk, if we look at our game mode base, we can remind ourselves how that's done.

04:25.170 --> 04:32.130
Get save slot data calls, load game from slot, passing in the slot name as an F string, and the slot

04:32.130 --> 04:32.640
index.

04:32.640 --> 04:35.220
That's how we identify saved slots.

04:35.220 --> 04:41.910
So our game instance can know this as soon as we've loaded it in in the load screen, we can set this

04:41.940 --> 04:43.350
on the game instance.

04:43.350 --> 04:48.570
And then when we load into a new level, we'll know which data to load in from disk.

04:48.600 --> 04:51.990
But for now we're just concerned with the player start tag.

04:51.990 --> 04:59.160
We're going to set that, which means we're going to need to have a default player start tag that is

04:59.160 --> 05:06.270
designated for any players that have just created their character, they've just created a new slot.

05:06.270 --> 05:09.780
There needs to be a default slot to set this to.

05:10.200 --> 05:17.550
So we need to set this player start tag, and we can start by going to our load screen ViewModel.

05:17.850 --> 05:25.170
Because as we go and create a first slot, our new slot button pressed is called right here.

05:25.170 --> 05:30.150
We need to specify that first player start that we should load into.

05:30.480 --> 05:35.730
In other words, we should get our game instance and tell the game instance what the player start should

05:35.730 --> 05:36.360
be.

05:36.360 --> 05:41.340
And while we're at it, we can tell it what the slot name and slot index are.

05:41.820 --> 05:45.630
So down here at the bottom, let's get the game instance.

05:45.630 --> 05:48.240
It's going to be you or a game instance.

05:50.960 --> 05:53.150
We'll call it or a game instance.

05:53.720 --> 05:56.240
Now I need to include this type.

05:56.240 --> 05:58.580
So we'll go ahead and add an include for it.

05:58.580 --> 06:04.580
And we're going to call or a game mode get game instance.

06:04.670 --> 06:08.570
And because this returns just a game instance we're going to cast.

06:10.250 --> 06:13.580
So we'll cast to you or a game instance.

06:16.760 --> 06:23.630
And as long as we're using the correct Oragame instance, this should be a valid pointer and we can

06:23.630 --> 06:25.310
take our game instance.

06:26.990 --> 06:37.340
And we can set its load slot name because we have our slot, we have load slots indexed with slot and

06:37.340 --> 06:38.900
it has a slot name.

06:40.130 --> 06:41.900
It's called load slot name.

06:42.800 --> 06:45.290
And we can set or a game instance.

06:47.430 --> 06:49.170
Load slot index.

06:49.530 --> 06:55.710
By getting our load slots of slot and getting the slot index.

06:56.350 --> 07:01.990
And then we can set the player start and the player start, which we called player start.

07:01.990 --> 07:08.380
Tag needs to exist in our first level, so that's something we can keep track of where we're setting

07:08.380 --> 07:12.340
that first level, that default level that would be on the game mode.

07:12.340 --> 07:19.330
So if we go into aura game mode base, along with the default map name and a default map, we can have

07:19.330 --> 07:21.100
a default player start as well.

07:21.100 --> 07:27.850
So this can be an F name called default Player start, and we'll call it default Player start tag,

07:28.450 --> 07:30.790
and we'll give it a U property.

07:30.790 --> 07:31.900
And it defaults only.

07:31.900 --> 07:34.090
And we'll have to set this in the game mode.

07:34.360 --> 07:38.020
And now we can use this in NVM load screen.

07:38.020 --> 07:49.960
We can set or a game instance player start tag equal to or a game mode default player start tag.

07:50.350 --> 07:56.380
Now our player start is going to have the proper value when we've created our first slot.

07:56.440 --> 08:02.620
So now that we're going to be setting that or a game instance player start tag, then our aura game

08:02.620 --> 08:07.390
mode base can get that tag from the game instance and choose Player Start.

08:07.780 --> 08:14.590
What we can do is first thing get our game instance which we're already getting in load screen.

08:14.590 --> 08:16.030
It's this line here.

08:17.310 --> 08:20.160
We can use that in or a game mode base up here.

08:20.690 --> 08:28.340
We do have to include our A game instance, but we also don't need to use or a game mode because we're

08:28.340 --> 08:29.330
in the game mode here.

08:29.330 --> 08:31.220
So we can just get game instance.

08:31.910 --> 08:37.820
Now we have our A game instance here, and when we're checking the player start tag, we can check it

08:37.820 --> 08:40.700
against or a game instance.

08:41.770 --> 08:47.830
Player start tag, and whatever that player start tag is set to, that's the player start that we'll

08:47.830 --> 08:48.760
start at.

08:49.240 --> 08:50.890
Now we can test this out.

08:50.890 --> 08:52.600
We can run in debug mode.

08:56.070 --> 09:00.330
And we have a couple things that we need to do right away.

09:00.360 --> 09:08.340
First, we have to go to our game mode class, and I'm going to go into the game folder and open up

09:08.340 --> 09:13.680
or a game mode and set that default player start tag right here.

09:13.950 --> 09:16.770
Now it's going to be for our first dungeon.

09:16.770 --> 09:21.420
So I'm going to call this dungeon one player Start one.

09:21.990 --> 09:27.060
And that's the tag that we're going to set on our game instance, provided that we're now using the

09:27.060 --> 09:30.210
aura game instance, which we need to make a blueprint for.

09:30.210 --> 09:32.550
And I'm going to do that here in the game folder.

09:32.550 --> 09:35.760
So new blueprint or a game instance.

09:36.710 --> 09:38.090
We'll choose that.

09:38.090 --> 09:44.870
Call this BP or a game instance, and we're going to make sure that our project uses this game instance.

09:44.870 --> 09:49.010
Let's go to Project Settings and search for game instance.

09:49.520 --> 09:51.290
And here's the game instance class.

09:51.290 --> 09:55.670
For our project we need to now choose BP or a game instance.

09:55.670 --> 09:57.680
Now we'll be using that.

09:57.680 --> 10:01.580
And now we should be able to load in at the correct player start.

10:01.580 --> 10:07.940
And just to remind ourselves, if we look in BP or a game mode, we named it to dungeon one player start

10:07.940 --> 10:08.240
one.

10:08.240 --> 10:09.500
I'm going to copy that.

10:09.500 --> 10:15.350
And I'm also going to make sure that Load Screen game mode has that set as well.

10:16.020 --> 10:21.240
So that way when we retrieve it from the game mode, we'll get the correct value.

10:21.270 --> 10:24.780
Now we just need a player start that has that tag.

10:24.810 --> 10:26.970
I'm going to go ahead and duplicate this player.

10:26.970 --> 10:29.190
Start and move it on over to here.

10:30.320 --> 10:33.200
And give this player start that tag.

10:33.410 --> 10:35.630
Dungeon one, player start one.

10:36.110 --> 10:37.820
So now this level has a player.

10:37.820 --> 10:39.290
Start with that tag.

10:39.590 --> 10:40.610
Now here's the thing.

10:40.610 --> 10:45.110
We have to save all and go back to our load screen our load menu.

10:45.110 --> 10:48.740
And we have to press play and delete these slots.

10:50.420 --> 10:56.060
We had to make a new slot because as soon as we create that new slot, that's when that player start

10:56.060 --> 10:58.760
tag will be set on our game instance.

10:58.760 --> 11:00.830
So I'm going to call this Steven.

11:01.160 --> 11:05.510
New slot should be First Dungeon if we select it and click on play.

11:05.510 --> 11:08.660
Now I go over to the correct spot.

11:08.660 --> 11:11.420
Our correct player start way over there.

11:12.120 --> 11:15.180
So we saw that we loaded in at the correct slot.

11:15.180 --> 11:15.840
Right.

11:15.840 --> 11:21.960
But the game instance only gets that player start tag set whenever we create a new slot.

11:21.960 --> 11:25.350
If we come back in, select the slot and press play.

11:26.190 --> 11:32.370
Well, we don't get spawned at that player start tag because we're not actually setting the game instance

11:32.370 --> 11:34.080
player start tag to that.

11:34.440 --> 11:39.750
What we need is a way to keep track of what our last player start was.

11:40.080 --> 11:43.530
So if we're loading in for the first time, this is fine.

11:43.830 --> 11:48.660
Over here in MVVM load screen, when new slot button is pressed.

11:48.660 --> 11:49.320
That's cool.

11:49.320 --> 11:53.790
We can set our player start tag on the game instance to the default one.

11:54.420 --> 11:58.260
But we need a way to save where we last were.

11:58.500 --> 12:05.250
So whenever we exit the game, for example, we need to save our last player start.

12:05.790 --> 12:10.740
So we need to figure out when exactly we should save our last player start.

12:10.770 --> 12:15.420
In other words, we need a sort of checkpoint fdname that we can save.

12:15.950 --> 12:22.370
So this is great that we're setting our game instance player start tag the first time we create a slot.

12:22.370 --> 12:26.930
But what about when we select a slot that's already existed for a while?

12:27.290 --> 12:30.620
We're going to need to save our last player start that we were at.

12:30.830 --> 12:34.520
In other words, we need a sort of checkpoint player start tag.

12:34.520 --> 12:40.850
And that way when loading in a saved slot that's not brand new, we'll know what to set our game instance

12:40.850 --> 12:45.020
player start tag to, and that's something we'll do in the next video.

12:45.680 --> 12:47.180
So a great job.

12:47.210 --> 12:49.850
Save your work and I'll see you in the next video.
