﻿1
00:00:04,370 --> 00:00:05,660
‫Hello and welcome.

2
00:00:05,660 --> 00:00:13,250
‫In this lecture, we're going to be understanding the main steps involved in compiling C++ files in

3
00:00:13,250 --> 00:00:13,910
‫Unreal.

4
00:00:13,910 --> 00:00:16,070
‫Let's dive in and see how they work.

5
00:00:16,850 --> 00:00:24,020
‫So it's soon going to be time for us to start using code from the outside, from other files, and we

6
00:00:24,020 --> 00:00:26,750
‫need to learn how this works in C++.

7
00:00:26,750 --> 00:00:31,220
‫To do that, we need to take a little bit of a detour and understand in more detail what's going on

8
00:00:31,220 --> 00:00:35,270
‫when we compile our C++ code into binary.

9
00:00:35,270 --> 00:00:38,690
‫So here are the compilation steps that are used.

10
00:00:38,690 --> 00:00:44,780
‫We start off with your code, your C++ files, your header files, all in various text files.

11
00:00:44,780 --> 00:00:49,070
‫These get fed into a tool called the Unreal Header Tool.

12
00:00:49,070 --> 00:00:56,270
‫Now, this tool is responsible for taking all the unreal specific pieces of syntax and using them to

13
00:00:56,270 --> 00:00:58,760
‫generate more C++ code.

14
00:00:58,760 --> 00:01:05,570
‫So let's have a look at some examples of where we've got this unreal specific syntax, this new class

15
00:01:05,570 --> 00:01:13,700
‫in capital letters that is unreal specific syntax, and so is the Crypt Reader API thing here and the

16
00:01:13,700 --> 00:01:15,380
‫generated body there.

17
00:01:15,410 --> 00:01:21,830
‫And basically what's going on here is the unreal header tool will see these different pieces of syntax

18
00:01:21,830 --> 00:01:24,500
‫in your code and go, okay, I need to do my job.

19
00:01:24,500 --> 00:01:27,020
‫I need to go in there, I need to add a bunch of stuff.

20
00:01:27,050 --> 00:01:33,800
‫It's going to replace your generated body with a bunch of code that makes our lives easier when using

21
00:01:33,800 --> 00:01:34,670
‫Unreal.

22
00:01:35,090 --> 00:01:38,300
‫It's also does things like the U properties and new functions.

23
00:01:38,300 --> 00:01:43,580
‫It adds all the stuff that it needs so that it can communicate with the blueprint world.

24
00:01:43,580 --> 00:01:45,020
‫So that is the first step.

25
00:01:45,020 --> 00:01:49,250
‫It converts all of its unreal specific stuff into actual C++.

26
00:01:49,490 --> 00:01:55,880
‫Once we've got the actual C++, we can then feed it into a standard C++ compilation process, which

27
00:01:55,880 --> 00:01:57,260
‫takes three steps.

28
00:01:57,260 --> 00:02:04,790
‫The first is to deal with the preprocessing step so this can actually touch any of the C++ syntax and

29
00:02:04,790 --> 00:02:07,610
‫actually only deals with lines that start with a hash.

30
00:02:07,610 --> 00:02:10,850
‫So we've got a few of these preprocessing directives.

31
00:02:10,850 --> 00:02:13,400
‫These are dealt with by the preprocessor.

32
00:02:14,150 --> 00:02:16,820
‫The next step is what we actually call the compiler.

33
00:02:16,850 --> 00:02:24,680
‫It takes a code and it converts it into executable binary, but it doesn't quite complete the step because

34
00:02:24,680 --> 00:02:31,790
‫it only does it on individual C++, what are known as translation units, basically C++ files.

35
00:02:31,790 --> 00:02:37,910
‫So it takes a C++ file and it translates that into binary individually, each individual C++ file.

36
00:02:37,910 --> 00:02:44,360
‫And then the third step is the linker, which brings all of that together and outputs an executable

37
00:02:44,360 --> 00:02:47,090
‫that we can actually run a single executable.

38
00:02:47,180 --> 00:02:52,970
‫So let's have a look at these standard compilation steps in a little bit more detail with an example

39
00:02:52,970 --> 00:02:53,780
‫file.

40
00:02:53,840 --> 00:02:55,970
‫So imagine that we had a game.

41
00:02:56,150 --> 00:03:02,420
‫CP And it's a very, very simple game because all it does is add one and one together, but to add one

42
00:03:02,420 --> 00:03:08,540
‫and one together is having to use a function that's declared in a different file in the math.

43
00:03:08,780 --> 00:03:10,700
‫H So the math declares.

44
00:03:10,700 --> 00:03:14,090
‫AD, but it doesn't actually define what it does.

45
00:03:14,090 --> 00:03:16,010
‫So that is done over in the math.

46
00:03:16,190 --> 00:03:19,520
‫CP And you can see it's a very simple implementation indeed.

47
00:03:20,000 --> 00:03:22,700
‫Now what happens at the preprocessor step?

48
00:03:22,700 --> 00:03:28,130
‫Well, like I said, it deals with any preprocessor directives, which are things that begin with a

49
00:03:28,130 --> 00:03:28,610
‫hash.

50
00:03:28,610 --> 00:03:34,970
‫So the hash include math, which basically means just copy everything in math into here.

51
00:03:34,970 --> 00:03:40,700
‫So what it does is it takes these two files and it combines them together to create a new output file

52
00:03:40,700 --> 00:03:48,050
‫called Game I basically games include and you can see that it is included the definition from Master

53
00:03:48,050 --> 00:03:52,730
‫H and it's replaced the hash preprocessor directive.

54
00:03:52,730 --> 00:04:03,180
‫So now Game II has got a definition for the ADD operation and then we run the preprocessor on math DHCP.

55
00:04:03,200 --> 00:04:07,760
‫But because it doesn't have any preprocessor directives, basically nothing is changed there.

56
00:04:08,060 --> 00:04:12,890
‫The next step is the compilation is probably the most important and complicated step, because what

57
00:04:12,890 --> 00:04:21,350
‫it does is it takes that C++ in each individual file and converts it in to binary, but it's not complete

58
00:04:21,350 --> 00:04:28,820
‫binary because for example, my game doesn't actually know how to implement AD, it just knows the shape

59
00:04:28,820 --> 00:04:30,620
‫of that add function.

60
00:04:30,620 --> 00:04:34,940
‫So that needs to be filled in later and that's filled in by the linker.

61
00:04:34,940 --> 00:04:41,150
‫So the linker is going to take the binary created for the game obj file and the binary created for the

62
00:04:41,150 --> 00:04:44,810
‫master file and bring them together to make a game.

63
00:04:45,020 --> 00:04:52,010
‫XY which combines the binary for both and finally is a complete executable that we can actually run

64
00:04:52,010 --> 00:04:55,280
‫because it's got the definition for everything it needs.

65
00:04:55,280 --> 00:04:58,730
‫Now, why do we have such a complicated process?

66
00:04:58,730 --> 00:05:03,860
‫The idea here is that it speeds up our compilation time because if I only made a change.

67
00:05:04,310 --> 00:05:06,470
‫To game DHCP.

68
00:05:06,710 --> 00:05:10,340
‫I don't actually need to run the entire compilation process.

69
00:05:10,340 --> 00:05:16,730
‫All I have to do is run the bits involving game DHCP, so I'd run the preprocessor only on the CP,

70
00:05:16,760 --> 00:05:23,660
‫then I'd run the compiler only on the game to I and then I can reuse the math obj file from before.

71
00:05:23,660 --> 00:05:26,960
‫I don't need to recompile it because nothing has changed in that.

72
00:05:26,960 --> 00:05:33,590
‫Similarly, if I only change math dot CP, I wouldn't have to recompile the game obj file, which is

73
00:05:33,590 --> 00:05:37,640
‫why this is a more efficient process and why we're doing it in the first place.

74
00:05:37,640 --> 00:05:44,630
‫So I'd like us to do a little experiment and try and figure out why do we include move a H in and move

75
00:05:44,630 --> 00:05:46,280
‫a CP file?

76
00:05:46,280 --> 00:05:47,750
‫What's the reason for it?

77
00:05:47,750 --> 00:05:51,770
‫Why can't we just compile the C++ file without including moved?

78
00:05:51,770 --> 00:05:56,660
‫H So the experiment we're going to do is we're going to comment out the hash include line.

79
00:05:56,660 --> 00:06:02,000
‫So using a double forward slash to make a comment in front of that line, which will basically make

80
00:06:02,000 --> 00:06:07,340
‫it get stripped out by the preprocessor instead of the preprocessor replacing it with the contents of

81
00:06:07,340 --> 00:06:08,060
‫the file.

82
00:06:08,510 --> 00:06:15,050
‫We're then going to recompile and I'd like you to have a look at the error messages that come out and

83
00:06:15,050 --> 00:06:21,110
‫see what it says to see if you can try and understand what it is that we're including this move for.

84
00:06:21,260 --> 00:06:23,450
‫Pause the video and have a go.

85
00:06:26,590 --> 00:06:27,030
‫Okay.

86
00:06:27,040 --> 00:06:28,000
‫Welcome back.

87
00:06:28,030 --> 00:06:33,280
‫So let's put a double forward slash at the beginning of this line, which basically makes it null and

88
00:06:33,280 --> 00:06:33,870
‫void.

89
00:06:33,880 --> 00:06:40,450
‫And then we're going to do a control alt f 11 and we're going to have a look at the output of live coding.

90
00:06:40,450 --> 00:06:44,680
‫So look, we've got some errors straight away very, very early on.

91
00:06:44,680 --> 00:06:50,740
‫And what it's saying is that you mover is not a class or namespace and there's some other stuff down

92
00:06:50,740 --> 00:06:51,160
‫here.

93
00:06:51,160 --> 00:06:56,050
‫It's saying that primary tech component hasn't been declared that super isn't a class or namespace get

94
00:06:56,050 --> 00:06:58,360
‫owner is an unknown identifier.

95
00:06:58,360 --> 00:07:03,940
‫And basically what this is saying is you've talked about you mover here, but you've not defined it

96
00:07:03,940 --> 00:07:05,920
‫anywhere, you've not declared it anywhere.

97
00:07:05,920 --> 00:07:07,240
‫So I don't know.

98
00:07:07,240 --> 00:07:11,560
‫The C++ compiler says, I don't know what this is.

99
00:07:11,560 --> 00:07:18,250
‫So that's why we are hash, including the mover H because mover H declares the class.

100
00:07:18,250 --> 00:07:25,780
‫It says a U mover is a class and it derives from you act a component and it's got these methods, etc.

101
00:07:25,780 --> 00:07:28,480
‫It's declaring what it means to be that class.

102
00:07:28,480 --> 00:07:32,440
‫So without that declaration, the C++ compiler can't continue.

103
00:07:32,440 --> 00:07:36,160
‫And that's why we need to include that header file.

104
00:07:36,760 --> 00:07:37,240
‫Great stuff.

105
00:07:37,240 --> 00:07:44,920
‫So hopefully you now understand a little bit better the process involved in compilation of C++ and particularly

106
00:07:44,920 --> 00:07:47,890
‫compilation of C++ in Unreal.

107
00:07:47,920 --> 00:07:49,810
‫I will see you in the next lecture.

