WEBVTT 1 00:00:24.200 --> 00:00:26.230 Hello, I'm Joohwan Kim 2 00:00:26.231 --> 00:00:29.731 This is the fourth class of Unreal C++ basics 3 00:00:29.731 --> 00:00:32.959 C++ Unreal Structure 4 00:00:32.959 --> 00:00:37.510 During this time, inheritance, polymorphism, and template 5 00:00:37.511 --> 00:00:39.560 are the elements of C++ that we'll learn 6 00:00:39.560 --> 00:00:45.870 And we'll learn about the C++ inheritance structure within the Unreal Engine 7 00:00:46.470 --> 00:00:48.320 And in order to implement reflection 8 00:00:48.321 --> 00:00:51.321 We'll learn about UPROPERTY and UFUNCTION 9 00:00:51.520 --> 00:00:55.320 Finally, we'll learn about the life cycle of actors 10 00:00:55.320 --> 00:00:57.380 Then after the lecture 11 00:00:57.381 --> 00:01:00.731 you will be ready for C++ programming using Unreal 12 00:01:02.475 --> 00:01:05.075 Understanding Inheritance, Polymorphism, and Template 13 00:01:06.080 --> 00:01:09.120 First, the other elements of C++ 14 00:01:09.120 --> 00:01:12.559 It's actually impossible to explain all the elements of C++ 15 00:01:12.559 --> 00:01:15.669 But in order to do Unreal C++ Programming 16 00:01:15.670 --> 00:01:17.620 a must-have part is 17 00:01:17.620 --> 00:01:20.400 inheritance 18 00:01:20.400 --> 00:01:23.599 We learned about class in the previous lecture 19 00:01:23.599 --> 00:01:27.850 Inheritance is collecting a certain part 20 00:01:27.851 --> 00:01:29.801 and sending it to the parent object 21 00:01:29.801 --> 00:01:32.239 So it inherits the parent 22 00:01:32.239 --> 00:01:35.800 It's like us inheriting in real life 23 00:01:35.800 --> 00:01:38.599 A certain property, or content 24 00:01:38.600 --> 00:01:41.700 Usually data and function, are inherited 25 00:01:41.700 --> 00:01:44.260 When parent class is inherited 26 00:01:44.261 --> 00:01:48.811 The daughter becomes the parent's member variable, or member function 27 00:01:48.811 --> 00:01:49.559 It becomes the member of the parent 28 00:01:49.559 --> 00:01:53.080 We can call it parent's member variable or member function, either works 29 00:01:53.080 --> 00:01:55.561 We make this inheritance because 30 00:01:55.561 --> 00:01:57.461 since we're making multiple classes 31 00:01:57.461 --> 00:02:00.619 the similar parts that overlap 32 00:02:00.620 --> 00:02:02.120 need to be reused 33 00:02:02.120 --> 00:02:03.599 That's why this grammar was made 34 00:02:03.599 --> 00:02:05.750 For example 35 00:02:05.751 --> 00:02:09.801 Birds, cats, whales 36 00:02:09.801 --> 00:02:12.399 These objects were constructed with class 37 00:02:12.399 --> 00:02:13.920 But after construction 38 00:02:13.921 --> 00:02:16.671 They had the similarity of being a living thing 39 00:02:16.720 --> 00:02:19.440 And the similarity of moving 40 00:02:19.440 --> 00:02:21.600 And the similarity of having a name 41 00:02:21.600 --> 00:02:24.140 All these parts are overlapping 42 00:02:24.140 --> 00:02:26.940 So we make a parent class called living thing 43 00:02:26.940 --> 00:02:28.690 And by inheriting that 44 00:02:28.691 --> 00:02:32.091 we make birds, cats, dogs, and whales 45 00:02:32.240 --> 00:02:37.039 The inherited form is called Class Hierarchy 46 00:02:37.039 --> 00:02:39.759 In English, it's called hierarchy 47 00:02:39.759 --> 00:02:43.720 Hierarchy is similar to a family tree 48 00:02:43.720 --> 00:02:45.279 That's also called Hierarchy 49 00:02:45.279 --> 00:02:48.360 Just like the family tree 50 00:02:48.360 --> 00:02:51.720 The parent class, the middle class 51 00:02:51.720 --> 00:02:55.720 and the bottom class are depicted 52 00:02:55.720 --> 00:02:57.880 So creating this hierarchy 53 00:02:57.880 --> 00:02:59.899 in object-oriented programming 54 00:02:59.900 --> 00:03:01.300 it corresponds to the construction part 55 00:03:01.300 --> 00:03:03.880 It's a very important part 56 00:03:03.880 --> 00:03:05.479 There's a lot of philosophy to it 57 00:03:05.479 --> 00:03:06.689 As I mentioned earlier 58 00:03:06.690 --> 00:03:08.890 Are we going to link it by similar parts 59 00:03:09.039 --> 00:03:11.839 or are we going to link them by similar forms 60 00:03:11.839 --> 00:03:14.359 or link them by similar functions 61 00:03:14.759 --> 00:03:16.399 There are various approaches 62 00:03:16.399 --> 00:03:19.919 Based on that, we would link them differently 63 00:03:19.919 --> 00:03:21.439 The things I mentioned earlier 64 00:03:21.440 --> 00:03:22.940 We may link them as living things 65 00:03:22.940 --> 00:03:25.750 or moveable 66 00:03:25.751 --> 00:03:27.301 having a name 67 00:03:27.302 --> 00:03:28.852 able to move 68 00:03:28.852 --> 00:03:31.119 able to attack, able to be hit 69 00:03:31.119 --> 00:03:34.620 Like those, they may also be classified by functions 70 00:03:35.320 --> 00:03:38.000 So in order to implement those 71 00:03:38.000 --> 00:03:38.880 What we need to know it 72 00:03:38.880 --> 00:03:41.200 Function Overriding 73 00:03:41.201 --> 00:03:43.851 We need to redefine the function 74 00:03:44.000 --> 00:03:46.839 What this means is that 75 00:03:46.839 --> 00:03:49.759 The daughter classes that inherited the parent class 76 00:03:49.759 --> 00:03:53.320 Still has the member variable of the parent 77 00:03:53.320 --> 00:03:55.399 It's not private, but more than protected 78 00:03:55.399 --> 00:03:57.479 If the access modifier is made 79 00:03:57.479 --> 00:04:00.759 The data within the parent class can be used 80 00:04:00.759 --> 00:04:02.869 As for functions 81 00:04:02.869 --> 00:04:05.919 we can also use the parent class 82 00:04:05.919 --> 00:04:07.959 But rather than the parent operation 83 00:04:07.960 --> 00:04:09.760 If we want to operate differently 84 00:04:09.760 --> 00:04:11.240 Then we do overriding 85 00:04:11.240 --> 00:04:13.080 That's why it's function overriding 86 00:04:13.119 --> 00:04:15.199 When we do function overriding 87 00:04:15.199 --> 00:04:17.000 Operating in the parent 88 00:04:17.000 --> 00:04:19.839 and operating in the daughter can be made differently 89 00:04:19.839 --> 00:04:21.239 That's called polymorphism 90 00:04:21.239 --> 00:04:24.160 It's also called dynamic binding 91 00:04:24.160 --> 00:04:27.239 Usually, we call it subtype polymorphism 92 00:04:27.239 --> 00:04:28.640 There are many types of polymorphisms 93 00:04:28.640 --> 00:04:30.760 Out of them, the sub type 94 00:04:30.760 --> 00:04:32.519 So between the parent and the daughter 95 00:04:32.519 --> 00:04:37.279 Since the sub type is made from the parent 96 00:04:37.279 --> 00:04:40.239 the polymorphism that has the form of parent-daughter relationship 97 00:04:40.239 --> 00:04:42.640 is called sub-type polymorphism 98 00:04:42.640 --> 00:04:45.200 And through polymorphisms 99 00:04:45.200 --> 00:04:48.040 By combining multiple objects into one parent 100 00:04:48.040 --> 00:04:50.279 The parent function 101 00:04:50.279 --> 00:04:52.559 Usually the virtual function, is overridden 102 00:04:52.559 --> 00:04:55.489 Using the parent function to control 103 00:04:55.490 --> 00:04:56.840 the daughter class functions 104 00:04:57.239 --> 00:04:59.660 is called abstraction 105 00:05:00.160 --> 00:05:04.640 To tell you about polymorphism further 106 00:05:04.640 --> 00:05:08.079 If we take a look at the link about polymorphism 107 00:05:08.079 --> 00:05:09.440 The page you're seeing right now 108 00:05:09.440 --> 00:05:11.640 is called GitHub 109 00:05:11.640 --> 00:05:16.059 You'll use it a lot as a programmer 110 00:05:16.559 --> 00:05:19.559 It uses the version control system called Git 111 00:05:19.559 --> 00:05:21.909 The sources that Microsoft possesses 112 00:05:21.910 --> 00:05:24.360 can be saved in this page 113 00:05:24.360 --> 00:05:27.679 If you take a look, there's a particular page 114 00:05:27.679 --> 00:05:29.239 and the 4 types of C++ polymorphism 115 00:05:29.239 --> 00:05:32.279 It says The Four Polymorphisms in C++ 116 00:05:32.279 --> 00:05:35.219 It's an explanation of the four types of polymorphisms of C++ 117 00:05:35.219 --> 00:05:38.239 Polymorphism exists in more than 4 types 118 00:05:38.239 --> 00:05:41.279 These days, we even say 7 types or 12 types 119 00:05:41.279 --> 00:05:43.959 To put it in simple terms 120 00:05:43.959 --> 00:05:45.600 When we do a certain operation 121 00:05:45.600 --> 00:05:47.040 It's the same operation 122 00:05:47.040 --> 00:05:50.289 But it acts differently based on the object 123 00:05:50.289 --> 00:05:51.880 It's the same command 124 00:05:51.881 --> 00:05:55.131 but it acts differently, and that's what polymorphism is 125 00:05:55.131 --> 00:05:59.100 So just like the first line, there's subtype polymorphism 126 00:05:59.100 --> 00:06:01.330 And second, parameter polymorphism 127 00:06:01.331 --> 00:06:03.731 and temporary polymorphism and forced polymorphism 128 00:06:03.980 --> 00:06:06.379 I'll only explain about the subtype polymorphism 129 00:06:06.379 --> 00:06:08.920 It's also called runtime polymorphism 130 00:06:08.920 --> 00:06:10.020 As I told you 131 00:06:10.021 --> 00:06:13.971 Linking cats, tigers, and cheetahs 132 00:06:13.971 --> 00:06:19.200 and calling them "moving", is what the example shows 133 00:06:19.200 --> 00:06:22.250 To tell you about abstraction 134 00:06:22.251 --> 00:06:24.851 Through subtype polymorphism 135 00:06:24.851 --> 00:06:28.900 a certain object is literally becoming abstracted 136 00:06:29.450 --> 00:06:33.000 Dogs, cats, and whales can all move but 137 00:06:33.000 --> 00:06:35.471 Dogs will run 138 00:06:35.471 --> 00:06:37.821 Birds will fly 139 00:06:37.822 --> 00:06:39.322 And whales will swim 140 00:06:39.322 --> 00:06:41.480 But by placing a parent object 141 00:06:41.481 --> 00:06:44.581 and calling it "move", is abstracting 142 00:06:44.799 --> 00:06:49.900 It abstracts by using polymorphism 143 00:06:49.900 --> 00:06:54.580 It's similar to hiding data using capsulation 144 00:06:54.580 --> 00:06:57.139 In summary, it's a method of abstracting class and method 145 00:06:57.139 --> 00:07:00.620 It's the method of abstraction, and it uses polymorphism 146 00:07:00.620 --> 00:07:05.660 To implement polymorphism, to implement abstraction 147 00:07:05.660 --> 00:07:10.009 The most important part of C++ grammar 148 00:07:10.010 --> 00:07:12.160 There's the virtual keyword 149 00:07:12.160 --> 00:07:16.570 When the keyword virtual is placed in front of a function 150 00:07:16.571 --> 00:07:17.921 It becomes a virtual function 151 00:07:17.921 --> 00:07:19.699 Called virtual function in English 152 00:07:19.699 --> 00:07:22.120 As I mentioned earlier 153 00:07:22.121 --> 00:07:24.921 Implementing subtype polymorphism 154 00:07:24.921 --> 00:07:28.980 It's the most normal and the only way 155 00:07:28.980 --> 00:07:32.660 In the grammar, create the virtual function in the parent 156 00:07:32.660 --> 00:07:35.630 and in the daughter, take the virtual function 157 00:07:35.631 --> 00:07:37.831 and override it 158 00:07:38.430 --> 00:07:41.309 Then when it's called from the parent 159 00:07:41.310 --> 00:07:43.310 Even though it's the same call 160 00:07:43.310 --> 00:07:46.500 It will show different operations based on the daughter type 161 00:07:46.500 --> 00:07:49.699 For overriding and virtual function, the signature has to match 162 00:07:49.699 --> 00:07:52.900 Signature, as I mentioned before 163 00:07:52.900 --> 00:07:55.670 For the signature of a function 164 00:07:55.670 --> 00:07:58.921 The return type and the parameter 165 00:07:59.020 --> 00:08:02.699 and how the function looks, are called signature 166 00:08:02.699 --> 00:08:04.820 Having the two integer parameters 167 00:08:04.820 --> 00:08:07.619 A function that has the integer return form 168 00:08:07.619 --> 00:08:10.580 Then we say that the signature is the same 169 00:08:10.580 --> 00:08:14.020 So when the signature of the parent and the daughter is the same 170 00:08:14.020 --> 00:08:17.259 The method of calling the function will also be the same 171 00:08:17.259 --> 00:08:20.699 Then through function call, we can implement polymorphism 172 00:08:20.699 --> 00:08:24.580 For polymorphism and virtual function, destructor is possible 173 00:08:24.580 --> 00:08:27.319 For destructor, when it disappears 174 00:08:27.320 --> 00:08:29.670 in order to destruct polymorphically 175 00:08:29.670 --> 00:08:31.810 it can use them 176 00:08:31.811 --> 00:08:33.511 It's impossible for constructor 177 00:08:33.511 --> 00:08:35.380 And that's because 178 00:08:35.380 --> 00:08:38.940 in the hierarchy, the parent and the daughter has to be formed 179 00:08:38.940 --> 00:08:40.559 But when the parent is constructed 180 00:08:40.560 --> 00:08:42.260 we don't know the daughter 181 00:08:42.260 --> 00:08:45.220 So it's not the target of virtual function 182 00:08:45.220 --> 00:08:49.860 Once we know virtual function, the way how virtual functions work 183 00:08:49.860 --> 00:08:54.500 or the way it compiles as one, also needs to be learned 184 00:08:54.500 --> 00:08:56.419 First, there's something called static binding 185 00:08:56.419 --> 00:08:58.619 What static binding is 186 00:08:58.619 --> 00:09:02.139 is that it's related to how the function is called over 187 00:09:02.140 --> 00:09:04.890 At the side where the function is called over to 188 00:09:04.890 --> 00:09:06.860 In order to call the function 189 00:09:06.860 --> 00:09:10.100 In order to call the function text 190 00:09:10.100 --> 00:09:13.179 they need to know the address of the function text 191 00:09:13.179 --> 00:09:16.059 So what decides the address 192 00:09:16.059 --> 00:09:19.500 When you compile, you can know the function call address 193 00:09:19.500 --> 00:09:21.660 Of course, you'll need to address when it operates 194 00:09:21.660 --> 00:09:22.960 But when it compiles 195 00:09:22.961 --> 00:09:24.961 The address that calls the function 196 00:09:24.961 --> 00:09:27.159 gets inserted into the calling part 197 00:09:27.159 --> 00:09:29.300 This is called static binding 198 00:09:29.300 --> 00:09:30.899 also called early binding 199 00:09:30.899 --> 00:09:32.580 In other words, when calling the function 200 00:09:32.580 --> 00:09:35.300 For normal functions, at the time of call 201 00:09:35.300 --> 00:09:38.179 we say that we know where the function is at 202 00:09:38.179 --> 00:09:41.220 So for normal member functions, static binding 203 00:09:41.220 --> 00:09:42.779 is done 204 00:09:42.779 --> 00:09:45.539 For normally made functions 205 00:09:45.539 --> 00:09:47.619 Whether they're member functions or not 206 00:09:47.619 --> 00:09:50.020 Since we're talking about class right now, they're member functions 207 00:09:50.020 --> 00:09:53.699 But for normal functions, they're called static 208 00:09:53.699 --> 00:09:58.259 But as before, in order to implement subtype polymorphism 209 00:09:58.259 --> 00:10:00.740 Function made as virtual function 210 00:10:00.740 --> 00:10:02.699 can be decided at the time of operation 211 00:10:02.699 --> 00:10:05.640 Because the pointer of the parent 212 00:10:05.641 --> 00:10:08.241 can point to the daughter 213 00:10:08.241 --> 00:10:10.940 But when the parent is pointing to the daughter 214 00:10:10.940 --> 00:10:14.540 The actual type may be bird, cat, or dog 215 00:10:14.540 --> 00:10:16.779 But when it receives living thing 216 00:10:16.779 --> 00:10:20.299 Until the time of calling it as living thing class 217 00:10:20.299 --> 00:10:22.220 it's usually not decided until then 218 00:10:22.220 --> 00:10:26.859 So we say that we decide the call function during runtime 219 00:10:26.859 --> 00:10:29.739 and that's called dynamic binding, or late binding 220 00:10:29.739 --> 00:10:33.220 In summary, virtual function is when 221 00:10:33.221 --> 00:10:35.471 you know the address of the function when you call 222 00:10:35.471 --> 00:10:37.739 And you know it by 223 00:10:37.739 --> 00:10:40.049 for any objects or any classes 224 00:10:40.050 --> 00:10:42.050 when you use virtual function 225 00:10:42.050 --> 00:10:43.549 Where there's at least one virtual keyword 226 00:10:43.550 --> 00:10:45.000 and it's implemented 227 00:10:45.000 --> 00:10:49.420 The 4 byte or 8 byte at the very front of the class 228 00:10:49.420 --> 00:10:52.619 The pointer forms, that points to the virtual function table 229 00:10:52.619 --> 00:10:56.921 So it includes the information of what function to call and how to call 230 00:10:56.921 --> 00:10:59.980 The pointer that points to the table, is formed 231 00:10:59.980 --> 00:11:01.929 And through the pointer 232 00:11:01.930 --> 00:11:03.880 Through the pointer of basic class 233 00:11:03.880 --> 00:11:05.270 Where the function is at 234 00:11:05.271 --> 00:11:08.621 Where the function pointer is at, is found 235 00:11:08.820 --> 00:11:11.250 This is subtype polymorphism 236 00:11:11.251 --> 00:11:15.501 It's the method of how polymorphism is formed 237 00:11:15.700 --> 00:11:19.540 We need to actually look at the code in order to understand 238 00:11:19.540 --> 00:11:21.339 That's how difficult it is at first 239 00:11:21.339 --> 00:11:22.750 So for now 240 00:11:22.751 --> 00:11:24.551 When calling with virtual function, we can know the address of the function 241 00:11:24.551 --> 00:11:27.380 Static binding, is as far as you should know 242 00:11:27.380 --> 00:11:29.339 So when making this virtual function 243 00:11:29.339 --> 00:11:33.299 Among virtual function, there's something called pure virtual function 244 00:11:33.299 --> 00:11:36.220 It's for making abstract class 245 00:11:36.220 --> 00:11:38.899 To put this in simple terms 246 00:11:38.900 --> 00:11:42.700 It's a virtual function with no content, no implementation 247 00:11:42.899 --> 00:11:46.829 The dog runs, the bird flies 248 00:11:46.830 --> 00:11:48.630 the whale swims 249 00:11:48.630 --> 00:11:50.980 We say that the living things are moving 250 00:11:50.980 --> 00:11:53.500 But the living thing may not even be there 251 00:11:53.500 --> 00:11:55.460 The target of living thing 252 00:11:55.461 --> 00:11:58.311 may not even move, is what it means 253 00:11:58.311 --> 00:12:03.039 So for abstract class that contains pure virtual function 254 00:12:03.040 --> 00:12:05.440 Instance is impossible 255 00:12:05.440 --> 00:12:07.859 It means that we can't create that class 256 00:12:07.859 --> 00:12:11.479 The concept of a living thing moving 257 00:12:11.480 --> 00:12:12.880 can't be actually made 258 00:12:12.880 --> 00:12:15.260 By creating a pointer called living thing 259 00:12:15.260 --> 00:12:17.829 we point to the dog, point to the bird 260 00:12:17.830 --> 00:12:19.980 and pointing to the whale, is possible 261 00:12:19.980 --> 00:12:24.100 It's the exact same meaning as the pointer 262 00:12:24.100 --> 00:12:27.739 So for pure virtual function 263 00:12:27.739 --> 00:12:33.299 Or abstract virtual function, doesn't create the function implementation 264 00:12:33.299 --> 00:12:35.759 It only creates the outer form of the function 265 00:12:35.760 --> 00:12:38.160 and redefine them in the daughter 266 00:12:38.459 --> 00:12:40.700 When we use this pure virtual function 267 00:12:40.701 --> 00:12:43.401 we can't actually made the object 268 00:12:43.500 --> 00:12:47.140 so we can't only make abstract classes 269 00:12:47.141 --> 00:12:49.401 We can only make abstract class 270 00:12:49.401 --> 00:12:52.301 And this means forcing abstract 271 00:12:52.301 --> 00:12:55.600 Related to virtual function, I can explain about the virtual destructor 272 00:12:55.601 --> 00:12:58.301 As I mentioned earlier, destructor is possible in virtual function 273 00:12:58.302 --> 00:12:59.850 but not constructor 274 00:12:59.850 --> 00:13:03.300 Why does destructor have virtual function? 275 00:13:03.301 --> 00:13:05.101 Within the hierarchy 276 00:13:05.102 --> 00:13:07.703 When there's the parent and daughter relationship 277 00:13:07.753 --> 00:13:12.253 In order to completely destroy the daughter using the parent class 278 00:13:12.254 --> 00:13:16.054 even the destroyer is implemented virtually 279 00:13:16.654 --> 00:13:18.454 This is the virtual function table I mentioned earlier 280 00:13:18.454 --> 00:13:20.851 It's called virtual table 281 00:13:20.851 --> 00:13:24.901 There were controversies about the word virtual 282 00:13:24.902 --> 00:13:30.703 The address of the function created virtually, or dynamically 283 00:13:30.703 --> 00:13:33.903 the function pointer is included in this table 284 00:13:33.903 --> 00:13:35.901 The compiler makes this 285 00:13:35.901 --> 00:13:39.551 The implementation may be different based on how the compiler makes it 286 00:13:39.551 --> 00:13:42.750 But grammatically, when virtual function is called over 287 00:13:42.751 --> 00:13:45.151 The daughter is overridden 288 00:13:45.152 --> 00:13:48.000 in the virtual function 289 00:13:48.000 --> 00:13:49.901 If it follows the C++ standard 290 00:13:49.901 --> 00:13:52.651 So the class that uses virtual function 291 00:13:52.652 --> 00:13:54.352 has the virtual function table 292 00:13:54.353 --> 00:13:57.904 And the pointer that points to the table 293 00:13:57.904 --> 00:13:59.554 is saved in the object 294 00:14:00.150 --> 00:14:03.700 I explained about abstract and polymorphism 295 00:14:03.701 --> 00:14:07.751 For configuration of the C++ language 296 00:14:07.752 --> 00:14:10.452 For the two main elements 297 00:14:10.452 --> 00:14:13.600 Unlike C, the two main elements are 298 00:14:13.601 --> 00:14:18.901 Abstract and polymorphism are one part 299 00:14:18.902 --> 00:14:21.602 And then there's template called generic 300 00:14:21.602 --> 00:14:23.950 It's called generic programming 301 00:14:23.951 --> 00:14:26.601 It means that we can do something generally 302 00:14:26.602 --> 00:14:29.602 In C++, this grammar is called template 303 00:14:29.952 --> 00:14:34.150 This template grammar literally means template 304 00:14:34.151 --> 00:14:36.601 It sets the form 305 00:14:36.602 --> 00:14:39.902 In generic programming 306 00:14:39.903 --> 00:14:42.553 it's used as a tool 307 00:14:42.553 --> 00:14:45.650 Let's take a quick look at the MSDN page 308 00:14:45.650 --> 00:14:48.200 As I explained in other lectures 309 00:14:48.201 --> 00:14:51.501 for looking at a certain concept, the best way is 310 00:14:51.502 --> 00:14:54.152 using Microsoft's 311 00:14:54.153 --> 00:14:56.753 Visual Studio C++ 312 00:14:56.753 --> 00:15:00.750 That's why is good to use Microsoft's MSDN page 313 00:15:00.750 --> 00:15:05.350 At the very top, it says 'Learn C++, C and Assembler' 314 00:15:05.351 --> 00:15:08.451 And it says template C++ 315 00:15:08.601 --> 00:15:12.300 Normally, template grammar 316 00:15:12.301 --> 00:15:14.001 only exists in C++ 317 00:15:14.002 --> 00:15:16.502 Template limited to C++ 318 00:15:16.503 --> 00:15:19.353 Template is the basis of generic programming in C++ 319 00:15:19.353 --> 00:15:21.700 There's the basic explanation 320 00:15:21.701 --> 00:15:24.001 There's the definition and usage of template 321 00:15:24.001 --> 00:15:28.050 Under here, it says C++ and there's a code 322 00:15:28.051 --> 00:15:32.251 template typename T, T minimum, const T reference 323 00:15:32.551 --> 00:15:34.600 Like this, template grammar 324 00:15:34.601 --> 00:15:36.950 is pretty complicated for a beginner 325 00:15:36.950 --> 00:15:38.550 But in the beginning 326 00:15:38.551 --> 00:15:43.151 there's the template bent bracket, called angle bracket 327 00:15:43.151 --> 00:15:46.000 Starting from the angle bracket 328 00:15:46.001 --> 00:15:48.801 typename T, then close angle bracket 329 00:15:48.801 --> 00:15:52.251 This grammar is essential for using template 330 00:15:52.251 --> 00:15:54.301 It's a must-have grammar 331 00:15:54.301 --> 00:15:57.050 And the next part that starts with T 332 00:15:57.051 --> 00:15:58.801 The typename of template 333 00:15:58.802 --> 00:16:01.152 It means that it operates on a certain T type 334 00:16:01.152 --> 00:16:03.800 So the details and the form parameter 335 00:16:03.801 --> 00:16:06.251 parameters without the form, specialization 336 00:16:06.251 --> 00:16:12.000 Template is the grammar that takes up the other 50% of C++ 337 00:16:12.001 --> 00:16:14.051 So the grammar is very complicated and varies a lot 338 00:16:14.051 --> 00:16:17.000 So for modern C++ 339 00:16:17.001 --> 00:16:22.101 After C++ emerging in 1979 340 00:16:22.102 --> 00:16:25.002 it continues to improve from 2011 341 00:16:25.002 --> 00:16:26.800 So it's called C++11 342 00:16:26.801 --> 00:16:28.001 After 2011 343 00:16:28.002 --> 00:16:30.402 a new version is released every 3 years 344 00:16:30.402 --> 00:16:32.400 And the new versions are mostly 345 00:16:32.401 --> 00:16:34.750 used for strengthening generic programming 346 00:16:34.750 --> 00:16:39.501 So template has various grammars and is difficult 347 00:16:39.501 --> 00:16:42.201 but if you want to use C++ well 348 00:16:42.251 --> 00:16:44.350 you must know this grammar 349 00:16:44.351 --> 00:16:46.601 So I hope you take a look at the MSDN page 350 00:16:46.601 --> 00:16:48.450 Using template 351 00:16:48.451 --> 00:16:50.201 is called compile type polymorphism 352 00:16:50.201 --> 00:16:52.101 In English, Compile Type Polymorphism 353 00:16:52.101 --> 00:16:53.500 Usually, for polymorphism 354 00:16:53.500 --> 00:16:57.700 as I explained earlier, abstract that uses virtual function 355 00:16:57.701 --> 00:17:01.101 It's usually called runtime polymorphism that uses virtual function 356 00:17:01.101 --> 00:17:03.400 The polymorphism appears at the time of operation 357 00:17:03.401 --> 00:17:06.101 But unlike that, using a template 358 00:17:06.101 --> 00:17:09.051 Compile type, or the source code 359 00:17:09.051 --> 00:17:11.201 If they're made into a binary code 360 00:17:11.202 --> 00:17:13.402 and made possible, that's called compile 361 00:17:13.402 --> 00:17:15.650 At the time of translating 362 00:17:15.651 --> 00:17:19.301 the polymorphism is operated 363 00:17:19.301 --> 00:17:22.050 So at the time of compiling 364 00:17:22.051 --> 00:17:26.451 we said that it's a tool for making a class type 365 00:17:26.451 --> 00:17:28.550 But even for the type 366 00:17:28.551 --> 00:17:31.251 Even when we don't know what type will come in 367 00:17:31.252 --> 00:17:33.202 We can still write the code 368 00:17:33.202 --> 00:17:34.351 To put it in simple terms 369 00:17:34.351 --> 00:17:38.351 I explained about the add function that adds two integers 370 00:17:38.351 --> 00:17:40.500 When we make the add function 371 00:17:40.501 --> 00:17:44.451 We don't know whether integer or float will come in 372 00:17:44.452 --> 00:17:46.252 But we can still make it 373 00:17:46.252 --> 00:17:48.700 That's the concept 374 00:17:48.701 --> 00:17:51.101 of compile type polymorphism template 375 00:17:51.101 --> 00:17:54.000 So on top of runtime polymorphism 376 00:17:54.001 --> 00:17:57.451 Runtime polymorphism is the same thing as subtype polymorphism 377 00:17:57.451 --> 00:17:59.301 The runtime polymorphism 378 00:17:59.301 --> 00:18:02.351 On top of the polymorphism that uses hierarchy 379 00:18:02.352 --> 00:18:05.002 It's also an important element of C++ 380 00:18:05.803 --> 00:18:08.254 C++ Unreal Engine Structure 381 00:18:09.350 --> 00:18:12.301 So the overall form 382 00:18:12.301 --> 00:18:16.401 of C++ were touched upon 383 00:18:16.401 --> 00:18:18.200 Based on that 384 00:18:18.201 --> 00:18:22.251 let's take a look at the hierarchy structure of Unreal C++ 385 00:18:22.251 --> 00:18:24.801 Visual studio 2022 community 386 00:18:24.801 --> 00:18:27.801 We're going to use this version 387 00:18:27.901 --> 00:18:30.850 And let's skim through the Unreal source code 388 00:18:30.850 --> 00:18:32.451 We didn't learn it yet 389 00:18:32.451 --> 00:18:36.751 but actor class, with A as the prefix 390 00:18:36.751 --> 00:18:40.400 actor class and character class 391 00:18:40.401 --> 00:18:42.251 For the hierarchy of the actor class series 392 00:18:42.252 --> 00:18:45.102 as we move up from the character class 393 00:18:45.103 --> 00:18:47.403 We'll take a look at the inheritance structure 394 00:18:47.404 --> 00:18:49.440 If you look at the source code 395 00:18:49.440 --> 00:18:50.945 There's a lot to explain 396 00:18:50.945 --> 00:18:55.120 But I'll just touch upon the main parts 397 00:18:55.120 --> 00:18:57.190 First, where 'sharp' is included 398 00:18:57.191 --> 00:19:00.840 Syntaxes such as sharp pragma once or sharp include 399 00:19:00.840 --> 00:19:04.280 are called pre-processors 400 00:19:04.280 --> 00:19:08.160 Before compiling, the pre-processor 401 00:19:08.160 --> 00:19:13.120 the pre-processor is commanded to change the document this way 402 00:19:13.120 --> 00:19:17.600 The pragma once is declaring that this code doesn't repeat twice 403 00:19:17.600 --> 00:19:22.439 And it says sharp include core minimal.h 404 00:19:22.439 --> 00:19:24.730 What #include is, is that 405 00:19:24.731 --> 00:19:27.381 within the source code 406 00:19:27.382 --> 00:19:29.849 other source codes are included 407 00:19:29.849 --> 00:19:34.120 So the core minimal. h header file 408 00:19:34.120 --> 00:19:36.170 is part of the source code 409 00:19:36.170 --> 00:19:39.310 That source code, in this third line 410 00:19:39.311 --> 00:19:41.711 will be copied as is 411 00:19:42.360 --> 00:19:45.709 Then there's include GameFramework/Character.h 412 00:19:45.709 --> 00:19:49.120 Same thing for this, the source code content of character.h 413 00:19:49.121 --> 00:19:51.571 will be pasted as-is here 414 00:19:51.571 --> 00:19:54.400 Then there's UCLASS and parenthesis 415 00:19:54.400 --> 00:19:59.760 This UCLASS doesn't exist in the C++ grammar 416 00:19:59.760 --> 00:20:02.120 The implementation is done by pre-processor 417 00:20:02.121 --> 00:20:05.171 but this grammar doesn't exist in C++ grammar 418 00:20:05.171 --> 00:20:07.639 But it's made with pre-processor 419 00:20:07.639 --> 00:20:11.639 It's a characteristic of C++ used in unreal 420 00:20:11.639 --> 00:20:14.880 When this UCLASS is added, it means that we'll use it in Unreal 421 00:20:14.881 --> 00:20:18.281 That's what it means 422 00:20:18.480 --> 00:20:21.440 Then there's the lowercase class 423 00:20:21.440 --> 00:20:25.400 LECTURE01_API is calling convention 424 00:20:25.400 --> 00:20:28.599 You don't need to know about this for now 425 00:20:28.599 --> 00:20:32.919 This is about how we're going to call this class 426 00:20:32.919 --> 00:20:35.080 It's a code, but we'll pass for now 427 00:20:35.080 --> 00:20:39.199 And the AMyCharacterL after that 428 00:20:39.199 --> 00:20:42.030 This is the class type of the character 429 00:20:42.031 --> 00:20:44.131 that I made in Unreal 430 00:20:44.131 --> 00:20:46.519 And next to it, there's a colon 431 00:20:46.519 --> 00:20:48.959 and says public Acharacter 432 00:20:48.959 --> 00:20:51.160 And this is the grammar of inheritance 433 00:20:51.160 --> 00:20:53.820 The name of the class 434 00:20:53.820 --> 00:20:55.670 The name of the class that I made 435 00:20:55.671 --> 00:20:57.621 is AMyCharacterL 436 00:20:57.621 --> 00:20:59.760 And this AMyCharacterL 437 00:20:59.761 --> 00:21:02.811 is the type I explained, the type of the class 438 00:21:02.960 --> 00:21:05.960 And this class, public acharacter 439 00:21:05.960 --> 00:21:08.960 has another class called acharacter as the parent 440 00:21:08.960 --> 00:21:11.639 That's what this inheritance grammar means 441 00:21:11.639 --> 00:21:14.199 As I mentioned earlier, it corresponds to the inheritance 442 00:21:14.199 --> 00:21:16.119 It has the parent called acharacter 443 00:21:16.119 --> 00:21:18.370 With the acharacter parent 444 00:21:18.371 --> 00:21:20.521 we made the AMyCharacterL 445 00:21:20.521 --> 00:21:23.919 For the generate body inside the braces 446 00:21:23.919 --> 00:21:26.000 it's the code made in Unreal 447 00:21:26.000 --> 00:21:29.880 I'll also explain about this later when I talk about reflection 448 00:21:29.880 --> 00:21:33.919 There are codes that Unreal creates and inserts 449 00:21:33.919 --> 00:21:35.850 For the existing C++ 450 00:21:35.851 --> 00:21:38.701 reflection function is not possible 451 00:21:38.701 --> 00:21:42.020 It's not provided in the language 452 00:21:42.020 --> 00:21:45.080 But to implement that, Unreal has made it 453 00:21:45.080 --> 00:21:47.160 I'll explain about it later 454 00:21:47.160 --> 00:21:50.600 And there's public modifier 455 00:21:50.600 --> 00:21:51.399 There's the comment 456 00:21:51.399 --> 00:21:55.320 and the constructor called AMyCharacterL 457 00:21:55.320 --> 00:21:58.720 And after that, public void BeginPlay 458 00:21:58.720 --> 00:22:00.420 When this actor begins 459 00:22:00.421 --> 00:22:02.371 this is what's called 460 00:22:02.800 --> 00:22:04.880 tick is called at every frame 461 00:22:04.880 --> 00:22:06.160 It says it in English at the top 462 00:22:06.160 --> 00:22:07.479 Called every frame 463 00:22:07.479 --> 00:22:10.919 or called when the game starts or when spawned 464 00:22:10.919 --> 00:22:14.160 The time that these functions will be called 465 00:22:14.160 --> 00:22:16.240 are described in Unreal 466 00:22:16.240 --> 00:22:18.919 For begin play, tick, setup player, and input component 467 00:22:18.919 --> 00:22:22.080 they're all declared as virtual 468 00:22:22.080 --> 00:22:24.320 virtual void, and void is the return type 469 00:22:24.320 --> 00:22:26.040 Virtual, as I mentioned earlier 470 00:22:26.041 --> 00:22:28.841 is the keyword that shows that it's a virtual function 471 00:22:29.240 --> 00:22:32.759 At the back, there's the keyword override 472 00:22:32.759 --> 00:22:34.439 Looking at this 473 00:22:34.440 --> 00:22:37.040 this function was implemented in the parent 474 00:22:37.040 --> 00:22:41.600 and was redefined in the daughter 475 00:22:41.600 --> 00:22:43.560 So the very bottom part 476 00:22:43.561 --> 00:22:46.211 the most daughter of the hierarchy 477 00:22:46.360 --> 00:22:50.880 was this AMyCharacterL class that I created 478 00:22:50.880 --> 00:22:54.880 This AMyCharacterL class inherited from 479 00:22:54.880 --> 00:22:57.960 character a, the parent right above it 480 00:22:57.960 --> 00:23:00.399 Right-click on it in visual studio 481 00:23:00.400 --> 00:23:02.100 and go to definition 482 00:23:02.199 --> 00:23:04.679 Then we can go to the definition of the object 483 00:23:04.679 --> 00:23:07.600 It's the function of the visual studio itself 484 00:23:07.600 --> 00:23:11.040 That's how I moved to the parent right above it 485 00:23:11.040 --> 00:23:13.959 To go back, the class I made earlier 486 00:23:13.959 --> 00:23:15.839 is the character that I made 487 00:23:15.839 --> 00:23:17.799 And in the character I made 488 00:23:17.799 --> 00:23:21.079 there will be functions exclusive to my character 489 00:23:21.079 --> 00:23:22.399 And the a character above it 490 00:23:22.399 --> 00:23:26.040 is a class made by Unreal Engine 491 00:23:26.040 --> 00:23:27.740 Here, normally 492 00:23:27.741 --> 00:23:30.041 it contains how the character is supposed to act 493 00:23:30.041 --> 00:23:33.559 We can't take a look at the entire source, but 494 00:23:33.559 --> 00:23:37.740 the thousands of functions 495 00:23:37.740 --> 00:23:40.519 of Unreal, called api 496 00:23:40.519 --> 00:23:43.799 We can't take a look at the whole Application Programming Interface 497 00:23:43.799 --> 00:23:47.600 but generally, when I make a certain class 498 00:23:47.600 --> 00:23:49.819 at the top 499 00:23:49.820 --> 00:23:52.520 to see what code that Unreal makes 500 00:23:52.520 --> 00:23:56.219 I'm looking through the sources 501 00:23:56.219 --> 00:24:00.659 It says class ACharacter : public APawn 502 00:24:00.659 --> 00:24:04.249 It means that it made the class, or character, by inheriting Pawn 503 00:24:04.659 --> 00:24:07.219 Same thing here, in GenerateBody 504 00:24:07.219 --> 00:24:10.929 codes for reflection made by Unreal were inserted 505 00:24:11.379 --> 00:24:14.628 Underneath, it says DefaultUObjectConstruct 506 00:24:14.628 --> 00:24:16.669 In order to Unreal to use them 507 00:24:16.819 --> 00:24:20.019 the basic codes are listed here 508 00:24:20.379 --> 00:24:22.499 Similarly, if we move up one step again 509 00:24:22.500 --> 00:24:24.800 There class APawn 510 00:24:24.800 --> 00:24:27.659 Pawn is just like the Pawn of chess 511 00:24:27.659 --> 00:24:29.129 It's lower than the actor 512 00:24:29.130 --> 00:24:30.430 but higher than the character 513 00:24:30.430 --> 00:24:32.239 It's moveable 514 00:24:32.239 --> 00:24:34.258 It doesn't have characteristics 515 00:24:34.338 --> 00:24:36.909 but an object that can be moved 516 00:24:36.978 --> 00:24:39.859 It will be helpful to read the top explanation 517 00:24:39.859 --> 00:24:43.209 Pawn is the base class of all actors 518 00:24:43.210 --> 00:24:46.460 that can be possessed by players or AI 519 00:24:46.460 --> 00:24:48.648 Players or AI 520 00:24:48.648 --> 00:24:51.379 The players or AI can 521 00:24:51.379 --> 00:24:53.909 possess, but it basically means moveable 522 00:24:54.018 --> 00:24:56.459 The objects that can be possessed and moveable 523 00:24:56.459 --> 00:24:58.619 are made here, is what it's trying to say 524 00:24:58.699 --> 00:25:01.119 So when you take a look at APawn class 525 00:25:01.119 --> 00:25:03.828 there are actions that only Pawns can do 526 00:25:04.339 --> 00:25:06.778 Under that, the purple part 527 00:25:06.778 --> 00:25:08.589 the parts written in purple 528 00:25:08.590 --> 00:25:11.619 are what pre-processors redefined 529 00:25:11.619 --> 00:25:14.099 The purple parts 530 00:25:14.738 --> 00:25:17.699 in C++ or C language itself 531 00:25:17.699 --> 00:25:20.058 is not included 532 00:25:20.058 --> 00:25:21.749 The pre-processor was used 533 00:25:22.019 --> 00:25:24.939 to create the reflection function 534 00:25:24.939 --> 00:25:27.718 that doesn't exist 535 00:25:28.299 --> 00:25:29.858 Later on, when I explain reflection 536 00:25:29.858 --> 00:25:31.649 GenerateBody, UProperty 537 00:25:31.650 --> 00:25:33.650 and UFunction will all be explained 538 00:25:34.619 --> 00:25:38.219 Anyways, that's how APawn hierarchy is made up 539 00:25:38.219 --> 00:25:44.299 For Pawn, GetLifetimeReplicateProperty or PreReplication can be used 540 00:25:44.299 --> 00:25:47.858 Replication literally means that the object can be replicated 541 00:25:47.858 --> 00:25:49.579 It means moving the same way 542 00:25:49.579 --> 00:25:50.979 That's not what I'll explain right now 543 00:25:51.019 --> 00:25:53.358 This Pawn does a certain job 544 00:25:53.619 --> 00:25:56.998 It has the function of being possessed and moved 545 00:25:57.019 --> 00:25:58.598 is what we can know from this 546 00:25:58.738 --> 00:26:01.409 When I moved back to the character, the character 547 00:26:01.738 --> 00:26:03.918 wasn't that different from Pawn 548 00:26:03.919 --> 00:26:06.529 When we move up to Pawn and move up one more step 549 00:26:06.539 --> 00:26:08.299 We come across the Actor 550 00:26:08.299 --> 00:26:10.659 Before I explain the Actor 551 00:26:10.659 --> 00:26:14.109 When you take a look at Class APawn 552 00:26:14.179 --> 00:26:16.739 There's colon and Public AActor 553 00:26:16.739 --> 00:26:19.898 then comma, then Public INavAgentInterface 554 00:26:19.898 --> 00:26:22.058 This is called multiple inheritance 555 00:26:22.058 --> 00:26:24.698 There's more than one parent 556 00:26:24.698 --> 00:26:26.498 It can inherit from multiple 557 00:26:26.659 --> 00:26:30.418 But I won't mention this multiple inheritance for now 558 00:26:30.418 --> 00:26:33.259 So it inherited two things 559 00:26:33.858 --> 00:26:36.058 Interface Navigation Agent Interface 560 00:26:36.058 --> 00:26:37.978 I stands for Interface 561 00:26:37.978 --> 00:26:40.898 Rather than going to INavigationAgentInterface 562 00:26:40.898 --> 00:26:42.898 we'll move up to Actor class 563 00:26:42.898 --> 00:26:45.659 If we go to AActor class again 564 00:26:45.659 --> 00:26:47.819 This becomes the parent of Pawn 565 00:26:47.819 --> 00:26:49.659 It's the parent of Pawn 566 00:26:49.659 --> 00:26:52.379 Same thing, there's the actor for the parent of Pawn 567 00:26:52.379 --> 00:26:55.138 And how this Actor acts 568 00:26:55.138 --> 00:26:57.498 The top part is similar 569 00:26:57.498 --> 00:27:00.258 But there's something called InitializeDefaults 570 00:27:00.258 --> 00:27:01.698 If you look at the explanation 571 00:27:01.698 --> 00:27:04.258 Called from the constructor to initialize the class 572 00:27:04.258 --> 00:27:05.739 to its default setting 573 00:27:05.739 --> 00:27:07.379 Using the default setting 574 00:27:07.379 --> 00:27:10.498 this object 575 00:27:10.498 --> 00:27:13.248 will be initialized 576 00:27:13.248 --> 00:27:16.208 So as you've seen so far 577 00:27:16.258 --> 00:27:18.979 We can move up even more, but up until this hierarchy 578 00:27:19.138 --> 00:27:22.719 Starting from AMyCharacterL 579 00:27:22.719 --> 00:27:25.579 to ACharacter 580 00:27:25.579 --> 00:27:27.258 APawn 581 00:27:27.258 --> 00:27:28.549 AActor 582 00:27:28.579 --> 00:27:31.459 Until then, there are many parent hierarchy 583 00:27:31.459 --> 00:27:33.299 This is called inheritance hierarchy 584 00:27:33.299 --> 00:27:35.978 We divide it into so many hierarchy because 585 00:27:35.978 --> 00:27:38.618 for each hierarchy, for each parent 586 00:27:38.618 --> 00:27:41.299 there are various and complex works that need to be done 587 00:27:41.299 --> 00:27:42.988 That's why it's configured like this 588 00:27:43.099 --> 00:27:45.219 The explanation was long 589 00:27:45.219 --> 00:27:48.118 But we have one or two more steps left 590 00:27:48.138 --> 00:27:52.198 Let's go to UObject, the parent of Actor 591 00:27:52.498 --> 00:27:55.898 UObject is actually the parent 592 00:27:55.898 --> 00:27:58.998 of almost all objects that exist in Unreal 593 00:27:59.179 --> 00:28:02.228 There's one more step, but first for UObject 594 00:28:02.338 --> 00:28:04.418 For UObject 595 00:28:04.539 --> 00:28:06.579 it's also explained on top in English 596 00:28:06.579 --> 00:28:10.659 The Base Class of all UE objects 597 00:28:10.659 --> 00:28:14.018 For all the objects that appear in Unreal Engine 598 00:28:14.018 --> 00:28:14.939 this is the base class 599 00:28:14.939 --> 00:28:17.379 Hence the name, it's the basic class 600 00:28:17.379 --> 00:28:18.859 Of course, there's another parent at the top 601 00:28:18.859 --> 00:28:21.898 But this is the hierarchy for implementing functional aspects 602 00:28:22.219 --> 00:28:25.539 This class, UObject, is actually 603 00:28:25.539 --> 00:28:28.419 very important for Unreal C++ Programming 604 00:28:28.419 --> 00:28:30.379 It's the most basic 605 00:28:30.379 --> 00:28:33.178 It can act most normally 606 00:28:33.178 --> 00:28:35.219 It's the class that you must know 607 00:28:35.219 --> 00:28:37.099 There are lots of grammars 608 00:28:37.099 --> 00:28:39.699 and I can't explain every one of them 609 00:28:39.699 --> 00:28:41.778 as Unreal is the world's most 610 00:28:41.778 --> 00:28:43.618 AAA class engine 611 00:28:43.618 --> 00:28:45.659 The content is very complicated 612 00:28:45.659 --> 00:28:48.778 and the explanation and the implementation are also complicated 613 00:28:48.778 --> 00:28:51.539 But through the Pawn and Actor 614 00:28:51.539 --> 00:28:53.898 moving up the hierarchy 615 00:28:53.898 --> 00:28:56.778 moving up to the UObject 616 00:28:56.778 --> 00:28:59.309 is what's important 617 00:28:59.578 --> 00:29:01.069 Same thing, at the top 618 00:29:01.069 --> 00:29:03.939 There's a slash, not two slashes, but slash asterisk 619 00:29:04.058 --> 00:29:06.578 Starting from slash asterisk 620 00:29:06.859 --> 00:29:09.759 the first four lines are the comment 621 00:29:09.939 --> 00:29:11.458 The comment doesn't get compiled 622 00:29:11.458 --> 00:29:13.998 It's an explanation, so take a look 623 00:29:13.998 --> 00:29:18.298 Same thing for document.unrealengine.com 624 00:29:18.298 --> 00:29:19.699 The explanation in Unreal engine 625 00:29:19.699 --> 00:29:22.298 take a look at that as well 626 00:29:22.298 --> 00:29:24.298 Then the things I've said so far 627 00:29:24.298 --> 00:29:26.778 will be understood in detail 628 00:29:26.778 --> 00:29:29.298 So if you take a look at UObject for a second 629 00:29:29.298 --> 00:29:32.458 There's Virtual Constructor 630 00:29:32.458 --> 00:29:36.458 probably virtual function constructor 631 00:29:36.458 --> 00:29:39.219 will also be callable 632 00:29:39.219 --> 00:29:40.659 Config Name, Static Config Name 633 00:29:40.659 --> 00:29:44.618 We'll be able to name static names as well 634 00:29:44.618 --> 00:29:46.139 The normal things that we can do 635 00:29:46.139 --> 00:29:49.298 The thing that all Unreal objects can do 636 00:29:49.298 --> 00:29:52.519 are what's written here 637 00:29:52.819 --> 00:29:55.338 While we're on it 638 00:29:55.338 --> 00:29:59.018 I said that Unreal Object is the parent 639 00:29:59.018 --> 00:30:01.018 of practically all the objects that appear in Unreal 640 00:30:01.018 --> 00:30:02.618 But let's go to the very top 641 00:30:02.618 --> 00:30:05.778 So Unreal Object is Unreal Object Base Utility 642 00:30:05.778 --> 00:30:07.618 The basic actions 643 00:30:07.618 --> 00:30:11.298 The basic useful utilities are included 644 00:30:11.298 --> 00:30:14.469 And when you take a look, there seems to be functions 645 00:30:14.738 --> 00:30:17.609 As for MarkPendingKill 646 00:30:17.898 --> 00:30:21.099 There's something called Garbage Collecting 647 00:30:21.099 --> 00:30:23.738 where objects need to be removed someday 648 00:30:23.738 --> 00:30:26.178 This is the hierarchy that holds those functions 649 00:30:26.178 --> 00:30:29.819 You can see Clear Garbage or Mark As Garbage Clear Pending 650 00:30:29.819 --> 00:30:33.859 But for this UObjectBaseUtility hierarchy 651 00:30:33.859 --> 00:30:35.939 The object is created and deleted 652 00:30:35.939 --> 00:30:39.379 in this class 653 00:30:39.379 --> 00:30:41.498 Let's move up to UObjectBase 654 00:30:41.498 --> 00:30:44.458 This is the uppermost, without a parent 655 00:30:44.458 --> 00:30:45.898 hierarchy that we're at 656 00:30:45.900 --> 00:30:52.300 UObject was called BaseOfU earlier because 657 00:30:52.300 --> 00:30:55.200 when it operates 658 00:30:55.201 --> 00:30:57.801 conceptually, the parent is UObject 659 00:30:58.100 --> 00:31:01.300 But UObject can't be made at once as well 660 00:31:01.300 --> 00:31:04.000 So for UObject, in Unreal 661 00:31:04.001 --> 00:31:07.301 It needs a lot of functions as the parent of all objects 662 00:31:07.301 --> 00:31:11.100 That's why there are two more hierarchy above it 663 00:31:11.100 --> 00:31:14.600 Then at the very top 664 00:31:14.600 --> 00:31:17.200 That's why the name is UObjectBase 665 00:31:17.200 --> 00:31:19.750 When making Unreal object 666 00:31:19.751 --> 00:31:24.251 this is the basic class 667 00:31:24.500 --> 00:31:27.599 In the comment, it says Low Level Implementation of UObject 668 00:31:27.599 --> 00:31:31.099 Literally translates to its meaning 669 00:31:31.099 --> 00:31:34.500 So it means making the most basic, at the low level 670 00:31:34.500 --> 00:31:36.599 Should not be used directly in game code 671 00:31:36.599 --> 00:31:39.299 So we can't use this right away in game code 672 00:31:39.299 --> 00:31:42.500 There's a keyword called Friend, and to explain this briefly 673 00:31:42.500 --> 00:31:47.100 This means that rather than going to other class or qualifier 674 00:31:47.101 --> 00:31:48.900 we can use it right away 675 00:31:48.900 --> 00:31:53.200 Normally, to keep all Private Projected and Public 676 00:31:53.400 --> 00:31:56.900 they have to pass through all capsulation 677 00:31:56.900 --> 00:31:59.800 But without those, they can access each other 678 00:31:59.900 --> 00:32:04.150 So they set that as Friend class or Friend Struct 679 00:32:04.199 --> 00:32:08.649 Here as well, there's the basic form of constructor 680 00:32:08.649 --> 00:32:12.599 And the name, the package name 681 00:32:12.599 --> 00:32:15.000 It says super class, static class 682 00:32:15.000 --> 00:32:18.300 So the name and where it belongs to 683 00:32:18.400 --> 00:32:21.500 Only those basic things 684 00:32:21.501 --> 00:32:23.051 are included here 685 00:32:23.400 --> 00:32:25.801 So to recall 686 00:32:25.801 --> 00:32:28.099 Using the source code 687 00:32:28.099 --> 00:32:29.600 in the example of lecture 1 688 00:32:29.601 --> 00:32:32.501 The character class, MyCharacter class that we made 689 00:32:32.800 --> 00:32:37.700 We went through each hierarchy using the source code 690 00:32:37.700 --> 00:32:40.500 Starting from Begin, Play, Tick, the overridden parts 691 00:32:40.699 --> 00:32:44.800 then up to the middle hierarchy, Garbage Collecting, and handling objects 692 00:32:44.800 --> 00:32:47.500 Then up to the Actor 693 00:32:47.500 --> 00:32:50.400 And the Unreal Object, the parent of all, and UObject, the base of all 694 00:32:50.400 --> 00:32:53.050 In order to implement the UObject 695 00:32:53.051 --> 00:32:55.301 we also took a look at the two class hierarchies 696 00:32:55.600 --> 00:32:59.800 Even the programmers who can handle C++ well 697 00:32:59.800 --> 00:33:04.899 have a hard time looking at the Unreal class hierarchy 698 00:33:04.899 --> 00:33:09.249 So when you have just learned C++ 699 00:33:09.250 --> 00:33:11.700 it may be difficult to read these codes 700 00:33:11.700 --> 00:33:14.000 But when you do Unreal programming 701 00:33:14.000 --> 00:33:19.000 you'll see them often, so I skimmed through them 702 00:33:19.000 --> 00:33:21.800 The UProperty and UFunction I mentioned earlier 703 00:33:21.800 --> 00:33:25.650 I'll explain about the reflection system of Unreal 704 00:33:25.699 --> 00:33:30.699 Actually, this isn't the details of C++ 705 00:33:30.800 --> 00:33:32.950 It's not the C++ Specification 706 00:33:32.951 --> 00:33:34.801 And it's not implemented in C++ 707 00:33:34.801 --> 00:33:38.700 It's not implemented in C++ language 708 00:33:38.701 --> 00:33:41.251 so Unreal made this system 709 00:33:41.399 --> 00:33:43.900 To explain this briefly 710 00:33:43.900 --> 00:33:47.500 When there's a syntax that says int a = 3 711 00:33:47.699 --> 00:33:50.049 In variable a 712 00:33:50.050 --> 00:33:52.750 3 can be included or used 713 00:33:52.750 --> 00:33:56.000 But we don't know that the name of the variable is a 714 00:33:56.000 --> 00:33:58.850 When the program is executed 715 00:33:58.850 --> 00:34:02.100 we can't know the name of the variable and the class 716 00:34:02.199 --> 00:34:07.249 Even in the current C++2023 717 00:34:07.249 --> 00:34:09.899 That's the newest version 718 00:34:09.899 --> 00:34:12.550 Even in the C++ released in 2023 719 00:34:12.550 --> 00:34:14.749 The name of the variable or the name of the class 720 00:34:14.750 --> 00:34:16.650 cannot be brought as text 721 00:34:16.650 --> 00:34:20.899 So using the existing grammar, we need to implement it somehow 722 00:34:20.899 --> 00:34:22.699 To see what class I made 723 00:34:22.699 --> 00:34:25.899 And what variables and functions are there 724 00:34:25.899 --> 00:34:27.300 From outside the program 725 00:34:27.301 --> 00:34:29.851 Being able to see those outside the source code 726 00:34:29.851 --> 00:34:31.800 is called the Reflection system 727 00:34:31.800 --> 00:34:35.050 In order to implement the Unreal's Reflection system 728 00:34:35.050 --> 00:34:37.199 If you look at Unreal engine 729 00:34:37.199 --> 00:34:38.500 When you click on Actor 730 00:34:38.501 --> 00:34:42.301 You can see the inner properties of Actor 731 00:34:42.301 --> 00:34:44.100 Those are possible because 732 00:34:44.100 --> 00:34:47.650 And we can call a function of an Actor 733 00:34:47.650 --> 00:34:49.499 We can call it from the server 734 00:34:49.500 --> 00:34:53.550 And other clients can call as well because 735 00:34:53.550 --> 00:34:57.700 This Reflection function that works with UProperty and UFunction 736 00:34:57.700 --> 00:34:59.800 is coming into play 737 00:34:59.800 --> 00:35:02.099 I skipped in the middle 738 00:35:02.099 --> 00:35:03.800 but to summarize it 739 00:35:03.800 --> 00:35:07.099 Many implementations are skipped, actually 740 00:35:07.099 --> 00:35:09.700 UProperty is placed in front of the member variable 741 00:35:09.799 --> 00:35:13.800 If we put UProperty Define before the variable 742 00:35:13.800 --> 00:35:15.299 The pre-processor 743 00:35:15.299 --> 00:35:19.399 Then that means that this variable will be used in the Reflection system 744 00:35:19.399 --> 00:35:22.200 Same thing for UFunction, it's used in member function 745 00:35:22.200 --> 00:35:25.500 Existing in C++ as well 746 00:35:25.500 --> 00:35:27.600 UClass, UEnumerate 747 00:35:27.600 --> 00:35:30.899 I didn't explain Enumerate, but 748 00:35:30.899 --> 00:35:34.100 it's a countable form 749 00:35:34.100 --> 00:35:35.899 It's put as a special reason 750 00:35:35.899 --> 00:35:38.899 There's a keyword called UStruct 751 00:35:38.899 --> 00:35:41.799 As I explained, since it doesn't have the Reflection function 752 00:35:41.799 --> 00:35:46.100 When we make one C++ file in Unreal 753 00:35:46.100 --> 00:35:48.000 when we make the class 754 00:35:48.000 --> 00:35:52.000 For example, after ACharacterL 755 00:35:52.000 --> 00:35:55.899 Generated.h file is formed automatically 756 00:35:55.899 --> 00:36:00.500 And this becomes included in Generated Body 757 00:36:00.700 --> 00:36:03.700 Unreal's Reflection system is 758 00:36:03.700 --> 00:36:10.100 not something we can talk about within 5 or 10 minutes 759 00:36:10.100 --> 00:36:12.500 It's made very complex 760 00:36:12.500 --> 00:36:13.799 But when we actually use it 761 00:36:13.799 --> 00:36:17.300 You just need to see that UProperty and UFunction are together 762 00:36:17.300 --> 00:36:19.300 So within the source code that I showed you earlier 763 00:36:19.300 --> 00:36:22.000 Go to AMyCharacterL 764 00:36:22.000 --> 00:36:23.849 and look at the GenerateBody 765 00:36:23.849 --> 00:36:26.399 or the UProperty above it 766 00:36:26.700 --> 00:36:30.650 Finally, I'll show you the life cycle of an Actor 767 00:36:30.700 --> 00:36:33.050 The purpose of my lecture is 768 00:36:33.299 --> 00:36:37.150 being able to do Unreal Programming using C++ 769 00:36:37.151 --> 00:36:40.201 That's the step I wanted to reach 770 00:36:40.399 --> 00:36:42.450 So opening Unreal 771 00:36:42.500 --> 00:36:46.150 and changing and moving the actor 772 00:36:46.151 --> 00:36:47.651 won't be done 773 00:36:47.700 --> 00:36:50.599 But for Actor, Pawn, or Character 774 00:36:50.700 --> 00:36:52.000 when you do Unreal programming 775 00:36:52.001 --> 00:36:54.551 They're the very first object that you encounter 776 00:36:54.600 --> 00:36:57.750 So we'll take a look at the Actor's life cycle 777 00:36:57.750 --> 00:37:02.000 Click the Unreal Documentation Actors Life Cycle link 778 00:37:02.000 --> 00:37:04.000 And this screen appears 779 00:37:04.000 --> 00:37:06.750 There's a simple Breakdown 780 00:37:06.750 --> 00:37:11.399 This shows what happens when the Unreal Actor is formed 781 00:37:11.399 --> 00:37:14.100 You'll see this later 782 00:37:14.100 --> 00:37:18.700 For Actor, there are 3 main ways 783 00:37:18.700 --> 00:37:21.051 of how the life cycle works 784 00:37:21.051 --> 00:37:23.050 When it's executed in Editor 785 00:37:23.051 --> 00:37:25.701 or when it's loaded from data 786 00:37:25.701 --> 00:37:28.600 and third is when it's created dynamically 787 00:37:28.600 --> 00:37:30.999 The yellow on the left 788 00:37:31.000 --> 00:37:33.400 says Play in Editor 789 00:37:33.400 --> 00:37:36.950 What happens when the player button is pressed in Editor 790 00:37:36.950 --> 00:37:41.150 It means copying it from Editor and running it in engine 791 00:37:41.150 --> 00:37:44.450 For the second, there's a level, and the map is loaded on the level 792 00:37:44.450 --> 00:37:46.350 or when it's added in the world 793 00:37:46.399 --> 00:37:49.999 The actor is formed by bringing it from the disk 794 00:37:50.000 --> 00:37:52.300 On the right, it starts from nothing 795 00:37:52.301 --> 00:37:54.351 When an action actually happens 796 00:37:54.351 --> 00:37:56.950 For example pressing a key or colliding 797 00:37:56.950 --> 00:38:00.000 The Spawn, or Actor is dynamically created 798 00:38:00.000 --> 00:38:01.799 The Spawn Actor is created right away 799 00:38:01.799 --> 00:38:06.750 And Spawn Actor Deferred is the delayed spawn 800 00:38:06.750 --> 00:38:10.500 So it's created dynamically and about what happens next 801 00:38:10.500 --> 00:38:13.650 It's a step process 802 00:38:13.650 --> 00:38:16.350 If you look at the bottom 803 00:38:16.351 --> 00:38:17.801 It's created 804 00:38:17.801 --> 00:38:22.750 It begins play through Begin Play 805 00:38:22.750 --> 00:38:26.300 In the middle, where it says The application is running and the actor is ticking 806 00:38:26.300 --> 00:38:28.300 This is where the game is actually running 807 00:38:28.300 --> 00:38:30.200 The green part in the middle 808 00:38:30.200 --> 00:38:35.600 The game ultimately goes around a tick 809 00:38:35.600 --> 00:38:37.299 It's an infinite loop 810 00:38:37.299 --> 00:38:40.499 So it goes around the loop infinitely and runs the game 811 00:38:40.500 --> 00:38:43.799 Based on the 6 conditions on the bottom 812 00:38:43.799 --> 00:38:47.299 When it ends, go to End Play 813 00:38:47.500 --> 00:38:49.900 and it reaches the step of deleting the object 814 00:38:49.900 --> 00:38:51.600 So for Actor mark, as I explained earlier 815 00:38:51.600 --> 00:38:54.849 does Garbage Collecting and Pending Kill 816 00:38:54.849 --> 00:38:56.450 and once everything is over 817 00:38:56.451 --> 00:38:58.251 After the post processing 818 00:38:58.251 --> 00:39:01.849 BeginDestroy, IsReadyforFinishDestroy, then FinishDestroy 819 00:39:01.849 --> 00:39:05.000 It ends by destroying the object 820 00:39:05.000 --> 00:39:09.799 You're going to go through these kinds of programming 821 00:39:09.799 --> 00:39:15.500 And I hope the C++ programming basics today was helpful 822 00:39:15.500 --> 00:39:18.799 And same thing for MSDN, Microsoft Development Network, but 823 00:39:18.799 --> 00:39:21.299 when you study Unreal 824 00:39:21.299 --> 00:39:23.900 The Epic Games that made Unreal 825 00:39:23.900 --> 00:39:26.450 Their Documentation page will be the most helpful 826 00:39:26.450 --> 00:39:29.099 I'll end the lecture here, thank you 827 00:39:29.100 --> 00:39:30.350 Understanding inheritance, polymorphism, and template Inheritance Inherit the parent object for the common parts, can use the data and functions of the parent 828 00:39:30.350 --> 00:39:31.551 Need inheritance to reuse the repeated parts Redefining function is needed to implement the inheritance hierarchy 829 00:39:31.551 --> 00:39:33.002 Polymorphism Executing different actions with the same commands, based on different object Subtype polymorphism: applied on daughter type that comes from the parent type 830 00:39:33.002 --> 00:39:34.553 Compile-Time Polymorphism: uses template 831 00:39:34.553 --> 00:39:35.804 Template Name of the C++ normalization programming Essential grammar template for using template 〈typename T〉 832 00:39:35.804 --> 00:39:37.454 C++ Unreal Engine Structure Unreal C++ Inheritance Hierarchy 833 00:39:37.455 --> 00:39:39.105 AMyCharacterL 〈 ACharacter 〈 APawn 〈 AActor 〈 UObject 〈 UObjectBaseUtility 〈 UObjectBase 834 00:39:39.105 --> 00:39:40.906 Unreal's Reflection System Made by Unreal because there's no reflection function in C++ Can view the variables and functions within the class from outside the source code 835 00:39:40.906 --> 00:39:42.657 Can call over the properties or functions of an Actor UPROPERTY in front of member variable UFUNCTION in front of member function 836 00:39:42.657 --> 00:39:43.657 The End