WEBVTT

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

00:08.420 --> 00:14.900
Now, we've created an ability and we've seen that we can activate abilities as soon as we grant them,

00:14.900 --> 00:16.010
which is great.

00:16.010 --> 00:20.210
But we'd like to be able to activate abilities via input.

00:20.690 --> 00:23.840
So let's discuss about possible ways to do it.

00:24.050 --> 00:31.490
Now, binding input directly to the ability system component was something that we could do before enhanced

00:31.490 --> 00:34.550
input, before enhanced input came around.

00:34.580 --> 00:40.250
There was the option to bind input directly to abilities.

00:40.250 --> 00:49.970
So you press a button and an ability receives that input automatically and either activates or does

00:49.970 --> 00:54.410
whatever it wants to do depending on how you've coded that ability.

00:54.440 --> 01:02.690
Now, this was done by creating an enum with ability input constants, so it was a rigid system as you

01:02.690 --> 01:11.720
would sort of hardcode these enum constants into an ability input enum and those inputs would be linked

01:11.720 --> 01:14.090
to those specific abilities.

01:14.120 --> 01:22.170
Now this was something that we could do before the old input system became deprecated, but now we have

01:22.170 --> 01:28.680
enhanced input and things are done a little bit differently and the changes are for the better, in

01:28.680 --> 01:29.610
my opinion.

01:29.850 --> 01:35.490
Input actions are bound to inputs via the input mapping context.

01:35.490 --> 01:38.790
This is just how enhanced input works.

01:38.880 --> 01:46.500
Now we can decide how to activate abilities in response to these inputs, and we can do this any way

01:46.500 --> 01:47.460
we'd like.

01:47.490 --> 01:56.730
Lyra, the multiplayer Shooter Example project provided by Epic Games, provides us with one example

01:56.760 --> 02:03.840
of linking up enhanced input with the gameplay ability system abilities of that project.

02:03.840 --> 02:06.250
And it's a little bit overengineered.

02:06.270 --> 02:14.550
Lyra is a great example of how to do things, but it can be overly complicated and hard to approach.

02:14.790 --> 02:22.080
Now what we'll do in this course is similar to how Lyra does it, but a little bit less complicated

02:22.080 --> 02:26.580
as we don't need the over flexibility that Lyra provides us with.

02:26.760 --> 02:32.640
So our approach will be a little bit less complicated, but that doesn't mean it will be less useful

02:32.640 --> 02:33.720
or flexible.

02:33.930 --> 02:36.470
We're going to take a data driven approach.

02:36.480 --> 02:41.500
I'd like to be able to change the input to ability mappings at runtime.

02:41.520 --> 02:48.420
In other words, pressing the left mouse button to activate a specific ability should be something that

02:48.420 --> 02:51.000
we should be able to change at runtime.

02:51.000 --> 02:58.140
And thanks to the gameplay ability system's flexibility, this is actually not very hard to do provided

02:58.140 --> 02:59.700
that we code this well.

02:59.880 --> 03:07.950
Now what we're going to do is create a data asset that's going to contain input actions, but we're

03:07.950 --> 03:11.910
going to link up input actions with gameplay tags.

03:11.910 --> 03:15.480
I'd like to have a gameplay tag for each of our inputs.

03:15.480 --> 03:20.340
For example, the one key, the left mouse button, the right mouse button and so on.

03:20.340 --> 03:27.960
And at runtime we should be able to assign various tags to our gameplay abilities.

03:27.960 --> 03:34.560
And then as we activate abilities, every ability will be associated with its input tag, which can

03:34.560 --> 03:36.520
be checked and changed.

03:36.540 --> 03:39.110
So the first step is to make this data asset.

03:39.120 --> 03:40.290
So let's do it.

03:40.810 --> 03:42.310
I'm going to launch the editor.

03:43.570 --> 03:47.350
And we'll make a new C plus plus class for our data asset.

03:47.380 --> 03:49.600
So I'm going to go to C plus plus classes.

03:49.640 --> 03:51.370
Aura public.

03:51.610 --> 03:57.310
And we're going to put this new data asset into a new folder called input.

03:57.460 --> 04:03.550
Let's go ahead and create a new C plus plus class and choose all classes.

04:03.550 --> 04:06.190
And this will be a data asset.

04:07.150 --> 04:13.240
So selecting data asset, we're going to put this in public slash input.

04:14.570 --> 04:22.370
Now this is going to be an input configuration, so I'm going to call this aura input config.

04:23.060 --> 04:27.530
So I'll go ahead and create the class and close the editor.

04:27.710 --> 04:32.630
Now I'm going to go ahead and close all tabs and open my new input config.

04:33.870 --> 04:37.440
So starting with the public folder, I'm going to open input.

04:37.470 --> 04:43.860
Here's ora input config and alt o will open the cpp file.

04:44.610 --> 04:49.620
Now the input config is not going to be terribly complicated.

04:49.650 --> 04:57.600
I just want an array of input actions, but our input actions need to be linked to gameplay tags.

04:57.600 --> 05:03.030
So I want an easy way to link up an input action with a gameplay tag.

05:03.030 --> 05:08.340
And the way that Lyra does it is pretty nice and that's the approach that I'm going to take for our

05:08.340 --> 05:09.180
project.

05:09.210 --> 05:12.960
What we're going to do is create a struct and the struct will be simple.

05:12.960 --> 05:16.380
It will contain an input action and a gameplay tag.

05:16.380 --> 05:18.390
So we'll make this struct here.

05:18.540 --> 05:22.560
We'll call this f ora input action.

05:23.100 --> 05:25.710
And we'll give it a use struct.

05:27.300 --> 05:36.600
With blueprint type and of course a generated body and F or a input action is going to contain an input

05:36.600 --> 05:37.380
action.

05:37.410 --> 05:44.430
Now I'm going to make this a const input action and I'm also going to forward declare the class you

05:44.430 --> 05:48.090
input action so we don't have to include that header file.

05:48.090 --> 05:54.290
And this input action pointer will be called input action and it will be initialized to null pointer.

05:54.300 --> 05:59.520
Now it's const, meaning it can't be changed at runtime, but that doesn't mean we can't set it to a

05:59.520 --> 05:59.880
value.

05:59.910 --> 06:07.380
We're going to set it in the blueprint for this data asset by giving it a new property and making it

06:07.380 --> 06:10.200
either edit anywhere or edit defaults only.

06:10.200 --> 06:12.690
I think edit defaults only makes more sense.

06:12.930 --> 06:21.690
And in addition to this we'll make an F gameplay tag called input tag and this should also be a const

06:21.720 --> 06:22.800
gameplay tag.

06:22.800 --> 06:25.770
We'll initialize it with f gameplay tag.

06:25.770 --> 06:27.360
Just an empty tag.

06:27.360 --> 06:34.470
Now this is not a pointer or a reference, so we are going to include the header file for our gameplay

06:34.470 --> 06:34.770
tag.

06:34.770 --> 06:41.490
That's gameplay tag container dot h and this can be also edit defaults only.

06:42.370 --> 06:49.000
And now that we have this struct, our data asset can contain an array of these that we can set in the

06:49.000 --> 06:50.530
data asset blueprint.

06:50.710 --> 06:56.110
Now we're going to add public didn't need to do that for the struct because struct bodies are public

06:56.110 --> 06:56.920
automatically.

06:56.920 --> 06:57.460
Right?

06:57.460 --> 07:00.010
So let's add this t array.

07:00.490 --> 07:04.180
It's going to be of type for input action.

07:05.480 --> 07:07.520
So we'll have an array of these structs.

07:07.550 --> 07:10.760
We're going to call this ability input actions.

07:11.890 --> 07:15.370
Now this we're going to fill in in the blueprint.

07:15.370 --> 07:20.470
So we're going to give it a new property with edit defaults only.

07:21.760 --> 07:26.110
I'd like to make it blueprint read only, just in case we need to access it.

07:26.560 --> 07:33.940
And now we have a data asset that contains an array of input actions specifically, or input actions

07:33.940 --> 07:35.830
which have a game play tag.

07:35.860 --> 07:45.190
Now this is great because if we have a pointer or a reference to this input config, then we can look

07:45.190 --> 07:51.150
up in this array any of our input actions that have a specific tag.

07:51.160 --> 07:55.450
And I'd like to make a function for performing this lookup.

07:56.140 --> 07:59.800
So we're going to make a function that returns a const.

07:59.830 --> 08:01.720
You input action.

08:03.410 --> 08:08.660
So why do we want to return an input action and not an input action?

08:08.690 --> 08:15.110
Well, we could return an input action, but this is going to be more useful if we can return just the

08:15.110 --> 08:18.800
input action associated with a gameplay tag.

08:18.800 --> 08:25.190
And then this input action is kind of an internal thing to our input config.

08:25.220 --> 08:31.430
We don't have to worry about breaking it open and finding the input action inside.

08:31.430 --> 08:34.250
This function is just going to do all that for us.

08:34.250 --> 08:42.770
So this function will be called find ability input action for tag, which will take a const gameplay

08:42.770 --> 08:53.060
tag by reference called input tag and I'll have an optional boolean be log not found.

08:54.760 --> 08:59.500
We'll set it to false by default and this will be a const function.

08:59.650 --> 09:06.160
So this will simply return the input action associated with a given tag.

09:06.250 --> 09:08.470
So let's generate the definition.

09:09.130 --> 09:14.260
Now, if you'd like a little challenge, why don't you implement this on your own?

09:14.350 --> 09:22.120
Go ahead and pause the video and figure out how to find the input action associated with a given tag

09:22.120 --> 09:24.550
from our Ability Input actions array.

09:24.580 --> 09:29.380
So if you're up for the challenge, go ahead and pause the video now and give it a try.

09:31.150 --> 09:31.660
Okay.

09:31.660 --> 09:39.000
So I want to find the input action associated with the input tag passed into this function.

09:39.010 --> 09:44.950
So I'm simply going to loop through our input actions in ability input actions.

09:44.950 --> 09:50.110
So this will be a range based for loop looping through each for input action.

09:50.110 --> 09:52.740
I'm going to use const reference.

09:52.750 --> 09:58.720
We'll call this action and it's each action in ability input actions.

09:58.720 --> 09:59.980
What are we going to do?

09:59.980 --> 10:02.950
Well, we're going to check to see if it's tag matches.

10:02.950 --> 10:08.020
So we'll say if and I'll say action dot input.

10:08.020 --> 10:08.920
Action.

10:09.740 --> 10:13.190
And this input action could be a null pointer.

10:13.190 --> 10:15.140
So we'll check to see if it's null.

10:17.090 --> 10:20.030
And we'll also check its input tag.

10:20.030 --> 10:22.730
So we'll say action dot input tag.

10:22.760 --> 10:25.640
We'll see if it's equal to input tag.

10:27.730 --> 10:33.490
And if we succeed and get inside this if statement, we'll return this input action.

10:33.490 --> 10:38.680
So we'll say return action, dot input action, and that's it.

10:39.010 --> 10:45.610
Now we have this bool for if we can't find anything right, if we don't find our input action or perhaps

10:45.610 --> 10:52.060
we fail to get inside this if statement and get to this return that means the input action was a null

10:52.060 --> 10:52.900
pointer.

10:52.900 --> 10:55.810
Any of those things happen, then we have a problem.

10:55.810 --> 11:01.600
So we'll say if B log not found, then we'll do a u log.

11:01.600 --> 11:03.580
We'll log out an error.

11:04.300 --> 11:13.420
So for now we're using log temp until we create our own log category and we're going to say error text

11:13.690 --> 11:23.380
and we can just say can't find ability input action for input tag and we'll say the tag.

11:23.380 --> 11:37.600
We'll use a percent s for the string for tag on input config and we'll say what this class is.

11:37.600 --> 11:39.640
So first we have our input tag.

11:39.640 --> 11:41.830
We're going to use star input tag.

11:43.250 --> 11:44.510
Dot to string.

11:45.800 --> 11:54.230
And then for the input config we're going to use the name and we can use the function get name safe.

11:56.770 --> 11:58.420
Passing in this.

11:59.230 --> 12:01.390
And this returns an F string.

12:01.390 --> 12:04.120
We'll have to use the star on this as well.

12:05.270 --> 12:09.440
So we'll log an error if B log not found.

12:09.710 --> 12:11.570
And by the end of this.

12:12.140 --> 12:15.800
We'll have to return a null pointer as we have to return a pointer from this.

12:15.800 --> 12:16.400
Right.

12:16.670 --> 12:22.850
So now we have a function to find an input action associated with a given tag.

12:22.850 --> 12:30.230
And this only works if we link up tags to input actions by filling out this data asset.

12:30.560 --> 12:32.960
Now we also need input tags, right?

12:32.960 --> 12:40.130
We're going to need a bunch of gameplay tags for any of the inputs that we want in our game so we can

12:40.130 --> 12:43.940
add those natively to aura gameplay tags.

12:43.940 --> 12:45.740
So I'd like to do that.

12:45.770 --> 12:48.710
We have our primary and secondary attributes.

12:48.710 --> 12:50.150
I'll put these underneath.

12:50.150 --> 12:53.390
It looks like we have this empty protected section.

12:53.390 --> 12:58.310
Since it's not being used, I'll go ahead and remove that and we'll make an gameplay tag.

13:00.680 --> 13:02.240
For each of our inputs.

13:02.240 --> 13:07.120
So I'm going to call these input tag as the first tag in the hierarchy.

13:07.130 --> 13:12.470
We'll say input tag dot and I'll have an NB for left mouse button.

13:12.470 --> 13:14.690
I'd like one for the right mouse button.

13:14.690 --> 13:19.970
I'll call that RMB and then we'll have one for the number keys.

13:19.970 --> 13:25.730
And really it's not very important which keys we end up mapping to these.

13:25.730 --> 13:33.200
I'm just going to give these tags the names, input tag, dot one, two, three and four.

13:35.130 --> 13:43.950
And I can go into aura gameplay tags dot CP and add those right here in our initialized native gameplay

13:43.980 --> 13:45.390
tags function.

13:45.510 --> 13:51.330
So after secondary attributes, I'm going to actually copy this function call to add native gameplay

13:51.330 --> 13:51.630
tag.

13:51.630 --> 13:58.890
I'm going to copy the comment as well and go all the way down to the bottom and this is going to be

13:58.890 --> 14:00.180
input tags.

14:01.670 --> 14:06.300
So we have gameplay tags, dot and the name of the tag.

14:06.320 --> 14:13.550
This is going to start off with input tag lmdb and we're going to add a native gameplay tag and it's

14:13.550 --> 14:18.020
going to be input tag dot lmdb.

14:18.710 --> 14:22.940
And for the F string we can just say.

14:24.180 --> 14:31.740
Input tag for left mouse button and we can just follow this pattern and make the rest of them.

14:31.740 --> 14:39.450
So we're going to have the right mouse button as well as and it looks like I missed the semicolon there,

14:40.470 --> 14:45.990
as well as keys one, two, three and four.

14:45.990 --> 14:47.900
So we just need to change these.

14:47.910 --> 14:50.070
This one will be input tag, R&amp;B.

14:51.060 --> 14:53.250
We'll change the name as well.

14:53.400 --> 14:55.680
And this will say right mouse button.

14:55.980 --> 14:58.200
Next we'll have input tag one.

14:59.530 --> 15:01.690
The string will say input tag one.

15:01.690 --> 15:06.220
This is error prone, so we have to make sure not to put any typos in.

15:06.310 --> 15:12.370
This will say input tag for instead of left mouse button, we'll say one key.

15:13.580 --> 15:22.730
Next we have input tag two changing the name and its input tag for to key.

15:23.090 --> 15:25.370
And then we have three.

15:26.840 --> 15:28.760
We'll go ahead and change that one.

15:32.270 --> 15:35.510
And finally input tag for.

15:42.080 --> 15:43.260
And there we go.

15:43.280 --> 15:51.470
So now that we've added some native tags for our inputs, then our input tag makes more sense here in

15:51.470 --> 15:57.290
our data asset and we can make some input actions and add them to our data asset.

15:57.290 --> 16:02.090
So what we can do is let's go ahead and compile and launch, make sure we don't have any errors.

16:02.090 --> 16:09.980
And it looks like I have an error here or an input config const properties are not supported.

16:10.010 --> 16:13.730
We're going to have to remove the const from the gameplay tag.

16:15.640 --> 16:17.260
Compiling again.

16:17.260 --> 16:23.200
And that's going to fix that problem so we can have a const pointer.

16:23.200 --> 16:25.270
We can't have a const gameplay tag.

16:25.270 --> 16:26.980
Let's launch the engine now.

16:28.580 --> 16:33.250
And we just need to create our new data asset.

16:33.260 --> 16:38.540
Before we do, let's go to project settings and just make sure that everything looks okay.

16:38.540 --> 16:47.810
In our gameplay tags, we have our input tag category with one through four LNB and R&amp;B and that looks

16:47.810 --> 16:48.530
great.

16:48.860 --> 16:50.690
So we'll make our data asset.

16:50.690 --> 16:58.130
Let's go to Blueprints and we have an input category already where we have our input mapping context

16:58.130 --> 16:59.770
and our input actions.

16:59.780 --> 17:02.000
Let's go ahead and make our data asset.

17:02.000 --> 17:09.170
We'll go to Miscellaneous Data Asset and choose Aura input config.

17:09.380 --> 17:14.960
Select that, call this D a R input config.

17:17.650 --> 17:24.280
We'll go ahead and open this up and we can add some ability input actions, but we need input actions

17:24.280 --> 17:28.960
for all of our inputs and that's going to be relatively straightforward.

17:29.230 --> 17:35.650
Now Move is a two dimensional input, but for our ability inputs, we're going to be one dimensional.

17:35.650 --> 17:41.950
So we'll right click, we'll go to input, choose input action.

17:41.950 --> 17:45.280
We'll call these I a underscore and just keep it simple.

17:45.280 --> 17:48.730
This one will be B, we'll open this up.

17:48.730 --> 17:52.210
It's going to be axis one D float.

17:52.860 --> 17:54.120
And that's it.

17:54.300 --> 17:57.210
And we'll make all of the rest of them.

17:57.210 --> 17:59.970
So we'll make another one.

18:00.970 --> 18:02.380
And put action.

18:02.380 --> 18:05.050
We'll call this I a R&amp;B.

18:06.440 --> 18:09.470
Change it to axis 1d float.

18:09.860 --> 18:11.420
We'll make another one.

18:12.500 --> 18:21.350
I a underscore one again value type axis 1d float and we just need two through three so I can quickly

18:21.350 --> 18:22.940
time lapse the rest of them.

18:35.570 --> 18:37.240
Okay, so we've got them all.

18:37.250 --> 18:42.740
I'm going to save all and go ahead and close out of these input actions.

18:42.740 --> 18:45.350
Just middle mouse clicking on the tab there.

18:45.560 --> 18:52.880
And now we need to make sure that our input mapping context has them mapped to inputs.

18:53.090 --> 18:59.270
So we have our I move, let's go ahead and add the rest of the input actions.

18:59.270 --> 19:07.700
So here's the next one and I'll start with a one and click the keyboard and hit the one key and that's

19:07.700 --> 19:07.970
it.

19:07.970 --> 19:09.290
This is going to be simple.

19:09.290 --> 19:11.930
I'm not going to add any triggers or modifiers.

19:11.930 --> 19:15.380
We're just going to map the I one to the one key.

19:15.380 --> 19:17.030
Let's add another one.

19:17.060 --> 19:18.980
This will be IA2.

19:18.980 --> 19:21.140
I'll click the keyboard and hit two.

19:21.320 --> 19:23.750
We'll add another mapping.

19:25.730 --> 19:29.030
This will be IA3 mapped to three.

19:30.450 --> 19:32.220
And another one.

19:32.250 --> 19:39.660
This will be IA4 mapped to four and then two more for the mouse buttons I'm going to click plus.

19:41.150 --> 19:45.080
This will be in a lab and I'm going to click and click.

19:45.080 --> 19:47.000
That'll give me the left mouse button.

19:47.000 --> 19:49.010
And finally.

19:49.800 --> 19:53.380
R i, a, R and B right there.

19:53.400 --> 19:58.140
I'm going to left click and right click and that'll give me the right mouse button.

19:58.380 --> 20:03.930
And now they're all linked up to the inputs that I want them to have.

20:03.960 --> 20:11.000
But of course we can always switch out input mapping contexts if we want those to be changed.

20:11.010 --> 20:18.720
But now that I have my input mapping context set up, we know that each input action is linked to those

20:18.720 --> 20:19.080
keys.

20:19.080 --> 20:25.020
As long as we're using that input mapping context, which we are, then we can add these to our input

20:25.020 --> 20:28.830
config by clicking plus and expanding it.

20:28.830 --> 20:32.970
And ability input actions is an array of or input actions.

20:32.970 --> 20:36.750
Those are just a struct with an input action and an input tag.

20:36.750 --> 20:43.440
And this data asset is what we will use to link up those input actions with their tags.

20:43.440 --> 20:50.290
So I'm going to choose IA1 and for the tag I'm going to expand input tag and choose one.

20:50.290 --> 20:54.940
And now IA1 is associated with this tag.

20:54.940 --> 21:01.870
And if we call the function we created to look up an input action based on a tag, then we'll get the

21:01.870 --> 21:03.490
correct input action.

21:03.490 --> 21:05.250
So that's a one.

21:05.260 --> 21:07.180
Let's add another one.

21:07.180 --> 21:10.210
We'll choose IA2 for the input tag.

21:10.210 --> 21:15.670
We'll choose input tag two and we'll repeat this process for the rest of them.

21:29.020 --> 21:29.590
Okay.

21:29.590 --> 21:33.280
So now we have our input config filled out.

21:33.310 --> 21:41.170
Now this is cool because we can always swap out our data assets even dynamically at runtime if we want

21:41.170 --> 21:42.550
to swap those out.

21:42.580 --> 21:45.300
We can swap out for other inputs.

21:45.310 --> 21:51.640
We can swap out for other configurations that have different tags, whatever we want really.

21:51.880 --> 21:59.650
But now we have six different input tags associated with different input actions.

21:59.770 --> 22:07.540
And this is what we'll be using to link up our inputs to not only ability activation, but whatever

22:07.540 --> 22:10.760
else we want to link up our inputs to.

22:10.810 --> 22:13.860
And that's the first step in our system.

22:13.870 --> 22:15.130
So excellent job.

22:15.130 --> 22:18.610
Make sure to save all and I'll see you in the next video.
