﻿1
00:00:04,370 --> 00:00:05,360
‫Hello and welcome.

2
00:00:05,360 --> 00:00:11,450
‫In this lecture, we're going to be looking at how we can create new nodes in Blueprint from our C++

3
00:00:11,450 --> 00:00:17,180
‫so that essentially we can be calling C++ functionality from within Blueprint.

4
00:00:17,180 --> 00:00:18,770
‫Let's dive in and see how it's done.

5
00:00:18,920 --> 00:00:27,260
‫Now, it's all well that I can use blueprints to call to blueprint nodes, but I actually want to activate

6
00:00:27,260 --> 00:00:32,300
‫our grabber from this piece of blueprint here, not print out some strings.

7
00:00:32,300 --> 00:00:34,670
‫So how do I go about doing that?

8
00:00:34,970 --> 00:00:43,520
‫Well, fortunately, we can quite easily expose a function from a C++ class in to blueprint.

9
00:00:43,520 --> 00:00:46,160
‫And the way we do this is as follows.

10
00:00:46,160 --> 00:00:48,560
‫So we're going to go and create a new public function.

11
00:00:48,560 --> 00:00:52,520
‫So I'm going to go to my public section just under the tick component.

12
00:00:52,520 --> 00:00:58,250
‫And here I'm going to create a new function with a void return type called release.

13
00:00:58,250 --> 00:01:03,830
‫So we're going to do grab later on, but we're just going to call a release function for now.

14
00:01:03,920 --> 00:01:07,790
‫How do I make this available in Blueprint?

15
00:01:07,790 --> 00:01:10,850
‫Well, I need to make it a U function.

16
00:01:10,850 --> 00:01:13,370
‫So you've got you properties for variables.

17
00:01:13,370 --> 00:01:20,570
‫You function is kind of the equivalent for making a function basically visible in the land of blueprint.

18
00:01:20,570 --> 00:01:23,210
‫But we don't stop there, just like with the new property.

19
00:01:23,210 --> 00:01:31,580
‫We have to make it edit anywhere here with the u function we have to make it blueprint callable and

20
00:01:31,580 --> 00:01:37,760
‫that, as the name suggests, means that this function now becomes a node that blueprint has access

21
00:01:37,760 --> 00:01:38,330
‫to.

22
00:01:38,330 --> 00:01:42,530
‫So let's go over to the grab a CP and create an implementation for this.

23
00:01:42,530 --> 00:01:44,480
‫It's going to be void return type.

24
00:01:44,480 --> 00:01:45,500
‫It's going to be a U.

25
00:01:45,530 --> 00:01:50,720
‫Grabber, colon, colon release, no parameters.

26
00:01:50,720 --> 00:01:57,350
‫And we'll put a function body, which I'm going to stick a u log in and I'm going to give the message,

27
00:01:57,380 --> 00:02:05,600
‫be released grabber like so and then we can compile and back in our beep.

28
00:02:05,600 --> 00:02:12,200
‫Player I'm going to delete the print string node and I'm going to drag off of released here and I'm

29
00:02:12,200 --> 00:02:17,060
‫going to search for release as a function in here.

30
00:02:17,060 --> 00:02:19,130
‫Now let's go and have a little bit of a look around.

31
00:02:19,130 --> 00:02:23,090
‫Nothing's showing up at the moment because I need to do this on the grabber.

32
00:02:23,090 --> 00:02:30,770
‫So let's take the grabber component, drag it into the event graph to create a grabber variable, then

33
00:02:30,770 --> 00:02:34,360
‫drag off of this and search for release.

34
00:02:34,370 --> 00:02:36,680
‫Now, you notice nothing's coming up in this case either.

35
00:02:36,680 --> 00:02:42,020
‫And that's because we've used live coding and sometimes things that are compiled in live coding do not

36
00:02:42,020 --> 00:02:44,180
‫show up in the editor.

37
00:02:44,180 --> 00:02:50,210
‫What we have to do is close down the editor, close down the live coding window and then in Visual Studio

38
00:02:50,210 --> 00:02:57,410
‫code, hit control shift B and build using the Crypt Raider editor win 64 Development Build.

39
00:02:57,410 --> 00:03:03,650
‫Wait for that to succeed and then relaunch the editor from the new project file.

40
00:03:03,650 --> 00:03:10,640
‫Now if we reopen our BP player and now dragging off the grabber, we search for release.

41
00:03:10,640 --> 00:03:13,850
‫You can see that now there is a node called release.

42
00:03:13,850 --> 00:03:17,930
‫And indeed all that's going to do is going to call as C++.

43
00:03:17,930 --> 00:03:25,790
‫So you can see how you can really use Blueprint and C++ in close collaboration this way by exposing

44
00:03:25,790 --> 00:03:28,730
‫C++ things into the Blueprint world.

45
00:03:28,730 --> 00:03:33,170
‫Now I'm going to connect up my release execution pin to the release node.

46
00:03:33,380 --> 00:03:38,630
‫We're going to go in to our dungeon and we're going to hit play.

47
00:03:39,320 --> 00:03:46,940
‫And now if I were to grab and then release, you can't see anything because it's in the output log.

48
00:03:46,940 --> 00:03:52,430
‫So let's open up the output log and dock it to the layout, then hit play again.

49
00:03:53,360 --> 00:03:57,860
‫And now when we grab and then we release, you can see there is a brief message there.

50
00:03:57,860 --> 00:04:04,340
‫It scrolls by really quickly because every tick we are doing this hit gargoyle status statue thing.

51
00:04:04,340 --> 00:04:09,530
‫But there if you stop and look back through the log, you can see it said released grabber.

52
00:04:09,530 --> 00:04:12,980
‫So our C++ code is being executed.

53
00:04:13,010 --> 00:04:19,280
‫Okay, so now I'd like you to move our sweep code in to a grab function.

54
00:04:19,280 --> 00:04:22,340
‫So you're going to create a grab function and call it from Blueprint.

55
00:04:22,340 --> 00:04:25,010
‫You're going to do it the same way as I just did the release function.

56
00:04:25,160 --> 00:04:29,630
‫But when you create the body of the grab function instead of just printing anything, let's move that

57
00:04:29,630 --> 00:04:36,500
‫sweeping code and the if statement and all the prep variables from TIC so that it's not doing it.

58
00:04:36,500 --> 00:04:43,100
‫Every single time we tick to just when we call that grab function, when we press our mouse button down

59
00:04:43,100 --> 00:04:49,970
‫or press a trigger on our controller, so then recompile and check the logs to make sure that indeed

60
00:04:49,970 --> 00:04:54,800
‫that's only happening when you press the button, pause the video and have a go.

61
00:04:58,180 --> 00:04:59,140
‫Welcome back.

62
00:04:59,170 --> 00:05:03,850
‫So let's go in to our C++ and up to our header file.

63
00:05:03,850 --> 00:05:07,390
‫I'm going to close down the compile window here and above release.

64
00:05:07,390 --> 00:05:17,920
‫I'm going to create a new U function blueprint, callable, which is going to be void called grab and

65
00:05:17,920 --> 00:05:20,590
‫we're going to implement this over in the C++.

66
00:05:20,590 --> 00:05:22,600
‫So again, it's going to be a void.

67
00:05:22,600 --> 00:05:28,540
‫You grab a colon, colon grab parentheses and then braces.

68
00:05:28,840 --> 00:05:34,690
‫And I'm going to move all of this code from TIC component because we are setting up our start vectors

69
00:05:34,690 --> 00:05:36,130
‫and all that sort of good stuff.

70
00:05:36,280 --> 00:05:42,940
‫Let's go all the way down and cut it out and paste it into grab instead where it should be.

71
00:05:42,940 --> 00:05:43,810
‫Just fine.

72
00:05:43,810 --> 00:05:50,120
‫Now let's see if live coding will bring about the function in the BP player.

73
00:05:50,140 --> 00:05:55,150
‫Let's go over to the beep player, delete our print string and let's drag off that.

74
00:05:55,150 --> 00:05:58,600
‫Grab a node we've got and see if we can find a grab function.

75
00:05:58,600 --> 00:06:02,170
‫Okay, so this time the grab function was available to us.

76
00:06:02,170 --> 00:06:02,860
‫That's great.

77
00:06:02,860 --> 00:06:09,610
‫Now let's hook up the pressed execution pin, go over to our dungeon, hit play and make sure we scroll

78
00:06:09,610 --> 00:06:11,410
‫down to the bottom of the output log.

79
00:06:11,440 --> 00:06:17,530
‫Going to right click into my viewport and have a look around and then I'm going to press my left button.

80
00:06:17,530 --> 00:06:22,150
‫It says No actor hit and then instantly the release grabber, so no actor hit.

81
00:06:22,150 --> 00:06:24,550
‫And then I release the key, no release grabber.

82
00:06:24,550 --> 00:06:26,770
‫Now if I go up to my gargoyle, I'll have a look at it.

83
00:06:26,800 --> 00:06:31,450
‫I press on it and it says Actor hit Gargoyle Statue and then I can release the grabber.

84
00:06:31,570 --> 00:06:38,770
‫So now we've got the right sort of architecture in place in order to grab this gargoyle.

85
00:06:38,770 --> 00:06:42,760
‫Next, we need to deal with the physics part of this setup.

86
00:06:42,880 --> 00:06:44,290
‫I'll see you in the next lecture.

