WEBVTT

00:07.040 --> 00:08.030
Welcome back.

00:08.850 --> 00:15.870
Now we know that we can load in information from disk, but that information is a little bit limited.

00:16.200 --> 00:23.940
If we open our load menu and press play, we know that if our slot was just created, then its map is

00:23.940 --> 00:25.350
set to first Dungeon.

00:25.350 --> 00:29.220
And if we select that slot and press play, we go to the first dungeon.

00:29.550 --> 00:34.800
Okay, well that's great, but we need to load in more information than that.

00:35.070 --> 00:42.360
Now we know we need to load in all of our saved attribute values, at least the primaries and our spells,

00:42.360 --> 00:49.590
any abilities that we have and whatever abilities we have equipped to whichever slots all of that stuff

00:49.590 --> 00:51.570
definitely needs to be loaded in, right?

00:51.570 --> 00:52.410
Of course.

00:52.530 --> 01:00.570
But in addition to that, we need to know where to load in in any given map, because a map might have

01:00.570 --> 01:07.620
different entrances and exits, it might have a starting point, but you may wish to have some kind

01:07.620 --> 01:14.010
of staircase that goes down to another dungeon, and at which point you travel to the other map and

01:14.010 --> 01:16.320
end up at a specific location in that map.

01:16.320 --> 01:22.980
And if you come back, maybe you want to spawn in right at that entrance, as opposed to at the beginning

01:22.980 --> 01:25.230
of the dungeon where you first spawned in.

01:25.230 --> 01:32.940
So there needs to be a way to choose where we spawn, and by default we spawn at player starts, and

01:32.940 --> 01:40.200
the game mode has the ability to choose a player start and player starts are a specific kind of actor

01:40.200 --> 01:41.520
that can be identified.

01:41.520 --> 01:43.860
In fact, they have a player start tag.

01:43.860 --> 01:47.610
If we select our player start right here, we see the player start tag.

01:47.610 --> 01:53.250
It's set to none, but we can use the player start tag to identify player starts if we want to.

01:53.430 --> 01:57.450
So how do we discern what player start to choose?

01:57.450 --> 02:02.340
Well, we can go back to C plus plus into our aura game mode base.

02:02.490 --> 02:09.450
And because this is based on a game mode base, let's go to a game mode base and just take a look.

02:09.450 --> 02:12.090
And if we search for choose.

02:12.820 --> 02:17.740
There's a function called Choose Player Start and this is a blueprint native event.

02:18.070 --> 02:24.610
It says return the best player start for this player to spawn from default implementation looks for

02:24.610 --> 02:26.890
a random unoccupied spot.

02:27.280 --> 02:32.170
Now it says that the player is the controller for whom we are choosing a player.

02:32.170 --> 02:35.860
Start returns actor chosen as the player start.

02:35.860 --> 02:39.100
Usually a player starts, so it returns an a actor.

02:39.100 --> 02:40.390
It doesn't have to be.

02:40.390 --> 02:41.440
It can be an actor.

02:41.440 --> 02:44.680
But usually we choose a player start.

02:44.890 --> 02:49.900
So because this is a blueprint native event, we can override its implementation.

02:49.900 --> 02:54.490
And if we want to do that, we can choose what player start to spawn at.

02:54.490 --> 02:56.770
Now which one are we going to choose?

02:56.770 --> 03:00.310
Well, that's going to need to be something we decide of course.

03:00.700 --> 03:03.220
So let's see how choose player Start works.

03:03.220 --> 03:07.540
Let's learn a little bit about how we can use it and how we can choose a specific player.

03:07.540 --> 03:08.140
Start.

03:08.720 --> 03:10.070
Now it's a public function.

03:10.070 --> 03:13.220
So we're going to override it in the public section.

03:14.000 --> 03:20.930
We're going to say virtual a actor pointer choose player start implementation override.

03:21.410 --> 03:23.990
We can go ahead and implement this function.

03:23.990 --> 03:26.540
And we don't need to call super.

03:26.540 --> 03:29.270
We want to choose the player start and return it.

03:29.840 --> 03:34.190
So I'm going to get all actors of a specific class.

03:34.190 --> 03:35.870
The player start class.

03:36.170 --> 03:41.240
And from those player starts I'm going to find one with a given tag and return it.

03:41.240 --> 03:42.590
That's what I'd like to do.

03:42.590 --> 03:47.510
Before I bother with all that though, I'm going to see what happens if we return a null pointer.

03:48.350 --> 03:49.760
What ends up happening?

03:49.760 --> 03:52.880
If that's the case, does the whole game crash?

03:52.880 --> 03:54.680
Does the world come crashing down?

03:54.680 --> 03:56.210
Let's just find out.

04:00.290 --> 04:05.210
So I'm just going to press play in this dungeon map and look at what happens.

04:05.210 --> 04:07.700
Really, we don't get a player start.

04:07.700 --> 04:09.590
We spawn in right here.

04:14.490 --> 04:16.110
Right there in the ground.

04:16.110 --> 04:21.360
So returning null for our player start is probably not the best idea.

04:21.360 --> 04:25.020
We should probably always return at least something, right?

04:25.020 --> 04:26.910
We need some kind of player start.

04:26.910 --> 04:33.930
So what we can do when we get all actors of the player start class is we could find the first one and

04:33.930 --> 04:34.890
just set that.

04:34.890 --> 04:39.630
And if we don't find any player starts that have the tag we're looking for, we'll return that first

04:39.630 --> 04:40.050
one.

04:40.050 --> 04:44.850
So here's what we'll do is first we're going to call get all actors of class.

04:44.850 --> 04:47.010
That's a you gameplay statics function.

04:47.160 --> 04:49.380
It's called get all actors of class.

04:49.380 --> 04:52.020
Now it requires a world context object.

04:52.020 --> 04:54.030
I'm just going to call Get world here.

04:55.790 --> 05:02.570
We can pass the world in itself as a world context object, and we need to pass in an actor class to

05:02.570 --> 05:06.470
filter this by, I'm going to use a player start.

05:08.610 --> 05:09.930
Static class.

05:11.210 --> 05:14.480
Now that means I need to include the player start header file.

05:14.480 --> 05:15.950
So we'll go ahead and do that.

05:16.160 --> 05:21.860
Now this function also needs a t array of actors called out actors that it can fill in with actors.

05:21.860 --> 05:25.250
So I'm going to make a T array of a actor pointers.

05:27.820 --> 05:29.650
Called actors.

05:29.650 --> 05:31.900
And we'll pass in our actors here.

05:35.150 --> 05:47.180
And if actors dot num is greater than zero, then we have actors, but otherwise we need to return a

05:47.180 --> 05:47.840
null pointer.

05:47.840 --> 05:51.230
So we're going to return null pointer here at the end.

05:51.230 --> 05:59.660
And if actors dot num is greater than zero, I'm going to first start off creating an a actor pointer

05:59.660 --> 06:01.130
called Selected Actor.

06:01.430 --> 06:04.280
And I'll start it off with actors of zero.

06:04.280 --> 06:05.570
So the first one.

06:06.470 --> 06:08.720
But then I want to loop over actors.

06:08.720 --> 06:18.290
I'm going to say for a actor actor in actors, and I'd like to cast it to a player start.

06:18.650 --> 06:25.430
So I'm going to say a player start pointer player start equals cast to a player start.

06:27.170 --> 06:27.980
Actor.

06:29.470 --> 06:33.430
And I'll go ahead and wrap this in an if statement.

06:35.850 --> 06:38.820
And I'll check that player starts player start tag.

06:38.820 --> 06:42.090
We can say if player start.

06:45.110 --> 06:50.360
Player start tag and we can check to see if it equals a specific F name.

06:50.360 --> 06:53.060
For now, I'm just going to hard code it to see how this works.

06:53.060 --> 07:00.620
I'm going to say the tag the tag, and if that player start matches this tag then I'm going to set selected

07:00.620 --> 07:04.160
actor equal to this player start.

07:05.390 --> 07:10.550
And by the end of this for loop, at the very end of it, I'm going to return selected actor.

07:11.600 --> 07:15.980
And of course, if we find a player start, there's no need to continue this for loop.

07:15.980 --> 07:18.050
We can break out of the for loop.

07:18.570 --> 07:24.270
So now we have choose player starts that is going to return the first player start.

07:24.270 --> 07:28.110
We find if none of them have the tag and it'll return null.

07:28.110 --> 07:34.170
If there are no player starts in the world, but if there is one with the tag, it'll return that one.

07:34.170 --> 07:38.100
If there's multiple with the tag, it's going to return the first one it finds.

07:38.340 --> 07:42.120
So we can test this out by running in debug mode.

07:43.860 --> 07:47.070
Okay, so first thing I'm going to do is press play.

07:47.670 --> 07:50.490
Now I see that we spawn at that player start.

07:50.490 --> 07:55.560
If we take that player start and delete it and press play, well, we just spawn in.

07:55.560 --> 07:57.180
We don't have a player start.

07:57.180 --> 08:01.980
I'm going to control Z though and keep that player start, but I'm going to duplicate it and bring the

08:01.980 --> 08:03.570
duplicate over to here.

08:03.570 --> 08:07.470
And for this one I'm going to set its player start tag to the tag.

08:07.470 --> 08:09.270
So right there in the details panel.

08:09.270 --> 08:12.000
And if I press play I spawn it that one.

08:12.000 --> 08:16.860
And if I have more than one with the tag it's just going to take one.

08:16.860 --> 08:18.270
The first one it finds.

08:18.780 --> 08:23.430
But we should never have more than one player start with the same tag, because that's ambiguous.

08:23.430 --> 08:29.430
Unless you don't care and you want a random player, start from among those player starts that all have

08:29.430 --> 08:31.740
the same tag, that would be fine too.

08:32.010 --> 08:38.160
But now at least we know that if we specify a tag we'll spawn in at the player start that has that tag,

08:38.160 --> 08:41.010
provided that there is one with that tag.

08:41.010 --> 08:46.860
If we take this tag and set it back to none, then if we press play, it's just going to pick one.

08:46.860 --> 08:48.990
So really no harm done.

08:48.990 --> 08:52.260
But now we can control where we spawn in.

08:52.260 --> 09:00.420
And this is pivotal to spawning in at checkpoints or places that we've saved, or even determining where

09:00.420 --> 09:01.800
to spawn in to a level.

09:01.800 --> 09:08.820
If we go into a dungeon entrance, for example, and we need to figure out how exactly we can know what

09:08.820 --> 09:13.290
that tag should be when we spawn in because we're spawning into a new level.

09:13.290 --> 09:16.560
So how are we going to know what the player start should be?

09:16.860 --> 09:19.410
We're going to figure that out in the next video.

09:19.860 --> 09:23.340
So until then I'm going to delete this player start.

09:23.340 --> 09:29.910
And I'm going to remove these enemies from this world as we're just going to start working on saving

09:29.910 --> 09:31.290
and loading.

09:31.940 --> 09:34.130
And I'll see you in the next video.
