﻿1
00:00:04,350 --> 00:00:05,340
‫Hello and welcome.

2
00:00:05,340 --> 00:00:11,910
‫In this lecture, we're going to be setting up remap able inputs so that when we press down or either

3
00:00:11,910 --> 00:00:19,650
‫on the mouse key or on a controller, we get a press and release message coming through from Blueprint.

4
00:00:19,650 --> 00:00:21,930
‫Let's dive in and see how to do this now.

5
00:00:21,930 --> 00:00:24,180
‫We don't want to be doing this trace all the time.

6
00:00:24,180 --> 00:00:28,710
‫We only need to be doing it when we're getting ready to grab an object and we don't want to automatically

7
00:00:28,710 --> 00:00:30,090
‫grab it when we go near it.

8
00:00:30,330 --> 00:00:37,950
‫So to actually grab onto something, we need to use a mouse input, some sort of input.

9
00:00:37,950 --> 00:00:43,170
‫Now previously we've done this with events in Blueprint and we're going to do it again with events.

10
00:00:43,170 --> 00:00:49,050
‫We will see how to do this in C++ soon, but we are going to first do it with events.

11
00:00:49,050 --> 00:00:56,070
‫And what I want to do is set it up so that it could work with the keyboard, it could work with the

12
00:00:56,070 --> 00:00:57,960
‫mouse, or it could work with a controller.

13
00:00:57,960 --> 00:01:02,700
‫So to do this, we need input mapping, something that you see quite often in games.

14
00:01:02,700 --> 00:01:09,480
‫And the way we're going to do this is go to our settings COG, we're going to go to the project settings,

15
00:01:09,660 --> 00:01:13,530
‫scroll down to the engine and then input.

16
00:01:14,040 --> 00:01:20,700
‫Here is where we set up things called action mappings and axis mappings.

17
00:01:20,700 --> 00:01:28,050
‫So what these two concepts are are essentially the mappings between your controller analog sticks or

18
00:01:28,050 --> 00:01:34,020
‫buttons, or perhaps your mouse and your mouse buttons or your keyboard.

19
00:01:34,020 --> 00:01:36,870
‫The actions are discrete things.

20
00:01:36,870 --> 00:01:41,910
‫These are things that you press a button and it just happens as a press, as a release.

21
00:01:41,910 --> 00:01:49,230
‫And the axis mappings are things which are more continuous, such as when you move a mouse slightly

22
00:01:49,590 --> 00:01:53,310
‫or you slightly tilt a controller, there's a degree to which you can tilt it.

23
00:01:53,310 --> 00:01:54,480
‫You can tilt it, not at all.

24
00:01:54,480 --> 00:01:57,480
‫You can tell to all the way or anywhere in between.

25
00:01:57,480 --> 00:01:58,290
‫Those are axes.

26
00:01:58,290 --> 00:02:04,200
‫We're not going to deal with axes in this section because all we're dealing with is an action where

27
00:02:04,200 --> 00:02:08,400
‫we are trying to activate our grabber component.

28
00:02:08,850 --> 00:02:13,020
‫So the way we're going to do this is to unfold our action mapping.

29
00:02:13,030 --> 00:02:16,290
‫So you can see there's already a couple of action mappings here.

30
00:02:16,290 --> 00:02:20,070
‫There's a jump and then there's a primary action.

31
00:02:20,070 --> 00:02:25,200
‫This has been set up for us because we're using the first person template and there is a primary action

32
00:02:25,200 --> 00:02:26,220
‫already here.

33
00:02:26,220 --> 00:02:33,090
‫Now let's unfold that primary action and you will see that there are two ways to trigger the primary

34
00:02:33,090 --> 00:02:33,750
‫action.

35
00:02:33,750 --> 00:02:39,060
‫You can use the left mouse button or the gamepad right trigger.

36
00:02:39,060 --> 00:02:44,550
‫Now, because I want to give you an idea of how we can set up our own action mapping.

37
00:02:44,550 --> 00:02:49,620
‫I'm actually going to hit the delete button next to the primary action and we're going to create our

38
00:02:49,620 --> 00:02:50,220
‫own.

39
00:02:50,220 --> 00:02:54,750
‫So the first thing to do is click the add button next to action mapping.

40
00:02:54,750 --> 00:02:56,550
‫Then we need to give this action a name.

41
00:02:56,550 --> 00:03:01,140
‫In my case, I'm going to call this grab and then we need to select a mapping.

42
00:03:01,140 --> 00:03:06,600
‫Now you can either do this from the dropdown where you can select any of the mappings in here, or you

43
00:03:06,600 --> 00:03:12,210
‫can click on that little keyboard button which allows you to capture whatever you're doing.

44
00:03:12,210 --> 00:03:17,100
‫So you click on it, it goes yellow and then you click again or you use whatever key.

45
00:03:17,100 --> 00:03:19,890
‫If I hit space, you can see it puts in space bar.

46
00:03:19,920 --> 00:03:26,820
‫If I actually click with my left mouse button, you can see it adds a left mouse button option here.

47
00:03:26,820 --> 00:03:33,150
‫So a little mini challenge for you now is to go ahead and set up this action mapping, add the left

48
00:03:33,150 --> 00:03:33,690
‫mouse button.

49
00:03:33,690 --> 00:03:38,370
‫Maybe if you've got a controller, add in a controller button here to.

50
00:03:39,960 --> 00:03:40,360
‫Okay.

51
00:03:40,400 --> 00:03:40,910
‫Welcome back.

52
00:03:40,910 --> 00:03:44,960
‫So I'm going to add in a new action mapping is this add button.

53
00:03:45,140 --> 00:03:49,880
‫And then what we can do is we can I don't have my controller hooked up at the moment.

54
00:03:49,880 --> 00:03:58,790
‫So what you can do is click the dropdown and we can go to gamepad and you can look for the gamepad right

55
00:03:58,790 --> 00:04:03,860
‫trigger, for example, and that will set it up so that when you pull the trigger on your gamepad,

56
00:04:03,860 --> 00:04:07,250
‫it's going to activate our grab action.

57
00:04:07,250 --> 00:04:09,080
‫So we've set up the action mapping.

58
00:04:09,080 --> 00:04:10,910
‫Now we need to actually make use of it.

59
00:04:10,910 --> 00:04:13,700
‫So we're going to go over to our content draw.

60
00:04:13,850 --> 00:04:19,820
‫We're going to look for our beep player and open it up because the beep player is the one that has the

61
00:04:19,820 --> 00:04:21,050
‫grabber component.

62
00:04:21,050 --> 00:04:25,850
‫And that's what we're eventually going to want to activate and make it grab something.

63
00:04:26,240 --> 00:04:33,920
‫And the way we can do this is by right clicking in the Blueprint Event graph and searching for grab.

64
00:04:34,370 --> 00:04:42,410
‫So now there is an input action events grab event and this is linked up to whatever keys you have set

65
00:04:42,410 --> 00:04:47,270
‫up and you can change that and you can potentially create screens in the game which allow your players

66
00:04:47,270 --> 00:04:50,330
‫to change the input mappings as well.

67
00:04:50,600 --> 00:04:55,490
‫And what you got here is two events, a press event and a released event.

68
00:04:55,490 --> 00:04:59,630
‫So I'd like to challenge you to log on that particular action.

69
00:04:59,630 --> 00:05:06,260
‫So add a blueprint log for when it's pressed, add it for when it's released, and check that your mappings

70
00:05:06,260 --> 00:05:06,620
‫work.

71
00:05:06,620 --> 00:05:07,640
‫So go into the game.

72
00:05:07,640 --> 00:05:14,930
‫Use the particular keys that you've mapped to grab action and see if your log messages get printed out.

73
00:05:14,930 --> 00:05:16,400
‫Pause the video and have a go.

74
00:05:19,650 --> 00:05:20,760
‫Hey, welcome back.

75
00:05:20,790 --> 00:05:26,780
‫So for pressed, we are going to do a print string, which is not going to say hello.

76
00:05:26,790 --> 00:05:31,680
‫It's going to say grabbed and then we're going to have a released one as well.

77
00:05:31,680 --> 00:05:36,870
‫Again, a print string which is going to say released like.

78
00:05:36,870 --> 00:05:40,980
‫So now let's go ahead into our dungeon level and hit play.

79
00:05:41,250 --> 00:05:45,570
‫And now if we hit the mouse button, it says grabbed.

80
00:05:45,570 --> 00:05:47,610
‫When I release it, it says released.

81
00:05:47,610 --> 00:05:50,910
‫And you can see that that is working as we would expect.

82
00:05:50,910 --> 00:05:51,420
‫Great stuff.

83
00:05:51,420 --> 00:05:57,990
‫Now we've seen how we can set up action mappings that are remap able and map able to multiple inputs.

84
00:05:57,990 --> 00:05:59,730
‫I'll see you in the next lecture.

