WEBVTT

00:07.110 --> 00:08.260
Welcome back.

00:08.280 --> 00:14.850
We're now ready to associate the enhanced input assets that we created in the editor with our player

00:14.850 --> 00:15.740
controller.

00:15.750 --> 00:20.370
So I'm going to go into our player controller here and open that up.

00:20.370 --> 00:25.680
I don't think I need my character classes open at the moment, so I'm going to right click on our player

00:25.680 --> 00:28.080
controller and close other tabs.

00:28.230 --> 00:30.780
Visual Studio has a similar option.

00:30.900 --> 00:39.360
Now I'll go ahead and open our player controller CP and I'll have them both open here and here in the

00:39.360 --> 00:40.200
header file.

00:40.200 --> 00:42.330
We're going to need a couple of functions.

00:42.450 --> 00:49.950
Now we created an input mapping context and the place to add that to our player controller is in Begin

00:49.950 --> 00:50.490
play.

00:50.520 --> 00:53.580
Begin Play is a protected function.

00:53.790 --> 01:00.120
I'm also going to want a constructor and that will go in the public section, so I'm going to want a

01:00.120 --> 01:01.370
couple of sections here.

01:01.380 --> 01:07.840
I'm going to make a public section and a protected section and in protected, I'm going to override

01:07.840 --> 01:08.830
begin play.

01:09.010 --> 01:11.200
So it's virtual, it's void.

01:11.200 --> 01:15.580
We're going to declare begin play and that's an override.

01:15.580 --> 01:23.980
And in the public section we'll make a Ora player controller constructor and we can define these functions.

01:23.980 --> 01:30.100
I'm going to let Rider create the definition for me by clicking on the hammer and selecting generate

01:30.100 --> 01:31.150
definition.

01:31.150 --> 01:37.690
And for now, the only thing I'd like to do in Ora player controller in the constructor is make sure

01:37.690 --> 01:40.480
that this player controller replicates.

01:40.480 --> 01:46.030
So the player controller has a B replicates boolean that we can set to true.

01:46.030 --> 01:51.100
And we'll talk more about what replication implies throughout the course.

01:51.100 --> 01:56.950
But replication essentially in multiplayer is when an entity changes on the server.

01:56.980 --> 02:05.680
That change that took place on the server will replicate or be sent down to all clients connected to

02:05.680 --> 02:06.370
the server.

02:06.370 --> 02:10.960
So we have the concept of changes being made on multiple machines.

02:10.960 --> 02:18.340
One of those machines is the server and all other machines are clients, so replication is responding

02:18.370 --> 02:22.300
to data, updating on the server and sending that down to clients.

02:22.300 --> 02:28.000
So we're just going to make sure that our player controller is designated to participate in that to

02:28.000 --> 02:29.950
be a replicated entity.

02:29.950 --> 02:31.690
So there's our constructor.

02:31.690 --> 02:34.450
And now let's make a definition for Begin Play.

02:34.600 --> 02:38.710
Thanks to Rider, I have super begin play automatically.

02:38.920 --> 02:44.170
If you're using Visual Studio or another IDE, don't forget your call to super.

02:44.170 --> 02:45.190
Very important.

02:45.280 --> 02:51.580
So here is where we're going to add the input mapping context and our player controller is going to

02:51.580 --> 02:55.090
need a variable to store that input mapping context.

02:55.090 --> 03:01.690
So we'll go ahead and make that member variable here in our player controller and that can be a private

03:01.690 --> 03:02.500
variable.

03:02.500 --> 03:05.620
So we'll make a private section down at the bottom.

03:07.450 --> 03:13.150
I just happened to like my private section below the protected which is below the public.

03:13.150 --> 03:17.410
And you may wish to organize your structure differently, and that's fine.

03:17.440 --> 03:19.840
Now I need a pointer for a U.

03:19.840 --> 03:21.520
Input mapping context.

03:21.520 --> 03:25.390
That's the C plus plus type for an input mapping context.

03:25.390 --> 03:31.090
So I'm going to make a T object pointer to u input mapping context.

03:33.830 --> 03:37.430
And I'm going to call this aura context.

03:37.820 --> 03:41.150
And of course, this will be a new property.

03:41.540 --> 03:45.400
And I'd like to be able to set this in the player controller blueprint.

03:45.410 --> 03:51.080
So I'll make it edit anywhere and I'll put it in the category of input.

03:51.960 --> 03:59.760
Now if I hit control shift B to compile, we're going to get compiler errors because input mapping context

03:59.760 --> 04:05.040
is an undeclared identifier so we can forward declare this type as to object.

04:05.040 --> 04:10.830
Pointer is a pointer after all, and that way we don't have to include the header file for input mapping

04:10.830 --> 04:11.400
context.

04:11.400 --> 04:16.610
Here we can just forward declare and include that header file where we need it.

04:16.620 --> 04:22.260
So up at the top I'll say class you input mapping context.

04:23.280 --> 04:25.440
So we have that forward declared.

04:25.620 --> 04:26.910
Now here's the thing though.

04:26.910 --> 04:33.300
We are going to include it where we need to use it and we can only successfully include the header for

04:33.300 --> 04:39.750
this if we have access to the module, the enhanced input module that contains these header files for

04:39.750 --> 04:41.400
enhanced input classes.

04:41.400 --> 04:49.140
That means we need to go over to our aura dot buildpacks and make sure to add enhanced input to our

04:49.140 --> 04:50.310
module names.

04:50.310 --> 04:58.330
So I'm going to go ahead and do that now right here in public Dependency module names in Aura dot Buildpacks.

04:58.330 --> 05:06.100
I'm going to add enhanced input just to make sure that we can access that module and I'll save and close

05:06.100 --> 05:07.780
out of the build file.

05:08.020 --> 05:14.500
So now that I have an aura context and we're planning on setting that in the blueprint, let's go into

05:14.500 --> 05:17.980
Begin play and we can add this mapping context.

05:18.010 --> 05:21.340
Now, Aura context may or may not be set.

05:21.340 --> 05:26.530
Remember, we need to set that in the blueprint and if we haven't, then this won't be a valid pointer.

05:26.530 --> 05:33.280
And if it's not valid, well then we'll have all kinds of problems such as input not working.

05:33.400 --> 05:39.640
And that's something that's serious enough, I think, to halt execution altogether for so that we can

05:39.640 --> 05:43.300
set that input mapping context on the player controller.

05:43.300 --> 05:48.400
We shouldn't be allowed to continue trying to play the game if input isn't going to work.

05:48.400 --> 05:52.240
So for that reason, I'm going to use an assert.

05:52.270 --> 05:57.400
We can use check here and we'll check the aura context pointer.

05:57.400 --> 06:06.730
So check is going to halt execution if this condition fails and aura context being a pointer will be

06:06.730 --> 06:10.000
evaluated as false if it hasn't been set yet.

06:10.000 --> 06:17.080
So this is a good way for us to assert that our aura context is set and if we try to run the game without

06:17.080 --> 06:18.880
setting it, we'll get a crash.

06:19.000 --> 06:25.840
Now the way to add an input mapping context is we access the enhanced input local player subsystem.

06:25.840 --> 06:28.330
That's a subsystem whose type is you.

06:28.330 --> 06:32.680
Enhanced input local player subsystem.

06:32.920 --> 06:34.660
We're going to make a pointer to this.

06:34.660 --> 06:36.520
We'll call this subsystem.

06:38.440 --> 06:45.130
And the way that we can get it is through a static function that belongs to the you local player class.

06:45.130 --> 06:53.440
So to access a static function, we use the class name, you local player, double colon and we can

06:53.440 --> 06:56.110
use the function get subsystem.

06:58.000 --> 07:00.970
This is a template requiring a type.

07:00.970 --> 07:07.930
We're going to use this type you enhanced input local player subsystem and the function will require

07:07.930 --> 07:16.030
an argument of type you local player which we can always get with the function get local player.

07:16.540 --> 07:21.070
So now we have this local pointer subsystem of type u enhanced input.

07:21.070 --> 07:24.880
Local player subsystem subsystems are singletons.

07:24.880 --> 07:30.670
There exists only one for the duration of the program and the enhanced input.

07:30.670 --> 07:37.840
Local player subsystem is what we can use to add mapping contexts such as our aura context.

07:37.960 --> 07:40.450
Now we can place this all in an If check.

07:40.480 --> 07:45.100
That way, if this subsystem pointer is null, we won't try to access it.

07:45.100 --> 07:53.710
Or we can do like we did with aura context and simply do a check with check subsystem.

07:53.710 --> 07:59.620
The difference between using an if statement to check the pointer and an assertion is that of course

07:59.620 --> 08:02.560
if subsystem is null, we'll get a crash here.

08:02.560 --> 08:10.750
Now, after checking subsystem, we can take subsystem and we can use the function add mapping context,

08:10.750 --> 08:13.150
which requires an input mapping context.

08:13.150 --> 08:19.510
We have our aura, context and a priority as you can have multiple input mapping contexts at the same

08:19.510 --> 08:20.170
time.

08:20.170 --> 08:25.990
And if they're competing with each other for the same inputs, well then you can use priority to determine

08:25.990 --> 08:27.390
which input wins.

08:27.400 --> 08:33.370
We just have a single input mapping context and we're going to keep that priority value at zero.

08:33.670 --> 08:37.330
So now our input mapping context is set here.

08:37.450 --> 08:44.950
Now while we're in Beginplay, we can set a number of settings that our player controller has control

08:44.950 --> 08:50.950
over, such as things like showing the mouse cursor as the player controller has a be show mouse.

08:50.980 --> 08:53.320
Mouse cursor boolean.

08:53.320 --> 08:56.560
We can set that to true in this top down.

08:56.560 --> 08:58.980
We're going to want to see our cursor.

08:58.990 --> 09:01.570
We can even set the default mouse cursor.

09:02.620 --> 09:06.880
And this is an enum of type E mouse cursor.

09:08.440 --> 09:10.990
So we have a number of different cursors.

09:10.990 --> 09:16.110
I'm going to use the default mouse cursor and we can also set the input mode.

09:16.120 --> 09:25.300
Now the struct f input mode game and UI is an input mode struct and if we use this input mode then we'll

09:25.300 --> 09:33.460
be able to use input from our keyboard and mouse and we'll also be able to use input to affect UI such

09:33.460 --> 09:37.360
as widgets and we'll have lots of that in this project.

09:37.360 --> 09:44.050
So I'm going to create one of these called input mode data and take input mode data and configure it

09:44.050 --> 09:44.860
a little bit.

09:44.860 --> 09:48.580
I'm going to use set lock mouse to viewport behavior.

09:48.610 --> 09:51.070
This takes an E mouse lock mode.

09:51.070 --> 09:52.750
I'm going to choose do not lock.

09:52.750 --> 09:56.470
And that way we will not lock our mouse to the viewport.

09:56.860 --> 10:04.030
I'm also going to take input mode data and use set hide cursor during capture to false.

10:04.180 --> 10:09.310
So as soon as our cursor is captured into the viewport, we will not hide the cursor.

10:09.310 --> 10:15.820
And in order to use this input mode data we use the player controllers function set input mode passing

10:15.820 --> 10:17.380
in the input mode data.

10:18.670 --> 10:26.380
So now our cursor settings are configured and now we have our subsystem set up and we're using some

10:26.380 --> 10:27.010
class types.

10:27.010 --> 10:34.420
Now let's go ahead and quickly compile so we can call out any compiler errors that we might have.

10:34.600 --> 10:37.720
And since we don't have any compiler errors, then we're good.

10:37.720 --> 10:40.450
We don't have to include any header files anywhere.

10:41.020 --> 10:47.740
So now that we have our input mapping context bound to our player controller, we're going to want a

10:47.740 --> 10:54.520
callback function that will handle actually moving the pawn, in our case, the Aura character in response

10:54.520 --> 10:55.690
to input.

10:55.690 --> 11:01.330
In other words, we want input actions to trigger some kind of movement.

11:01.630 --> 11:08.590
So in the next video we'll set up a variable for our input action and we'll create a callback function

11:08.590 --> 11:10.810
that we can use to move the character.

11:10.810 --> 11:12.010
So great job.

11:12.010 --> 11:13.930
I'll see you in the next video.
