WEBVTT 1 00:00:23.850 --> 00:00:26.350 Hello, this is Younghoon Lee 2 00:00:26.351 --> 00:00:31.200 Today we will be working on collisions and the game over function 3 00:00:31.200 --> 00:00:35.000 In this chapter, we wil learn about how to set the channel for collisions 4 00:00:35.001 --> 00:00:40.550 And how to process at C++ using this method 5 00:00:40.550 --> 00:00:43.920 And we will also learn about how to 6 00:00:43.921 --> 00:00:47.521 Make the collision between Player and enemy into the game over state 7 00:00:48.322 --> 00:00:51.139 Processing Collisions 8 00:00:51.920 --> 00:00:55.630 Unreal Engine has Physics, a physics engine 9 00:00:55.630 --> 00:00:58.730 With which we can process collisions 10 00:00:58.780 --> 00:01:00.700 In order to process collisions 11 00:01:00.701 --> 00:01:03.651 We need to start with some prerequesitory things 12 00:01:03.651 --> 00:01:05.350 First is the concept of channels 13 00:01:05.351 --> 00:01:07.167 Go to Edit 14 00:01:07.167 --> 00:01:09.550 Project Settings 15 00:01:09.550 --> 00:01:12.250 And at Collision, we see these 16 00:01:12.251 --> 00:01:15.151 Object and Trace channels 17 00:01:15.151 --> 00:01:16.800 Object Channels is where 18 00:01:16.801 --> 00:01:20.501 They process physical collisions 19 00:01:20.501 --> 00:01:23.600 While Trace is where they process 20 00:01:23.601 --> 00:01:25.901 Things such as the gaze direction 21 00:01:25.901 --> 00:01:29.051 Today, we will be using Object Channels 22 00:01:29.051 --> 00:01:31.000 In processing collisions 23 00:01:31.000 --> 00:01:33.050 The first objects that appear 24 00:01:33.051 --> 00:01:37.601 We have Player, Bullet and Enemy 25 00:01:37.601 --> 00:01:39.550 So using that 26 00:01:39.551 --> 00:01:40.951 Let's reconfigure this 27 00:01:40.952 --> 00:01:42.452 So first is Player 28 00:01:42.452 --> 00:01:44.600 And it says Default Response 29 00:01:44.601 --> 00:01:48.001 Which asks for default settings for 30 00:01:48.002 --> 00:01:51.000 The Player channel with existing channels 31 00:01:51.000 --> 00:01:54.550 Let's say Overlap here 32 00:01:56.050 --> 00:01:58.350 And we have Bullet 33 00:01:58.350 --> 00:02:00.000 Bullet 34 00:02:00.150 --> 00:02:04.000 We also need Overlap here 35 00:02:04.200 --> 00:02:09.000 And finally, let's say Enemy here 36 00:02:09.600 --> 00:02:12.400 And now we need detailed setups for this 37 00:02:12.400 --> 00:02:15.350 Let's start with Enemy 38 00:02:15.351 --> 00:02:17.202 Here, what we will try is 39 00:02:17.202 --> 00:02:19.350 Let me explain more about this later 40 00:02:19.350 --> 00:02:22.400 Let's visualize what we are going to do 41 00:02:22.400 --> 00:02:24.000 So we have Enemy 42 00:02:24.850 --> 00:02:28.000 And Player and Bullet 43 00:02:28.700 --> 00:02:32.000 So Enemy checks for Player 44 00:02:32.300 --> 00:02:35.000 And Bullet checks for Enemy 45 00:02:35.450 --> 00:02:38.450 That's the collision check that happens 46 00:02:39.000 --> 00:02:42.000 So first, let's start with Enemy 47 00:02:42.000 --> 00:02:44.550 At Enemy, this is what it looks like 48 00:02:44.550 --> 00:02:49.800 We first need to se this Box Component 49 00:02:49.800 --> 00:02:52.300 Over here, like so 50 00:02:52.301 --> 00:02:55.201 It says OverlapAllDynamic 51 00:02:55.201 --> 00:02:58.000 Let's put it to Custom 52 00:02:58.000 --> 00:03:02.000 So here, what corresponds to Collision Channel 53 00:03:02.000 --> 00:03:05.550 What corresponds to Object Channel is Object Type 54 00:03:05.550 --> 00:03:08.400 So open it here, and it says this here 55 00:03:08.400 --> 00:03:10.150 Let's start with Enemy 56 00:03:10.150 --> 00:03:13.700 And then it says Collision Enabled 57 00:03:13.700 --> 00:03:16.350 And there are two in general 58 00:03:16.350 --> 00:03:19.000 It has Query and Physics 59 00:03:19.000 --> 00:03:23.000 Query is what overlaps, it simple detects 60 00:03:23.000 --> 00:03:25.000 So it won't push things around 61 00:03:25.000 --> 00:03:27.550 It just detects the overlap 62 00:03:27.550 --> 00:03:29.650 And Physics is something physical 63 00:03:29.651 --> 00:03:32.301 It collides into something and pushes it away 64 00:03:32.301 --> 00:03:34.550 Let's check for the two here 65 00:03:34.550 --> 00:03:37.700 Let's set it up so that it detects both Query and Physics 66 00:03:37.700 --> 00:03:40.701 And for Enemy, like so 67 00:03:40.701 --> 00:03:42.351 The actual collision will happen 68 00:03:42.351 --> 00:03:46.000 Between Enemy with Player and Bullet 69 00:03:46.000 --> 00:03:49.000 Here, I won't use Block and only use Overlap 70 00:03:49.000 --> 00:03:52.000 Let me explain a bit more about this situation 71 00:03:52.000 --> 00:03:55.000 As you just saw, here's the diagram 72 00:03:55.000 --> 00:03:58.500 When we say there are two objects like so 73 00:03:58.500 --> 00:04:01.850 We can set for their collision settings 74 00:04:01.850 --> 00:04:04.050 For example, Object B 75 00:04:04.051 --> 00:04:07.401 With Object A, it will be Ignore 76 00:04:07.401 --> 00:04:10.000 So let's write this out here 77 00:04:10.150 --> 00:04:12.550 When we have A and B 78 00:04:12.550 --> 00:04:17.000 At A, it will Ignore B 79 00:04:17.100 --> 00:04:20.100 And then at B, it will Block A 80 00:04:20.100 --> 00:04:22.000 Let's say that this is the setup 81 00:04:22.000 --> 00:04:24.350 Then what happens in the end is 82 00:04:24.350 --> 00:04:25.800 Ignore is what happens 83 00:04:25.800 --> 00:04:28.000 And here at the diagram 84 00:04:28.000 --> 00:04:30.000 Here, let's take it as it is 85 00:04:30.000 --> 00:04:33.700 A is Ignore, and B is Block 86 00:04:33.700 --> 00:04:36.550 But the result for that is Ignore 87 00:04:36.550 --> 00:04:39.100 That's how Ignore and Block work 88 00:04:39.100 --> 00:04:41.200 So Ignore literally ignores 89 00:04:41.200 --> 00:04:42.150 So Overlap isn't a physical collision 90 00:04:42.150 --> 00:04:45.050 While this is an actual physical collision 91 00:04:45.050 --> 00:04:48.200 And the priority goes like this 92 00:04:48.200 --> 00:04:49.300 Ignore is at the top 93 00:04:49.300 --> 00:04:53.000 So if either of the two is Ignore, it becomes Ignore 94 00:04:53.000 --> 00:04:56.100 And if it is Overlap and Block 95 00:04:56.100 --> 00:04:58.550 It will end up being Overlap 96 00:04:58.550 --> 00:05:01.050 So we can set all these here 97 00:05:01.050 --> 00:05:06.900 And let's set it up for Player as well 98 00:05:06.900 --> 00:05:09.800 Select Box Component 99 00:05:10.050 --> 00:05:12.550 Come over here for customization 100 00:05:13.100 --> 00:05:14.800 Let's say Ignore for all 101 00:05:14.800 --> 00:05:16.800 And then for our Player 102 00:05:16.800 --> 00:05:18.850 Let's set it up like this 103 00:05:18.850 --> 00:05:23.400 Player will only Ovlerap with Enemy 104 00:05:24.200 --> 00:05:27.000 That's how we can set this up 105 00:05:27.600 --> 00:05:29.150 And we have Bullet as well 106 00:05:29.150 --> 00:05:33.000 For Bullet, select Box Component 107 00:05:33.000 --> 00:05:35.000 And customize Bullet as well 108 00:05:35.000 --> 00:05:37.000 And then, Ignore here and 109 00:05:37.000 --> 00:05:40.000 For Bullet, let's say it only Overlaps with Enemy 110 00:05:40.000 --> 00:05:44.600 Then Enemy overlaps with Bullet 111 00:05:44.600 --> 00:05:47.200 And Bullet overlaps with Enemy 112 00:05:47.200 --> 00:05:49.650 So it is Overlap for both 113 00:05:49.650 --> 00:05:52.150 That's how we set this up 114 00:05:52.150 --> 00:05:56.000 Let's save everything here as well 115 00:05:56.300 --> 00:05:58.600 And then 116 00:05:58.600 --> 00:05:59.650 Let's try colliding into them 117 00:05:59.650 --> 00:06:02.300 And we can't really see if it is happening 118 00:06:02.300 --> 00:06:05.850 So in order to process this 119 00:06:07.000 --> 00:06:11.000 Let's come over to Enemy and do that actuall collision 120 00:06:11.000 --> 00:06:14.000 We can first check for it at Blueprint 121 00:06:14.000 --> 00:06:17.000 So at Enemy 122 00:06:17.000 --> 00:06:20.000 We had this ActorBeginOverlap here 123 00:06:20.250 --> 00:06:25.000 This detects any collision between actors 124 00:06:25.000 --> 00:06:27.350 And it has no detailed content to it 125 00:06:27.350 --> 00:06:31.100 And we have a scenario we want 126 00:06:31.100 --> 00:06:33.100 Let me visualize it here 127 00:06:33.100 --> 00:06:35.000 For example 128 00:06:35.000 --> 00:06:39.050 Let's say there is some boss, like a golem 129 00:06:41.550 --> 00:06:43.550 And let's say we want to shoot here 130 00:06:43.550 --> 00:06:45.250 And smash its arm 131 00:06:45.250 --> 00:06:47.800 Or let's say we want to shoot its head 132 00:06:47.800 --> 00:06:50.550 Or some parts and destroy it 133 00:06:50.550 --> 00:06:52.400 For this to be implemented 134 00:06:52.400 --> 00:06:55.900 It is hard to realize this 135 00:06:55.900 --> 00:06:58.550 Only using our ActorBeginOverlap here 136 00:06:58.550 --> 00:07:00.550 It is very hard to detect where 137 00:07:00.551 --> 00:07:03.201 The 'where' of the hit 138 00:07:03.201 --> 00:07:05.650 We can't really use coordinate calculation for this 139 00:07:05.650 --> 00:07:08.050 So instead, we could 140 00:07:08.050 --> 00:07:09.600 At this component 141 00:07:09.600 --> 00:07:10.850 This collider 142 00:07:10.850 --> 00:07:13.100 Get to the bottom of the collider 143 00:07:13.100 --> 00:07:17.000 And here is a function that detects 144 00:07:17.000 --> 00:07:20.000 Whether that collider has been collided 145 00:07:20.100 --> 00:07:23.000 So using this 146 00:07:23.100 --> 00:07:26.600 We can use collision detection for each collider 147 00:07:26.600 --> 00:07:29.400 So at C++ 148 00:07:29.400 --> 00:07:32.600 We can demonstrate for these two 149 00:07:32.600 --> 00:07:34.400 So at its code 150 00:07:34.400 --> 00:07:36.000 Let's go to Header first 151 00:07:36.000 --> 00:07:38.700 Starting with Enemy 152 00:07:38.700 --> 00:07:41.300 Let's say this below Tick 153 00:07:41.300 --> 00:07:50.200 Virtual Void NotifyBeginOverlap 154 00:07:50.200 --> 00:07:52.000 There's that 155 00:07:52.350 --> 00:07:55.500 And Actor's OtherActor, like so 156 00:07:55.500 --> 00:07:57.700 We have a parameter like so as well 157 00:07:57.700 --> 00:08:01.050 This function is same as the node we saw 158 00:08:01.050 --> 00:08:05.250 At Blueprint in serving the same role 159 00:08:05.250 --> 00:08:08.100 So let's implement this 160 00:08:08.100 --> 00:08:10.000 And then over at this side 161 00:08:10.000 --> 00:08:11.600 Let's print the log 162 00:08:11.600 --> 00:08:13.000 At Unreal, to print log 163 00:08:13.000 --> 00:08:18.950 We can use the macro 'UE_LOG()' 164 00:08:20.250 --> 00:08:24.100 So write 'LogTemp' 165 00:08:24.100 --> 00:08:26.200 And then 'Warning' 166 00:08:26.200 --> 00:08:28.400 And this Warning is printed in yellow 167 00:08:28.400 --> 00:08:30.200 Which is very visible, so let's say Warning 168 00:08:30.200 --> 00:08:31.900 Let's say Text 169 00:08:31.900 --> 00:08:34.850 And let's just print something for the sake of it 170 00:08:36.000 --> 00:08:39.800 Let's print this text over here 171 00:08:43.000 --> 00:08:45.300 So that's how we code it 172 00:08:45.300 --> 00:08:49.650 Over at Unreal, let's compile 173 00:08:55.500 --> 00:09:00.000 So run it and collide into it 174 00:09:00.500 --> 00:09:03.000 And let's see if it prints the log 175 00:09:03.300 --> 00:09:06.100 So here we see how this log is being printed 176 00:09:06.100 --> 00:09:11.100 Let's take a look at it with this fixed 177 00:09:11.100 --> 00:09:13.450 Again 178 00:09:15.200 --> 00:09:17.100 So, when we collide into it 179 00:09:17.100 --> 00:09:20.600 We see how it prints the log 180 00:09:21.800 --> 00:09:25.100 So, we could use this function but 181 00:09:25.100 --> 00:09:27.000 As I mentioned before 182 00:09:27.000 --> 00:09:30.200 Let's try collision per parts 183 00:09:30.200 --> 00:09:33.400 So let's make this log a comment 184 00:09:33.400 --> 00:09:35.400 And again 185 00:09:36.700 --> 00:09:39.000 Over here at Header again 186 00:09:39.000 --> 00:09:45.250 The component that processes collision here is 187 00:09:45.250 --> 00:09:47.100 Our Box Component 188 00:09:47.100 --> 00:09:51.400 So whenever Box Component experiences any physical collision 189 00:09:51.400 --> 00:09:55.350 We can create a function so that this gets recorded 190 00:09:55.350 --> 00:09:59.050 And it will let us know in case of any collision 191 00:09:59.050 --> 00:10:02.000 That's how we can process collisions 192 00:10:02.650 --> 00:10:06.700 So back to our Enemy actor's BeginPlay 193 00:10:06.700 --> 00:10:08.400 Its BeginPlay is pretty long 194 00:10:08.400 --> 00:10:11.000 Let's write it out at the bottom 195 00:10:11.650 --> 00:10:15.000 Let's start at the very bottom of our BeginPlay 196 00:10:15.800 --> 00:10:22.071 At Box Component 197 00:10:22.071 --> 00:10:25.521 Whenever there is a collision 198 00:10:25.522 --> 00:10:29.622 We'd like to know, right? 199 00:10:32.120 --> 00:10:35.679 So let's say, BoxComp 200 00:10:35.680 --> 00:10:38.730 And then, what we want here is 201 00:10:38.731 --> 00:10:41.481 Looking at the list of its property and function 202 00:10:41.482 --> 00:10:47.732 We have a function called OnComponentBeginOverLap 203 00:10:48.482 --> 00:10:50.549 Over here 204 00:10:50.550 --> 00:10:51.800 So that's how it looks like 205 00:10:51.801 --> 00:10:54.001 In fact, it's less of a function 206 00:10:54.001 --> 00:10:56.319 Than it is a delegate 207 00:10:56.320 --> 00:10:59.870 So a delegate looks like this, when we follow it along like so 208 00:11:00.671 --> 00:11:04.256 So it says FComponentEndOverLapSignature 209 00:11:04.256 --> 00:11:05.809 And if we enter there 210 00:11:05.810 --> 00:11:08.710 It says Declare Dynamic Multicast 211 00:11:08.710 --> 00:11:10.460 So it says it is a delegate 212 00:11:10.460 --> 00:11:14.010 It says it is a delegate with six parameters 213 00:11:14.010 --> 00:11:18.780 So we can shape this into a function 214 00:11:18.781 --> 00:11:21.581 And add this function 215 00:11:21.581 --> 00:11:23.689 So it says six, over here 216 00:11:23.690 --> 00:11:28.890 Parameter, its variable name 217 00:11:28.891 --> 00:11:31.391 This is a pair for each 218 00:11:31.391 --> 00:11:34.540 So let's count it using the commas 219 00:11:34.541 --> 00:11:38.391 One, two, three, four, five, six, and that means it's twelve 220 00:11:39.040 --> 00:11:41.369 So it ends over here 221 00:11:42.220 --> 00:11:46.720 So let's copy all the way from here to there 222 00:11:47.519 --> 00:11:50.239 And then, let's come back over here 223 00:11:50.240 --> 00:11:51.940 Back at Header 224 00:11:51.941 --> 00:11:55.691 We will create a function we'll add 225 00:11:56.241 --> 00:11:59.090 Let's add it right at the bottom 226 00:11:59.091 --> 00:12:02.641 And the function we'd like to use added as delegate 227 00:12:02.642 --> 00:12:05.092 Needs a macro called UFUNCTION 228 00:12:05.092 --> 00:12:08.769 So write out UFUNCTION over here 229 00:12:09.370 --> 00:12:11.870 And for this void 230 00:12:11.871 --> 00:12:15.171 This is BeginOverlap of our Box Component 231 00:12:15.969 --> 00:12:24.160 So let's write out onBoxCompBeginOverlap 232 00:12:24.160 --> 00:12:28.250 And the one we brought in, 233 00:12:28.251 --> 00:12:30.800 Let's paste the one we copied 234 00:12:30.800 --> 00:12:33.309 And it should end with a semicolon 235 00:12:33.310 --> 00:12:35.160 And then here 236 00:12:35.161 --> 00:12:40.661 We can delete the comma to the right of our data type 237 00:12:49.959 --> 00:12:52.290 So that's how we can shape it 238 00:12:52.291 --> 00:12:55.391 Let's implement it, we can work with the implementation like so 239 00:12:55.391 --> 00:12:57.811 And let's see if it prints out well 240 00:12:57.811 --> 00:13:00.261 Let's also print this part as a log 241 00:13:01.160 --> 00:13:02.549 Like so, and 242 00:13:02.550 --> 00:13:05.250 Now we need to add this function 243 00:13:05.251 --> 00:13:07.301 In order to add the function 244 00:13:07.301 --> 00:13:11.389 Let's add it at BeginPlay 245 00:13:12.460 --> 00:13:14.350 The one we didn't finish, right? 246 00:13:14.801 --> 00:13:17.601 We will add it over here 247 00:13:17.752 --> 00:13:19.103 So add a dot here 248 00:13:19.103 --> 00:13:22.953 And wirte out 'addDynamic' 249 00:13:22.953 --> 00:13:25.600 And then here, the parenthesis 250 00:13:25.601 --> 00:13:29.601 This, and ampersand, and the address to that function 251 00:13:30.002 --> 00:13:31.652 That's how we add it like so 252 00:13:31.800 --> 00:13:34.030 Then, whenever there is a collision 253 00:13:34.030 --> 00:13:36.280 It will call this function 254 00:13:36.479 --> 00:13:41.029 So, after we've written out everything 255 00:13:41.030 --> 00:13:42.880 Let's compile first 256 00:13:42.881 --> 00:13:44.431 It may or may not work 257 00:13:44.432 --> 00:13:46.632 If it doesn't work, you can simply restart 258 00:13:46.632 --> 00:13:51.240 Restart, edit it once again 259 00:14:04.000 --> 00:14:09.250 And let's see, we know that the event is alright 260 00:14:10.440 --> 00:14:16.040 And then, remember the one we wrote out here? 261 00:14:16.290 --> 00:14:18.510 Starting with Enemy 262 00:14:19.511 --> 00:14:22.561 We set things up at Box Component like so 263 00:14:22.960 --> 00:14:26.880 Let's try writing this part out at our code 264 00:14:26.880 --> 00:14:31.420 So over at Enemy, let's go to our Enemy constructor 265 00:14:32.320 --> 00:14:34.900 So we'll be writing over here 266 00:14:35.679 --> 00:14:37.299 And what we want to do here is 267 00:14:37.300 --> 00:14:39.500 First, for Mesh Component 268 00:14:41.480 --> 00:14:44.509 We'd like to disable the collider 269 00:14:44.510 --> 00:14:49.560 Meaning, we'd like to make the collider 'off' 270 00:14:50.010 --> 00:14:54.559 And at Box Component 271 00:14:54.809 --> 00:14:58.959 We'd like to add 272 00:15:00.630 --> 00:15:02.981 The collision settings 273 00:15:02.981 --> 00:15:03.982 Let's work on each 274 00:15:03.982 --> 00:15:07.532 Let's try our MeshComp 275 00:15:10.559 --> 00:15:15.359 At set Collision, we have things like Enable 276 00:15:15.359 --> 00:15:18.829 At Set Collision, we have a few like so 277 00:15:18.830 --> 00:15:22.080 And here, Enable is for on/off 278 00:15:23.079 --> 00:15:26.829 Over here at the top, we have No Collision 279 00:15:26.830 --> 00:15:30.580 Meaning, its collision won't be processed 280 00:15:30.580 --> 00:15:33.799 We can set it up separately like so 281 00:15:33.799 --> 00:15:36.449 And let's look at our Box Component 282 00:15:37.350 --> 00:15:40.550 Let's work on one by one, over here 283 00:15:40.550 --> 00:15:43.130 We have Generate Overlap Event 284 00:15:43.131 --> 00:15:45.081 This should be enabled 285 00:15:45.082 --> 00:15:47.882 In order to detect collision 286 00:15:47.980 --> 00:15:49.940 So this needs to be on 287 00:15:49.941 --> 00:15:54.341 So let's call the function SetGenerateOverLapEvents 288 00:15:54.640 --> 00:15:58.349 SetGenerateOverlapEvents 289 00:15:58.350 --> 00:16:02.300 And first let's set this as 'true' 290 00:16:03.160 --> 00:16:06.870 And then we'll set up our collision 291 00:16:08.171 --> 00:16:11.871 Let's do the same thing as we've done for Set Collision 292 00:16:11.871 --> 00:16:13.720 Enabled 293 00:16:13.721 --> 00:16:16.821 And let's enable both Query and Physics 294 00:16:16.821 --> 00:16:19.229 In fact, we only need Query 295 00:16:19.230 --> 00:16:21.330 But let's just try enabling both 296 00:16:21.331 --> 00:16:23.031 And then 297 00:16:23.279 --> 00:16:26.910 We need to set up its collision channel 298 00:16:26.911 --> 00:16:29.561 Over here, it is set up as Enemy 299 00:16:29.860 --> 00:16:33.819 So let's try setting it up over here 300 00:16:35.070 --> 00:16:39.320 We can add SetCollisionObjectType here 301 00:16:39.321 --> 00:16:41.621 But over here, what it says is 302 00:16:41.621 --> 00:16:44.349 Its name is looking like this 303 00:16:45.449 --> 00:16:48.111 So we need to look it up once, right? 304 00:16:48.111 --> 00:16:50.511 Back to our Project 305 00:16:51.509 --> 00:16:53.690 Let's look at the folders 306 00:16:56.100 --> 00:16:58.280 Over here, we have a folder called Config 307 00:16:58.281 --> 00:16:59.281 This is a very important folder 308 00:16:59.282 --> 00:17:02.182 Config, Content, and then Source 309 00:17:02.183 --> 00:17:04.183 These three folders are very important 310 00:17:04.183 --> 00:17:09.500 At Configt, we have the DeafultEngine.ini setup file 311 00:17:09.501 --> 00:17:13.251 Ini file is for Initial file 312 00:17:13.301 --> 00:17:16.840 So let's try and edit this 313 00:17:17.391 --> 00:17:19.741 And try scrolling to the bottom 314 00:17:19.741 --> 00:17:21.770 And we see Player here 315 00:17:21.770 --> 00:17:22.571 Player, Bullet, Enemy 316 00:17:22.571 --> 00:17:25.671 These things we set up are all in here 317 00:17:25.671 --> 00:17:29.549 But the name that should actually be used is 318 00:17:29.550 --> 00:17:31.100 The channel names we have over here 319 00:17:31.201 --> 00:17:32.901 So this channel name says 320 00:17:32.901 --> 00:17:36.509 ECC_GameTraceChannel1 321 00:17:36.510 --> 00:17:38.110 So we have 1, 2 and 3 322 00:17:38.111 --> 00:17:40.061 In the order of Player, Bullet and Enemy 323 00:17:40.061 --> 00:17:42.499 So we should remember that 324 00:17:43.000 --> 00:17:46.000 And let's write that over here 325 00:17:46.000 --> 00:17:49.570 So 1 is Player, this is 3 326 00:17:49.571 --> 00:17:51.571 Enemy was 3 327 00:17:51.572 --> 00:17:53.622 So we write it up like so 328 00:17:53.720 --> 00:17:55.979 And then, what we did here is 329 00:17:55.980 --> 00:17:58.130 Overall 330 00:17:58.760 --> 00:18:00.930 Ignore for everything, and then 331 00:18:00.931 --> 00:18:02.481 Only the ones I want to enable 332 00:18:02.482 --> 00:18:05.932 Become Overlap like so here 333 00:18:05.932 --> 00:18:08.279 That's how we process it 334 00:18:08.330 --> 00:18:10.630 And we could do it like the following 335 00:18:10.630 --> 00:18:18.030 At Mesh Component, we have 336 00:18:18.481 --> 00:18:21.781 SetCollisionResponseToAllChannels 337 00:18:21.781 --> 00:18:25.579 It means all channels are Ignored at once 338 00:18:25.580 --> 00:18:28.780 And now we can set each channel separately 339 00:18:28.780 --> 00:18:32.490 At SetCollisionResponse 340 00:18:32.491 --> 00:18:34.441 We see the individual channel here 341 00:18:34.679 --> 00:18:36.450 We can set it up using this 342 00:18:36.451 --> 00:18:39.801 So here, we have the channel 343 00:18:39.802 --> 00:18:41.752 And then the Response Time 344 00:18:42.152 --> 00:18:43.609 So it starts with an 'E' 345 00:18:43.610 --> 00:18:45.410 Meaning, it is Enum type 346 00:18:45.511 --> 00:18:47.159 So these are Enum type over here 347 00:18:47.159 --> 00:18:50.810 So we know that all Enum types start with 'E' 348 00:18:51.010 --> 00:18:54.210 Anyhow, we need to write it up like this 349 00:18:56.360 --> 00:18:58.870 1 and 2 are to collide 350 00:18:58.871 --> 00:19:00.671 That's what we want to say, and then 351 00:19:00.671 --> 00:19:03.741 Overlap will happen at the second argument 352 00:19:03.741 --> 00:19:05.541 That's what we can set up like so 353 00:19:05.640 --> 00:19:07.350 Let's make another one 354 00:19:07.351 --> 00:19:09.951 And it can Overlap with 2 as well 355 00:19:10.252 --> 00:19:13.002 That's how we can set up for its collision 356 00:19:13.102 --> 00:19:16.230 In a way, we have this concept and another for setting up the whole 357 00:19:16.231 --> 00:19:17.931 That's what we have here 358 00:19:18.380 --> 00:19:21.760 But this will give us a lot of lines for the code 359 00:19:21.761 --> 00:19:24.561 So in order to abbreviate this a little 360 00:19:24.799 --> 00:19:28.009 Because if we repeat everything like so 361 00:19:28.010 --> 00:19:30.960 The code becomes too long and there may be typos 362 00:19:31.159 --> 00:19:35.810 So at Unreal Engine, in order to abbreviate all this 363 00:19:37.069 --> 00:19:39.490 They provide something called Preset 364 00:19:39.691 --> 00:19:43.791 So let's create these three into presets and add them here 365 00:19:43.840 --> 00:19:47.680 So go to New, and let's say Player 366 00:19:50.080 --> 00:19:53.590 And let's set it as Query and Physics 367 00:19:53.591 --> 00:19:56.691 And Object Type, Player 368 00:19:56.890 --> 00:19:59.280 And Ignore for everything 369 00:19:59.281 --> 00:20:03.331 And say it only Overlaps with Enemy 370 00:20:03.331 --> 00:20:06.380 And let's do the same for all others 371 00:20:08.960 --> 00:20:12.430 For Bullet, same thing 372 00:20:12.681 --> 00:20:15.621 Ignore everything, but only Overlap with Enemy 373 00:20:16.421 --> 00:20:19.000 And finally with Enemy 374 00:20:22.100 --> 00:20:24.300 Let's also go for Query and Physics 375 00:20:24.300 --> 00:20:27.000 Set its type as Enemy 376 00:20:27.000 --> 00:20:28.500 And Ignore 377 00:20:28.501 --> 00:20:30.901 And for Bullet and Player 378 00:20:30.902 --> 00:20:33.252 Let's have them Overlap 379 00:20:34.000 --> 00:20:36.000 So we are done with creating the presets 380 00:20:36.000 --> 00:20:39.850 And all we need is to assign the presets here 381 00:20:39.850 --> 00:20:41.800 Let me demonstrate here 382 00:20:41.800 --> 00:20:45.750 What we had to do was customize each and everything 383 00:20:45.750 --> 00:20:48.000 But now, open it up here and see 384 00:20:48.100 --> 00:20:50.450 Let's compile first beforehand 385 00:20:50.700 --> 00:20:54.750 So here we have all presets for Player, Bullet and Enemy 386 00:20:54.750 --> 00:20:58.150 So since this is Enemy here 387 00:20:58.151 --> 00:20:59.951 Set it up as Enemy 388 00:20:59.951 --> 00:21:02.650 Then it automatically sets it up 389 00:21:02.651 --> 00:21:05.301 So that it fits the type for Enemy 390 00:21:05.301 --> 00:21:10.000 So let's actually try it at the code 391 00:21:10.000 --> 00:21:12.000 So after having done this 392 00:21:12.500 --> 00:21:16.000 Let's close Unreal and restart 393 00:21:16.000 --> 00:21:20.250 So let's make this a comment 394 00:21:21.500 --> 00:21:26.000 When you make something in to a comment, select the part 395 00:21:26.000 --> 00:21:29.000 And use Ctrl K+C, K+U 396 00:21:29.600 --> 00:21:31.400 It's over here 397 00:21:31.400 --> 00:21:35.050 And then our Mesh Component 398 00:21:36.250 --> 00:21:38.400 Let's see the list that has it 399 00:21:38.401 --> 00:21:41.551 Here, SetCollision 400 00:21:42.200 --> 00:21:45.000 It says 'ProfileName' 401 00:21:45.000 --> 00:21:46.950 Preset is this profile 402 00:21:46.950 --> 00:21:48.300 So we need to add this 403 00:21:48.300 --> 00:21:50.500 Here, say Text 404 00:21:50.500 --> 00:21:53.200 And we can use the name as it is 405 00:21:53.200 --> 00:21:57.000 Pay close attention to case sensitivity 406 00:21:57.000 --> 00:21:59.350 It's 'Enemy' here 407 00:22:00.350 --> 00:22:02.550 So write it out like so 408 00:22:03.100 --> 00:22:06.950 Same thing, copy everything here 409 00:22:08.450 --> 00:22:11.000 And let's do the same for Bullet and Player 410 00:22:11.000 --> 00:22:14.000 Let's lok at the constructor for Bullet, paste everything 411 00:22:14.000 --> 00:22:17.250 Bullet over here 412 00:22:17.250 --> 00:22:19.000 We can write it out like so 413 00:22:19.000 --> 00:22:21.000 And then copy it as it is 414 00:22:21.700 --> 00:22:25.350 Back to Player, at its constructor 415 00:22:25.350 --> 00:22:28.050 Let's write it out 416 00:22:28.050 --> 00:22:30.400 Here, Player 417 00:22:31.450 --> 00:22:34.200 And let's compile 418 00:22:34.200 --> 00:22:38.100 You can do Ctrl B to compile 419 00:22:39.550 --> 00:22:44.000 And you can do Ctrl F5 to restart it 420 00:22:44.000 --> 00:22:46.000 So you could click on this or 421 00:22:46.001 --> 00:22:48.751 Click on thie button at Debug 422 00:22:49.700 --> 00:22:51.550 So we have it here 423 00:22:51.550 --> 00:22:53.450 Let's check each here 424 00:22:53.450 --> 00:22:55.900 At BulletActor 425 00:22:58.750 --> 00:23:01.000 Let's go back here 426 00:23:01.100 --> 00:23:04.000 Oh, it doesn't support this here 427 00:23:04.850 --> 00:23:07.000 Let's do it manually then 428 00:23:07.000 --> 00:23:08.000 Bullet 429 00:23:08.900 --> 00:23:11.200 Enemy 430 00:23:18.800 --> 00:23:21.000 They are not set up right 431 00:23:21.400 --> 00:23:24.000 Right, this isn't set up correctly 432 00:23:24.100 --> 00:23:26.000 Let's close it for now 433 00:23:26.850 --> 00:23:28.550 It's not Mesh 434 00:23:28.550 --> 00:23:30.400 We need Box Component 435 00:23:30.400 --> 00:23:32.700 But it says Mesh, which isn't right 436 00:23:32.700 --> 00:23:35.850 So let's change everything here 437 00:23:35.850 --> 00:23:39.800 For Profile, we need to assign something out of Box Component 438 00:23:39.800 --> 00:23:42.450 It's also not written correctly 439 00:23:44.150 --> 00:23:46.500 Yes, this is the right way to do it 440 00:23:47.150 --> 00:23:48.350 This here as well 441 00:23:48.350 --> 00:23:51.500 I realize that I didn't copy this 442 00:23:52.000 --> 00:23:55.550 So let's do it again here 443 00:23:56.350 --> 00:23:58.300 So this is what it is 444 00:23:58.300 --> 00:24:01.350 I said 'Box' but I wrote 'Mesh' here 445 00:24:01.350 --> 00:24:04.000 Same thing here 446 00:24:04.300 --> 00:24:06.750 Let's write it out here 447 00:24:08.600 --> 00:24:12.000 Looking at it again, starting with Enemy 448 00:24:12.000 --> 00:24:14.200 For Mesh, we disabled the collision 449 00:24:14.200 --> 00:24:16.350 And we enabled it for Box 450 00:24:17.150 --> 00:24:20.200 And for the class at Enemy 451 00:24:20.800 --> 00:24:24.000 We set the profile for its collision settings 452 00:24:24.850 --> 00:24:26.850 Same with Bullet 453 00:24:30.800 --> 00:24:34.500 Let's build it again 454 00:24:36.900 --> 00:24:39.450 And run it 455 00:24:47.350 --> 00:24:50.350 So as of its content 456 00:24:51.450 --> 00:24:53.150 Now it looks alright 457 00:24:53.150 --> 00:24:55.000 It says Bullet here 458 00:24:55.000 --> 00:24:57.000 So, Enemy too 459 00:24:59.950 --> 00:25:02.600 It's set up nicely as we can see here 460 00:25:06.650 --> 00:25:07.750 Let's go back here 461 00:25:07.750 --> 00:25:10.400 And now it's set as Player 462 00:25:10.400 --> 00:25:13.000 So that's how we set it up here 463 00:25:13.600 --> 00:25:16.250 Let's check if Mesh is off as well 464 00:25:16.300 --> 00:25:19.450 For Mesh, this Collision Enabled 465 00:25:19.450 --> 00:25:23.000 We can see how it is set as No Collision 466 00:25:24.050 --> 00:25:26.850 So now it is working as it should 467 00:25:26.850 --> 00:25:28.700 So let's run it 468 00:25:33.150 --> 00:25:34.950 Let's see if the log is printing 469 00:25:34.951 --> 00:25:36.751 Yes, we see how it is printed 470 00:25:39.300 --> 00:25:42.700 So now we need to actually process it here 471 00:25:42.700 --> 00:25:45.450 So a while ago, we said this is our plan 472 00:25:45.450 --> 00:25:47.150 Enemy destroys Player 473 00:25:47.150 --> 00:25:50.100 And Bullet destroys Enemy 474 00:25:50.100 --> 00:25:51.550 So let's start with Enemy 475 00:25:51.550 --> 00:25:53.000 Enemy 476 00:25:54.000 --> 00:25:58.400 Let's come over here, and the actual part for collision is here 477 00:25:58.400 --> 00:26:00.000 So here 478 00:26:01.200 --> 00:26:04.350 Let's say, if 479 00:26:04.350 --> 00:26:06.400 Other Actor 480 00:26:06.400 --> 00:26:08.000 If this Other Actor is 481 00:26:09.200 --> 00:26:11.200 Our Player 482 00:26:13.000 --> 00:26:15.000 Then you die 483 00:26:15.000 --> 00:26:17.000 And I die 484 00:26:18.000 --> 00:26:19.150 Right 485 00:26:19.150 --> 00:26:21.750 So if 486 00:26:21.750 --> 00:26:23.650 Let's start with the cast 487 00:26:23.650 --> 00:26:25.400 When we process something like this 488 00:26:25.400 --> 00:26:29.000 When we verify what Other Actor is 489 00:26:29.000 --> 00:26:30.350 We have a few methods 490 00:26:30.350 --> 00:26:32.850 We could use a tag or 491 00:26:32.850 --> 00:26:37.600 We could use the name and compare with the letters in it 492 00:26:37.600 --> 00:26:41.000 Or we could use its type and cast it 493 00:26:41.000 --> 00:26:44.450 To test if that is the right type 494 00:26:44.450 --> 00:26:47.450 Let me use the casting method here 495 00:26:49.000 --> 00:26:52.000 So let's say 'Cast' 496 00:26:53.000 --> 00:26:54.250 And let's do this 497 00:26:54.250 --> 00:26:57.000 Cast is a function that looks like this 498 00:26:57.000 --> 00:26:59.700 And then here 499 00:26:59.700 --> 00:27:02.800 We write the data whose type we want to change 500 00:27:02.800 --> 00:27:06.000 For me this is APlayerPawn 501 00:27:06.150 --> 00:27:09.000 So here, it would be Other Actor 502 00:27:13.250 --> 00:27:15.500 And then we will accept this 503 00:27:15.500 --> 00:27:18.900 And then, of course we receive it as APlaywerPawn 504 00:27:18.900 --> 00:27:23.200 And it's too much work to write this out every time, right? 505 00:27:23.200 --> 00:27:24.750 If we say Player every time 506 00:27:24.750 --> 00:27:28.500 So usually we just write out 'auto' like so 507 00:27:29.350 --> 00:27:32.000 It's a pointer, so you could say this 508 00:27:32.000 --> 00:27:33.750 Write out 'Auto' 509 00:27:33.750 --> 00:27:36.600 Then with 'Auto' it automatically does this 510 00:27:36.700 --> 00:27:39.000 Try hovering over and it looks like this 511 00:27:39.800 --> 00:27:43.800 It accepts it as this data type 512 00:27:44.200 --> 00:27:46.250 Since it's a pointer, let's add this 513 00:27:46.250 --> 00:27:49.000 So is this Player or not? 514 00:27:49.000 --> 00:27:52.000 We can ask, if nullptr 515 00:27:52.700 --> 00:27:55.250 This asks if this is not Null 516 00:27:55.250 --> 00:27:56.650 Instead of using the equal sign 517 00:27:56.650 --> 00:27:59.000 So if this is not Null 518 00:27:59.000 --> 00:28:02.000 Then this Other is PlayerPawn 519 00:28:02.650 --> 00:28:04.700 Then we work with 'you die' and 'I die' parts 520 00:28:04.700 --> 00:28:10.000 I should've added the header here 521 00:28:10.600 --> 00:28:13.200 Player Pawn header is added here 522 00:28:16.500 --> 00:28:21.000 So this part destroys Player 523 00:28:21.000 --> 00:28:24.000 Let's use Destroy 524 00:28:24.700 --> 00:28:27.200 And then for 'I die', I is 'this' 525 00:28:27.200 --> 00:28:31.000 And we write out Destroy like so 526 00:28:31.000 --> 00:28:33.000 And we can omit 'this' here 527 00:28:33.000 --> 00:28:35.000 You could do it this way as well 528 00:28:35.000 --> 00:28:36.000 It's the same thing 529 00:28:36.000 --> 00:28:39.300 So let's use this same structure for Bullet as well 530 00:28:39.300 --> 00:28:42.450 Then for Bullet, since this function is not implemented yet 531 00:28:42.450 --> 00:28:46.000 Let's copy the structur of the function at Emeny as it is 532 00:28:46.000 --> 00:28:48.300 And paste it right here 533 00:28:48.300 --> 00:28:52.200 Let's add it below Tick here 534 00:28:52.200 --> 00:28:54.850 And then we add the implementation 535 00:28:54.850 --> 00:28:56.450 We repeat the same thing 536 00:28:56.450 --> 00:28:59.150 And then over at BulletActor 537 00:28:59.150 --> 00:29:03.100 At BeginPlay let's request it from Box Component 538 00:29:03.100 --> 00:29:07.000 'Dear Box Component, let me know when you collide' 539 00:29:07.000 --> 00:29:10.400 OnComponentBeginOverlap 540 00:29:10.400 --> 00:29:14.500 And let's add AddDynamic 541 00:29:16.800 --> 00:29:19.000 Let's write it out like so 542 00:29:19.000 --> 00:29:20.250 Let's add 'this' next 543 00:29:20.250 --> 00:29:21.850 And then ampersand 544 00:29:21.851 --> 00:29:24.451 And we add the whole name for the function 545 00:29:24.451 --> 00:29:26.250 So over here, we have it here 546 00:29:26.250 --> 00:29:30.000 So we can copy and paste it right away here 547 00:29:30.000 --> 00:29:31.300 And then over here 548 00:29:31.300 --> 00:29:33.700 Here, the Other Actor 549 00:29:33.700 --> 00:29:38.700 If this Other is Enemy 550 00:29:39.800 --> 00:29:44.000 we want 'you die' and 'I die' parts 551 00:29:44.350 --> 00:29:45.500 So let's do this 552 00:29:45.500 --> 00:29:47.150 Let's change it up a little 553 00:29:47.150 --> 00:29:51.000 Here, we used the function 'cast' here 554 00:29:51.750 --> 00:29:55.000 And once we get into this function 555 00:29:56.000 --> 00:29:57.200 Let's get in there like so 556 00:29:57.200 --> 00:29:59.450 Actually, we can't do that here 557 00:29:59.450 --> 00:30:01.950 Let's try it here, where we worked at before 558 00:30:01.950 --> 00:30:03.550 Let's check into our 'cast' function 559 00:30:03.550 --> 00:30:05.000 It looks like this 560 00:30:05.000 --> 00:30:08.000 ANd then, finally 561 00:30:08.000 --> 00:30:10.000 This if statement says 562 00:30:10.000 --> 00:30:11.700 It says 'is a' 563 00:30:11.700 --> 00:30:14.250 When we talk about class 564 00:30:14.250 --> 00:30:16.000 There is a concept of relationship 565 00:30:16.001 --> 00:30:18.951 When we say Object Constraining Programming (OCP) 566 00:30:18.951 --> 00:30:21.980 At OCP, there is this concept 567 00:30:23.280 --> 00:30:26.580 Let's visualize a class 568 00:30:26.581 --> 00:30:29.181 We have the parent 569 00:30:30.080 --> 00:30:32.550 And the child 570 00:30:34.000 --> 00:30:38.559 And we say the child inherits from the parent 571 00:30:38.559 --> 00:30:43.310 This is the 'is-a' relationship 572 00:30:44.461 --> 00:30:45.411 The is-a relationship 573 00:30:45.411 --> 00:30:47.911 So the child can turn into the parent 574 00:30:47.911 --> 00:30:50.311 Or the parent type into the child 575 00:30:50.312 --> 00:30:51.312 This casting is available 576 00:30:51.360 --> 00:30:53.170 To enable type casting 577 00:30:53.171 --> 00:30:55.721 It should be in this inheritance relationship 578 00:30:55.721 --> 00:30:58.440 This is the is-a relationship 579 00:30:58.440 --> 00:31:02.920 And let's say, this child 580 00:31:03.971 --> 00:31:05.420 Let me take as an example... 581 00:31:05.420 --> 00:31:06.240 Let's say a knife 582 00:31:06.240 --> 00:31:09.510 Let's say that there is a class called knife 583 00:31:09.510 --> 00:31:13.970 As instance variable, let's say 584 00:31:13.971 --> 00:31:17.171 This child has the knife 585 00:31:17.520 --> 00:31:20.720 Then this child and the knife aren't in is-a relationship 586 00:31:20.720 --> 00:31:21.839 It's not the inheritance relationship 587 00:31:21.839 --> 00:31:26.419 This kind of relationship is called 'has-a' relationship 588 00:31:27.519 --> 00:31:29.279 The 'has-A' relationship 589 00:31:29.279 --> 00:31:31.919 This is the two types of relationship here 590 00:31:31.919 --> 00:31:33.559 So is-a relationship is, in the end 591 00:31:33.560 --> 00:31:36.610 The relationship that enables for casting 592 00:31:37.279 --> 00:31:41.680 That's why we can verify by checking if it is an is-a 593 00:31:41.680 --> 00:31:43.360 So let's use that here 594 00:31:43.360 --> 00:31:46.879 Here, instead of cast, let's try this 595 00:31:46.879 --> 00:31:50.830 So if, this OtherActor 596 00:31:51.730 --> 00:31:54.959 If OtherActor, is-a 597 00:31:54.959 --> 00:31:57.140 There's this function here 598 00:31:57.140 --> 00:31:58.320 It's the template here 599 00:31:58.320 --> 00:31:59.040 Let's do this 600 00:31:59.040 --> 00:32:02.879 And here, I write the data type I want to verify 601 00:32:02.879 --> 00:32:06.080 This asks if you want to work with Enemy here 602 00:32:06.080 --> 00:32:10.239 So it asks 'AEnemyActor' 603 00:32:10.239 --> 00:32:11.771 So if this is true 604 00:32:11.771 --> 00:32:14.321 We proceed with 'you die' and 'I die' 605 00:32:14.321 --> 00:32:17.519 With the casting, this is what we get 606 00:32:17.519 --> 00:32:21.120 If I want to verify various types 607 00:32:21.120 --> 00:32:23.310 Then more if statements have to be 608 00:32:23.311 --> 00:32:25.511 Added down here like so 609 00:32:25.511 --> 00:32:28.960 But using is-a, we can simply use 'else if' 610 00:32:28.960 --> 00:32:32.320 So you have a choice between these 611 00:32:32.570 --> 00:32:34.880 I will try this method 612 00:32:34.880 --> 00:32:38.750 Same thing, for 'you die' and 'I die', at OtherActor 613 00:32:39.451 --> 00:32:41.301 Destroy 614 00:32:42.000 --> 00:32:45.600 And at 'this', Destroy 615 00:32:45.600 --> 00:32:48.479 I'll write it out like so 616 00:32:48.479 --> 00:32:50.160 So this is done 617 00:32:50.160 --> 00:32:51.870 Since we edited this part 618 00:32:51.871 --> 00:32:53.621 We should restart it 619 00:32:53.621 --> 00:32:58.269 Let's restart 620 00:33:11.439 --> 00:33:13.760 And now let's run 621 00:33:13.760 --> 00:33:15.569 Let's try shooting 622 00:33:15.569 --> 00:33:17.451 When the two meet, they get destroyed 623 00:33:17.451 --> 00:33:19.101 When they touch, they get destroyed 624 00:33:19.250 --> 00:33:20.579 So it is working well 625 00:33:21.180 --> 00:33:24.200 Making Game Over 626 00:33:25.000 --> 00:33:28.320 So now that we have the collision settings 627 00:33:28.320 --> 00:33:32.236 Let's make the Game Over screen 628 00:33:32.439 --> 00:33:34.110 In order for a Game Over 629 00:33:34.111 --> 00:33:36.511 We need to make things like its UI 630 00:33:36.560 --> 00:33:39.649 So let's make a widget here 631 00:33:39.649 --> 00:33:44.279 At Unreal, whatever processes UI is called widget 632 00:33:44.279 --> 00:33:48.309 And usually the full term is 'Unreal Motion Graphic' 633 00:33:48.309 --> 00:33:50.159 So a UMG 634 00:33:51.310 --> 00:33:52.454 Let's creat one 635 00:33:52.454 --> 00:33:54.004 Right click 636 00:33:54.005 --> 00:33:55.662 Here's User Interface 637 00:33:56.313 --> 00:33:59.013 Let's go with Widget Blueprint 638 00:33:59.013 --> 00:34:02.240 See how it is inheriting our UserWiedget class 639 00:34:02.240 --> 00:34:06.559 Meaning, if we are to create the class with C++ 640 00:34:06.559 --> 00:34:08.909 It will inherit the User widget 641 00:34:08.910 --> 00:34:12.310 And that will be inherited back to this Blueprint 642 00:34:12.559 --> 00:34:14.639 So that's the plan for us 643 00:34:14.639 --> 00:34:18.639 So let's go to Tools and create a class 644 00:34:18.689 --> 00:34:21.550 Choose All Classes here 645 00:34:21.551 --> 00:34:22.901 And write it out here 646 00:34:22.901 --> 00:34:25.200 'Userwideget' 647 00:34:26.000 --> 00:34:27.299 It's here, right? 648 00:34:27.300 --> 00:34:30.000 Click on this and go to 'Next' 649 00:34:30.399 --> 00:34:33.600 Since we are working with Game Over here 650 00:34:33.600 --> 00:34:36.320 Let's write GameOverWidget 651 00:34:36.320 --> 00:34:39.120 Let's Create 652 00:34:39.920 --> 00:34:43.450 And it is created here 653 00:34:45.200 --> 00:34:49.809 Load it and it gets created here as well 654 00:34:50.559 --> 00:34:52.320 Yes, this is how we make it 655 00:34:52.320 --> 00:34:55.380 So let's begin with the work that is visible 656 00:34:55.381 --> 00:34:56.531 Let's start with that 657 00:34:56.531 --> 00:34:59.839 So choose our GameOverWidget 658 00:34:59.839 --> 00:35:02.559 And create its Blueprint, like so 659 00:35:02.559 --> 00:35:05.359 But actually, this is a lot of work 660 00:35:05.359 --> 00:35:08.320 So let's go over here, and instead of Blueprint 661 00:35:08.320 --> 00:35:10.720 Let's go with User Interface here 662 00:35:10.720 --> 00:35:12.959 And we'll swap the parent 663 00:35:12.959 --> 00:35:14.480 So at User Interface 664 00:35:14.480 --> 00:35:16.559 We're back at that Blueprint folder 665 00:35:16.559 --> 00:35:18.799 Right click here 666 00:35:18.799 --> 00:35:20.640 Select User Interface 667 00:35:20.640 --> 00:35:22.399 Click on Widget Blueprint 668 00:35:22.399 --> 00:35:24.239 Then we get our User Widget 669 00:35:24.239 --> 00:35:26.559 But here, at All Classes 670 00:35:26.559 --> 00:35:29.440 Let's write it out here 671 00:35:29.440 --> 00:35:31.839 So GameOverWidget is here 672 00:35:31.839 --> 00:35:34.000 Let's write it out here 673 00:35:34.000 --> 00:35:36.000 Select to create 674 00:35:36.000 --> 00:35:38.640 So since this is a Widget Blueprint 675 00:35:38.640 --> 00:35:42.720 Let's use the prefix 'wbp 676 00:35:42.720 --> 00:35:44.839 So this is for Game Over 677 00:35:46.420 --> 00:35:49.119 So let's call it WBP_GameOver 678 00:35:49.119 --> 00:35:51.780 Let's save here 679 00:35:52.630 --> 00:35:53.920 Let's start editing 680 00:35:53.920 --> 00:35:55.920 Let's plan on this screen visuals 681 00:35:55.920 --> 00:35:57.760 First, what we will do is 682 00:35:57.760 --> 00:35:58.480 We will do it like so 683 00:35:58.480 --> 00:36:01.600 We start with this box at the background 684 00:36:01.600 --> 00:36:04.239 We will make it a little transparent 685 00:36:04.239 --> 00:36:06.950 And we will write out 'Game Over' 686 00:36:08.000 --> 00:36:10.080 Maybe in English? 687 00:36:10.830 --> 00:36:13.000 Game Over 688 00:36:14.000 --> 00:36:15.679 With that text, and then 689 00:36:15.679 --> 00:36:17.529 Here, 'Quit' 690 00:36:18.079 --> 00:36:20.739 And here, 'Restart' 691 00:36:22.239 --> 00:36:24.239 These are the two buttons we will add here 692 00:36:24.239 --> 00:36:27.040 That's the UI of the screen 693 00:36:27.040 --> 00:36:28.320 This is simple 694 00:36:28.320 --> 00:36:29.690 Let's try it here 695 00:36:30.640 --> 00:36:34.720 We will start with adding a panel here 696 00:36:34.720 --> 00:36:36.799 Over here at the bottom you have Panel 697 00:36:36.799 --> 00:36:38.360 It must be hidden in the dropdown menu 698 00:36:38.360 --> 00:36:40.320 So try opening it up here 699 00:36:40.320 --> 00:36:42.079 And we have Canvas Panel 700 00:36:42.079 --> 00:36:44.799 Let's drag and drop 701 00:36:44.799 --> 00:36:46.320 And let's create it here 702 00:36:46.320 --> 00:36:49.119 Then this gives us a section like so 703 00:36:49.119 --> 00:36:50.559 And then, at the bottom right 704 00:36:50.559 --> 00:36:52.079 Drag on this cursor and 705 00:36:52.079 --> 00:36:54.239 We can adjust the resolution 706 00:36:54.239 --> 00:36:56.079 I will go with the default resolution 707 00:36:56.079 --> 00:36:59.780 And work with this 1280x720 one 708 00:37:00.480 --> 00:37:04.700 And we will add a back panel 709 00:37:05.200 --> 00:37:06.880 In an image 710 00:37:06.880 --> 00:37:08.459 Like so 711 00:37:09.560 --> 00:37:17.460 Let's make it around 1200x800 712 00:37:17.460 --> 00:37:21.679 Around 1200x800 713 00:37:21.679 --> 00:37:25.440 And let's set it as 0.0 for now 714 00:37:27.440 --> 00:37:28.880 So then this is what we have 715 00:37:28.880 --> 00:37:29.920 So over here 716 00:37:29.920 --> 00:37:32.160 We have this flower-shaped thing 717 00:37:32.160 --> 00:37:33.600 This is called an anchor 718 00:37:33.600 --> 00:37:35.279 This anchor is at the top left 719 00:37:35.279 --> 00:37:37.440 Then what this wil do is 720 00:37:37.440 --> 00:37:39.200 Whenever we change the resolution 721 00:37:39.200 --> 00:37:40.079 This is what happens 722 00:37:40.079 --> 00:37:42.320 This becomes the anchoring point 723 00:37:42.320 --> 00:37:45.040 So the top left is the anchoring point 724 00:37:45.040 --> 00:37:47.600 Since there are many options for resolution 725 00:37:47.600 --> 00:37:50.399 I recommend working with variable or adaptive resolution 726 00:37:50.399 --> 00:37:52.880 And what matters in that case is this anchor 727 00:37:52.880 --> 00:37:54.959 I will position this anchor at the center 728 00:37:54.959 --> 00:37:57.440 I will palce it at the center of the screen 729 00:37:57.440 --> 00:37:59.519 And let's start working on this 730 00:37:59.519 --> 00:38:00.720 Now, I want this image 731 00:38:00.720 --> 00:38:02.239 To be placed at the center 732 00:38:02.239 --> 00:38:05.119 For that, here 733 00:38:05.119 --> 00:38:07.119 There is 'Alignment' here 734 00:38:07.119 --> 00:38:09.519 This is the ratio here 735 00:38:09.519 --> 00:38:10.720 It goes from 0 to 1 736 00:38:10.720 --> 00:38:13.119 So this is 0, and this is 1 737 00:38:13.119 --> 00:38:16.079 So if I try 0.1 here 738 00:38:16.079 --> 00:38:19.440 It goes to the left like so 739 00:38:19.440 --> 00:38:22.079 And for this, we'll start with 0.0 740 00:38:22.079 --> 00:38:25.279 Then it will move to the center like so 741 00:38:25.279 --> 00:38:27.200 So for this, if we say 1 742 00:38:27.200 --> 00:38:29.440 This is what happens 743 00:38:29.440 --> 00:38:31.279 Then, if we say 0.5 744 00:38:31.279 --> 00:38:32.239 It will be the center 745 00:38:32.239 --> 00:38:34.480 And same thing here, 0.5 746 00:38:34.480 --> 00:38:38.480 Then it is placed right at the center 747 00:38:38.480 --> 00:38:40.079 That's where we start with 748 00:38:40.079 --> 00:38:41.359 And let's change the color 749 00:38:41.359 --> 00:38:44.079 Let's change it to black 750 00:38:44.079 --> 00:38:46.630 This 'A' at the bottom is for Alpha 751 00:38:46.630 --> 00:38:49.520 Or transparency, so 1 here means 100% 752 00:38:49.520 --> 00:38:51.440 So let's reduce it down 753 00:38:51.440 --> 00:38:54.479 To around 30% 754 00:38:54.479 --> 00:38:56.320 Let's finish around here 755 00:38:56.320 --> 00:38:57.520 And we will now add 756 00:38:57.520 --> 00:39:00.400 Game Over with two buttons 757 00:39:00.400 --> 00:39:02.799 So here 758 00:39:02.799 --> 00:39:04.719 Go to Text 759 00:39:04.719 --> 00:39:07.440 And place it here 760 00:39:07.440 --> 00:39:09.440 So this is here, drag it in 761 00:39:09.440 --> 00:39:11.919 And same thing here 762 00:39:11.919 --> 00:39:13.840 We will work with the anchor a little 763 00:39:13.840 --> 00:39:17.139 First, let's say 'Game Over' 764 00:39:19.039 --> 00:39:20.640 Write it out like so 765 00:39:20.640 --> 00:39:24.000 Let's give the font size around 150 766 00:39:24.000 --> 00:39:26.940 Then this is what we get 767 00:39:28.640 --> 00:39:30.719 And then, same thing here 768 00:39:30.719 --> 00:39:32.880 Anchor at the center 769 00:39:32.880 --> 00:39:34.880 And then with 0.0 770 00:39:34.880 --> 00:39:35.919 This is what happens 771 00:39:35.919 --> 00:39:38.000 And if we want this right at the center 772 00:39:38.000 --> 00:39:40.799 Go to Alignment and say 0.5, 0.5 773 00:39:40.799 --> 00:39:42.640 And it comes to the center 774 00:39:42.640 --> 00:39:45.520 Here, I won't say this for the vertical position 775 00:39:45.520 --> 00:39:47.440 So with this 776 00:39:47.440 --> 00:39:51.330 Let's bring its Y position up a little 777 00:39:52.559 --> 00:39:54.840 This is where we will place it 778 00:39:55.840 --> 00:39:58.640 And let's add two buttons here 779 00:39:58.640 --> 00:39:59.760 Button is right here 780 00:39:59.760 --> 00:40:03.269 Add a button 781 00:40:03.919 --> 00:40:07.579 Resize it a little 782 00:40:09.679 --> 00:40:11.359 And we need some text in there 783 00:40:11.359 --> 00:40:13.760 So that the button says something 784 00:40:13.761 --> 00:40:16.845 So for the text, this is for 'Quit' 785 00:40:17.960 --> 00:40:20.010 So let's write it out 786 00:40:20.561 --> 00:40:23.062 Let's also resize it 787 00:40:23.062 --> 00:40:25.412 I'll go with size 60 788 00:40:27.360 --> 00:40:32.100 And let's change the button name to _Quit 789 00:40:32.101 --> 00:40:34.101 Button_Quit 790 00:40:34.102 --> 00:40:36.053 And let's make another 791 00:40:36.053 --> 00:40:39.753 First, compile this and save 792 00:40:40.240 --> 00:40:43.210 And do Ctrl D to duplicate 793 00:40:43.261 --> 00:40:46.461 So place this over here 794 00:40:47.719 --> 00:40:50.439 I am trying to do it fast 795 00:40:50.440 --> 00:40:53.040 So this may not be the most aesthetic version, but you try yours nicely 796 00:40:53.439 --> 00:40:55.280 So place it like so 797 00:40:55.281 --> 00:40:57.431 These are at the top left now 798 00:40:57.432 --> 00:41:01.682 So let's move the anchor to the center for all 799 00:41:02.720 --> 00:41:03.880 Like so 800 00:41:03.881 --> 00:41:06.231 Let's move everything to the center 801 00:41:06.232 --> 00:41:08.482 This is how, even when we move it around 802 00:41:08.483 --> 00:41:10.533 The anchor stays at the center 803 00:41:11.980 --> 00:41:14.039 So that's what we do here 804 00:41:14.640 --> 00:41:16.440 And this here should not be 'Quit' 805 00:41:16.441 --> 00:41:18.391 We'll use 'Restart' 806 00:41:20.710 --> 00:41:24.609 So let's change the text to 'Restart' 807 00:41:29.059 --> 00:41:31.539 And if you want to change its color, click here 808 00:41:31.540 --> 00:41:33.190 And change the background color 809 00:41:33.191 --> 00:41:36.041 For Quit, we could use red 810 00:41:36.639 --> 00:41:39.000 And for Restart 811 00:41:40.101 --> 00:41:44.401 We could use blue, or something like that 812 00:41:45.250 --> 00:41:49.680 You can also change the color of 'GameOver' here 813 00:41:50.760 --> 00:41:52.659 Shall we go with yellow? 814 00:41:52.960 --> 00:41:57.411 Then, in order to process this at the original Blueprint 815 00:41:57.411 --> 00:41:59.959 Over at the top, we have Designer and Graph 816 00:41:59.959 --> 00:42:03.400 Designer is where we work with the layouts 817 00:42:03.400 --> 00:42:09.150 And Graph is where we do the visual coding 818 00:42:09.199 --> 00:42:11.639 And we won't work on it here 819 00:42:11.640 --> 00:42:13.890 We will make a class for this 820 00:42:13.890 --> 00:42:16.229 So generally for UI 821 00:42:16.230 --> 00:42:19.730 Widget designers start by making the widget 822 00:42:19.731 --> 00:42:22.331 And with that, us programmers 823 00:42:22.631 --> 00:42:24.800 Create a class and add it on 824 00:42:24.801 --> 00:42:27.251 To further process it 825 00:42:27.251 --> 00:42:32.701 So the other method is, this gets inherited with the existing Blueprint 826 00:42:32.701 --> 00:42:35.889 And we create a component for it 827 00:42:35.890 --> 00:42:38.140 To implement it here 828 00:42:38.491 --> 00:42:42.141 But instead, we will make a variable at this side 829 00:42:42.142 --> 00:42:44.342 And bind it together 830 00:42:44.342 --> 00:42:46.690 So let's try this latter method together 831 00:42:46.691 --> 00:42:50.491 So let's come over to GameOver Widget Header 832 00:42:50.492 --> 00:42:52.392 And say 'public' 833 00:42:53.440 --> 00:42:56.221 And let's write it out here 834 00:42:56.221 --> 00:42:57.821 UPROPERTY 835 00:43:00.249 --> 00:43:02.910 EditAnywhere 836 00:43:06.279 --> 00:43:09.299 And then write 'class' 837 00:43:09.300 --> 00:43:10.500 That's a button, so 838 00:43:10.501 --> 00:43:13.051 So say UButton 839 00:43:13.399 --> 00:43:15.640 We can actually see this 840 00:43:15.641 --> 00:43:17.741 Here, it says Button 841 00:43:17.742 --> 00:43:20.492 And to the top right, it says Open Button 842 00:43:20.492 --> 00:43:22.011 So click on this 843 00:43:22.011 --> 00:43:25.611 And we can see the class of that button 844 00:43:25.612 --> 00:43:28.412 It says UButton here 845 00:43:28.413 --> 00:43:31.360 So when you have trouble understanding 846 00:43:31.360 --> 00:43:32.970 You can look for it like so 847 00:43:32.971 --> 00:43:35.071 UButton, let's go with the pointer 848 00:43:35.072 --> 00:43:39.022 And the name we use here must be the same as this name here 849 00:43:39.622 --> 00:43:41.720 So say Button_Quit 850 00:43:41.721 --> 00:43:44.371 And So you cannot add a space here 851 00:43:44.670 --> 00:43:46.759 Everything should be together with no space 852 00:43:46.760 --> 00:43:49.160 And then let's write it out 853 00:43:49.609 --> 00:43:50.979 And we need to bind it 854 00:43:50.980 --> 00:43:53.431 To bind, write 'meta' here 855 00:43:53.431 --> 00:43:55.631 And you must add the parenthesis like this 856 00:43:55.632 --> 00:43:59.632 And write 'BindWidget' 857 00:44:00.720 --> 00:44:02.690 That's how you write it 858 00:44:02.691 --> 00:44:04.841 And let's make another same thing 859 00:44:04.842 --> 00:44:06.542 For not Quit but Restart 860 00:44:07.093 --> 00:44:08.793 So that's how you do it 861 00:44:09.479 --> 00:44:13.019 Save and let's go check 862 00:44:13.020 --> 00:44:15.470 To check for the binding 863 00:44:15.471 --> 00:44:18.069 Next to Hierarchy is 'Bind Widgets' 864 00:44:18.069 --> 00:44:21.160 Now, it is not bound correctly 865 00:44:21.161 --> 00:44:22.461 So we don't have anything bound 866 00:44:22.462 --> 00:44:23.562 So this part is empty 867 00:44:23.563 --> 00:44:28.163 So let's compile and take a look again 868 00:44:32.180 --> 00:44:34.221 So this has been compiled 869 00:44:34.221 --> 00:44:36.621 Over here, now it has a dropdown menu 870 00:44:36.622 --> 00:44:39.422 And we get two successful ones 871 00:44:39.422 --> 00:44:41.011 It's because they have the same name 872 00:44:41.011 --> 00:44:43.461 If we are to change the name 873 00:44:44.262 --> 00:44:48.012 This name at class and this name here 874 00:44:49.160 --> 00:44:50.729 Then there will be an error 875 00:44:50.730 --> 00:44:53.980 So it says the name is different, or that it cannot find it 876 00:44:54.331 --> 00:44:57.081 So we need to set the name identically 877 00:44:57.679 --> 00:45:00.209 So now when we compile, it works well 878 00:45:00.210 --> 00:45:05.060 And now we will connect action to this button 879 00:45:05.060 --> 00:45:06.561 Or rather, connect an event 880 00:45:06.562 --> 00:45:08.562 In fact, if we are to do it on Blueprint 881 00:45:08.562 --> 00:45:12.799 You can tick the box for Is Variable here 882 00:45:13.100 --> 00:45:16.450 And at the bottom we see that event 883 00:45:17.199 --> 00:45:20.440 I mean, you can see it even without Variable check 884 00:45:21.041 --> 00:45:24.691 Anyways, you can click this, and if you want this to be clickable 885 00:45:24.692 --> 00:45:27.992 Then you get this node over at Graph 886 00:45:27.992 --> 00:45:30.359 So you can process it here 887 00:45:30.360 --> 00:45:32.760 This is what works for Blueprint 888 00:45:32.959 --> 00:45:36.590 Since we are going to process it a C++ 889 00:45:36.591 --> 00:45:38.441 We can come over here and process it 890 00:45:38.442 --> 00:45:40.467 So if we press this 891 00:45:40.468 --> 00:45:42.418 It calls a function 892 00:45:42.419 --> 00:45:45.440 And after that call we can process it 893 00:45:45.940 --> 00:45:49.710 So over here 894 00:45:49.761 --> 00:45:51.311 We will connect a function 895 00:45:51.312 --> 00:45:53.562 And to do so, we need something 896 00:45:53.562 --> 00:45:55.470 We need a concept of 'start' 897 00:45:55.471 --> 00:45:57.021 So over here 898 00:45:57.622 --> 00:46:00.522 The starting function is this Construct 899 00:46:01.220 --> 00:46:05.610 So we need to use this Construct function 900 00:46:06.361 --> 00:46:09.511 It must be at the parent, inherited as virtual 901 00:46:09.512 --> 00:46:10.912 It is being redefined for use 902 00:46:10.912 --> 00:46:15.390 virtual void Native 903 00:46:15.391 --> 00:46:17.791 We have this NativeConstruct 904 00:46:18.040 --> 00:46:22.200 Which we can use to implement 905 00:46:22.760 --> 00:46:25.800 So we connect our button here 906 00:46:25.851 --> 00:46:30.451 And we need a function to call when the button is clicked 907 00:46:31.100 --> 00:46:34.400 So we will create two more functions 908 00:46:34.401 --> 00:46:36.501 Of course, as UFUNCTION 909 00:46:37.600 --> 00:46:39.959 Meaning, these are also processed as delegates 910 00:46:39.960 --> 00:46:45.860 So void OnClick, Quit 911 00:46:46.309 --> 00:46:50.799 Copy everything, restart 912 00:46:50.799 --> 00:46:54.480 Let's create these two functions 913 00:47:00.040 --> 00:47:02.259 And over at this side 914 00:47:02.760 --> 00:47:05.360 We will be connecting the button here 915 00:47:06.839 --> 00:47:09.709 And here, we will be implementing the functions 916 00:47:09.710 --> 00:47:13.860 So to connect thf button, at Button_Quit 917 00:47:14.261 --> 00:47:17.261 We have a delegate named OnClicked 918 00:47:17.559 --> 00:47:20.210 So it looks like this over here 919 00:47:21.111 --> 00:47:23.211 It is hard to find, let's do it as it is 920 00:47:23.211 --> 00:47:28.970 So here, after the period, AddDynamic 921 00:47:29.671 --> 00:47:31.321 We can write it out as it says here 922 00:47:31.321 --> 00:47:37.239 Add 'this' and connect the function like so 923 00:47:38.079 --> 00:47:40.899 You must add that ampersand 924 00:47:41.450 --> 00:47:44.250 You need to use the reference operator to pass over the address 925 00:47:44.399 --> 00:47:45.779 So, we get the error because 926 00:47:45.780 --> 00:47:49.780 This Header is not included to be added 927 00:47:49.781 --> 00:47:50.931 So let's include it 928 00:47:50.932 --> 00:47:54.432 So we include this button 929 00:47:56.679 --> 00:47:58.811 You could write it this way 930 00:47:58.811 --> 00:47:59.661 But I will do it this way 931 00:47:59.662 --> 00:48:02.212 Here, we see that UMG here 932 00:48:03.260 --> 00:48:06.169 It may not be a big error for now 933 00:48:06.820 --> 00:48:10.220 Let me explain more after finishing this part 934 00:48:10.221 --> 00:48:12.421 Let's set the Restart at our button 935 00:48:13.920 --> 00:48:17.320 So this needs the restart 936 00:48:20.020 --> 00:48:21.579 And we will ipmlement the function 937 00:48:21.580 --> 00:48:24.330 It is a simple work to end the game 938 00:48:24.330 --> 00:48:29.059 Here, we have UKismetSystemLibrary 939 00:48:29.360 --> 00:48:33.160 And here we have the function QuitGame 940 00:48:33.359 --> 00:48:36.879 And we first need World 941 00:48:36.880 --> 00:48:38.930 And Player Control, second 942 00:48:38.931 --> 00:48:41.831 And third, a sort of Type 943 00:48:41.832 --> 00:48:43.232 How should we fill it in? 944 00:48:43.232 --> 00:48:44.259 How should we end it? 945 00:48:44.260 --> 00:48:48.560 And this, will it be a platform-dependent processing? 946 00:48:48.561 --> 00:48:50.811 Are we going to ignore thoe on the platform? 947 00:48:50.812 --> 00:48:52.462 That's the concept here 948 00:48:52.462 --> 00:48:55.830 So for this fourth argument, for example 949 00:48:56.981 --> 00:48:58.931 We have all the PlayStation games 950 00:48:58.932 --> 00:49:02.532 And you do not quit the game right away 951 00:49:02.532 --> 00:49:05.259 When you 'quit' during a game 952 00:49:05.260 --> 00:49:06.610 It doesn't actually end the game 953 00:49:06.611 --> 00:49:09.411 You just get out into the lobby screen 954 00:49:09.609 --> 00:49:11.231 So will this ignore that? 955 00:49:11.231 --> 00:49:12.381 This is asking that question 956 00:49:12.382 --> 00:49:13.982 Same with Switch 957 00:49:14.280 --> 00:49:16.201 So let's add one by one 958 00:49:16.201 --> 00:49:18.251 Let's add GetWorld 959 00:49:20.101 --> 00:49:24.131 And second, we are to add Player Controller 960 00:49:24.131 --> 00:49:27.941 So at GetWorld, first player 961 00:49:27.942 --> 00:49:31.942 GetFirstPlayerController 962 00:49:31.943 --> 00:49:33.693 Bring this in like so 963 00:49:34.093 --> 00:49:41.651 And that is EQuitPreference 964 00:49:41.651 --> 00:49:43.581 So here it is 965 00:49:43.882 --> 00:49:46.182 Let's add Quit 966 00:49:47.233 --> 00:49:49.183 And then, next 967 00:49:49.481 --> 00:49:52.601 Let's add false 968 00:49:55.451 --> 00:49:57.900 It's because we haven't added the header 969 00:49:57.901 --> 00:49:59.951 So let's add that header like so 970 00:50:00.050 --> 00:50:05.590 Yes, you can add it at Kismet as well 971 00:50:06.571 --> 00:50:08.681 So that's how we can use it 972 00:50:08.682 --> 00:50:10.082 Quit is a simple task to implement 973 00:50:10.132 --> 00:50:11.832 And for restart 974 00:50:11.833 --> 00:50:15.333 We will reopen the level 975 00:50:16.031 --> 00:50:17.721 So it's a reload 976 00:50:17.722 --> 00:50:19.272 This will initialize everything 977 00:50:19.273 --> 00:50:22.373 It destroys everything that has been loaded 978 00:50:22.374 --> 00:50:24.574 And then it re-loads 979 00:50:24.574 --> 00:50:30.090 So here, UGameplayStatics 980 00:50:30.090 --> 00:50:33.451 Over here we have OpenLevel 981 00:50:33.852 --> 00:50:36.152 We can open the level with this 982 00:50:36.153 --> 00:50:39.253 So use GetWorld 983 00:50:39.603 --> 00:50:42.220 And then our level name is 984 00:50:42.621 --> 00:50:43.621 GameMap 985 00:50:43.672 --> 00:50:45.422 So we can use that 986 00:50:45.920 --> 00:50:48.591 So here, text 987 00:50:49.492 --> 00:50:52.342 But this will be problematic if we change the name 988 00:50:52.342 --> 00:50:54.693 So let's import the current level 989 00:50:54.743 --> 00:50:56.861 The current level name, over here 990 00:50:56.862 --> 00:51:02.212 We can use GetCurrentLevelName 991 00:51:04.061 --> 00:51:06.330 So we can use it to bring it in 992 00:51:06.331 --> 00:51:10.281 So here, let's first add the header 993 00:51:12.691 --> 00:51:18.611 And this returns FString 994 00:51:18.611 --> 00:51:21.591 So it returns something as a string 995 00:51:21.792 --> 00:51:24.292 So let's say LevelName 996 00:51:24.393 --> 00:51:27.193 So we add that levelname here 997 00:51:27.691 --> 00:51:28.490 And we get an error 998 00:51:28.491 --> 00:51:30.791 This is because 999 00:51:31.492 --> 00:51:34.542 For OpenLevel 1000 00:51:34.943 --> 00:51:38.593 We need FName, not FString 1001 00:51:38.593 --> 00:51:41.140 This error was because of the wrong data type 1002 00:51:41.141 --> 00:51:44.541 We can just change it, so let's say FName 1003 00:51:44.541 --> 00:51:47.971 That's it, FName 1004 00:51:47.972 --> 00:51:50.023 And here in front of it 1005 00:51:50.323 --> 00:51:52.323 We add the value like so 1006 00:51:54.131 --> 00:51:58.650 This allows us to load the current level 1007 00:51:58.801 --> 00:52:01.501 So finally, we need this 1008 00:52:02.701 --> 00:52:04.651 Actual UI to show up 1009 00:52:04.652 --> 00:52:08.203 And that can be shown when Enemy 1010 00:52:08.203 --> 00:52:09.001 Bumps into Player 1011 00:52:09.001 --> 00:52:11.031 When 'you die' and 'I die' happen 1012 00:52:11.032 --> 00:52:13.532 So this means Player has been destroyed 1013 00:52:13.533 --> 00:52:15.683 So what we want to do is 1014 00:52:15.684 --> 00:52:17.934 We will make it stop 1015 00:52:18.131 --> 00:52:19.610 Stop! 1016 00:52:19.611 --> 00:52:21.311 Let's stop the game 1017 00:52:21.712 --> 00:52:23.662 Should we first show the UI? 1018 00:52:24.460 --> 00:52:28.771 The GameOver UI 1019 00:52:29.211 --> 00:52:32.630 Create it first and 1020 00:52:33.381 --> 00:52:36.831 Show it on the screen 1021 00:52:36.930 --> 00:52:38.220 That will be the first thing 1022 00:52:38.221 --> 00:52:40.521 And then we stop the game 1023 00:52:41.730 --> 00:52:43.900 Yes, let's process it like so 1024 00:52:43.901 --> 00:52:47.901 So we need soemthing to make that GameOver UI 1025 00:52:48.750 --> 00:52:52.210 So, the function to create UI is 1026 00:52:52.211 --> 00:52:54.561 This function is called CreateWidget 1027 00:52:58.440 --> 00:52:59.560 That's the function 1028 00:52:59.561 --> 00:53:01.261 And here, we need 1029 00:53:01.512 --> 00:53:02.912 At first we add World 1030 00:53:02.913 --> 00:53:06.413 getWorld, like so 1031 00:53:08.071 --> 00:53:11.490 And second, TSubClassOf 1032 00:53:11.491 --> 00:53:12.491 This is UClass here 1033 00:53:12.492 --> 00:53:14.292 So this goes in here 1034 00:53:15.042 --> 00:53:18.461 We made GameOver UI at Blueprint 1035 00:53:18.462 --> 00:53:20.312 So we will be adding that here 1036 00:53:20.913 --> 00:53:23.113 So let's make it over here 1037 00:53:23.211 --> 00:53:24.190 Should we say this? 1038 00:53:24.191 --> 00:53:27.191 GameOverUIFactory 1039 00:53:29.090 --> 00:53:32.331 So we can define that variable like so 1040 00:53:33.431 --> 00:53:36.031 Let's go over here and make it here 1041 00:53:36.032 --> 00:53:37.882 UPROPERTY 1042 00:53:40.311 --> 00:53:43.610 EditAnywhere 1043 00:53:44.011 --> 00:53:46.331 TSubclassOf, and then 1044 00:53:46.332 --> 00:53:47.882 Class 1045 00:53:49.081 --> 00:53:51.930 UGame 1046 00:53:52.571 --> 00:53:54.081 OverWidget 1047 00:53:54.082 --> 00:53:55.082 This is it 1048 00:53:55.083 --> 00:53:57.733 So this will create going through these 1049 00:53:59.331 --> 00:54:01.230 So let's take them all 1050 00:54:01.231 --> 00:54:03.381 And make it over here 1051 00:54:03.382 --> 00:54:05.732 So now that we made it, let's process it 1052 00:54:06.430 --> 00:54:07.960 But here, we don't have it 1053 00:54:07.961 --> 00:54:11.011 Because, this nees to be used now 1054 00:54:13.760 --> 00:54:17.121 But we haven't included UGameOverWidget 1055 00:54:17.121 --> 00:54:18.271 So there will be an error 1056 00:54:18.370 --> 00:54:20.240 So over here 1057 00:54:23.610 --> 00:54:26.271 Let's write this 1058 00:54:29.551 --> 00:54:32.091 Let's write GameOverWidget 1059 00:54:32.092 --> 00:54:33.092 Then there's no error 1060 00:54:33.093 --> 00:54:36.993 And let's add Auto UI like so 1061 00:54:36.993 --> 00:54:38.981 And we will take this to the screen 1062 00:54:38.982 --> 00:54:40.032 The fact that we made it 1063 00:54:40.033 --> 00:54:42.183 Doesn't automatically show it on the screen 1064 00:54:42.183 --> 00:54:44.090 So in order to do so 1065 00:54:44.091 --> 00:54:49.492 At UI, using the function AddToViewport 1066 00:54:49.493 --> 00:54:51.443 Let's show it to the screen 1067 00:54:52.090 --> 00:54:54.501 And we will stop the game 1068 00:54:55.152 --> 00:54:57.802 So, let's do this and 1069 00:55:00.831 --> 00:55:03.330 Let's do Live Coding to compile 1070 00:55:04.490 --> 00:55:06.641 Yes, it works 1071 00:55:08.070 --> 00:55:11.302 So we need to fill it in over at Enemy 1072 00:55:11.302 --> 00:55:12.552 This none is empty 1073 00:55:12.553 --> 00:55:14.853 So let's fill it in with GameOver 1074 00:55:15.451 --> 00:55:17.321 So over here 1075 00:55:19.610 --> 00:55:21.011 Let's run it 1076 00:55:22.112 --> 00:55:23.062 We have it now 1077 00:55:23.063 --> 00:55:26.913 But the problem is, we don't get the cursor 1078 00:55:27.111 --> 00:55:29.160 We don't have that mouse focus 1079 00:55:29.161 --> 00:55:31.761 So we need to process it 1080 00:55:32.930 --> 00:55:38.171 We'd like to show that mouse pointer 1081 00:55:38.171 --> 00:55:39.220 So we need this 1082 00:55:39.521 --> 00:55:42.521 Stop the game and show the mouse pointer 1083 00:55:44.020 --> 00:55:46.121 We need PlayerController for this 1084 00:55:46.121 --> 00:55:47.921 At GetWorld 1085 00:55:49.251 --> 00:55:53.090 Get GetFirstPlayerController 1086 00:55:53.090 --> 00:55:55.201 Let's hold onto this here 1087 00:55:55.201 --> 00:55:57.201 Let's say it as auto pc 1088 00:55:57.202 --> 00:55:59.202 So let's stop with this 1089 00:55:59.202 --> 00:56:03.710 And at PC, there's a function called SetPause 1090 00:56:03.711 --> 00:56:05.761 So let's add 'true' here 1091 00:56:06.660 --> 00:56:11.171 And we can simply not show this 1092 00:56:11.971 --> 00:56:14.111 Or, rather, we need to show the mouse pointer 1093 00:56:14.112 --> 00:56:16.112 SetShow 1094 00:56:17.810 --> 00:56:20.160 SetShowMouseCursor 1095 00:56:20.161 --> 00:56:23.611 So we can set this as 'true' 1096 00:56:24.731 --> 00:56:26.691 Then after GameOver 1097 00:56:26.692 --> 00:56:27.792 With the restart 1098 00:56:27.792 --> 00:56:30.593 We need to reverse this 1099 00:56:32.041 --> 00:56:33.790 We do not stop 1100 00:56:34.741 --> 00:56:36.641 We run it again 1101 00:56:36.642 --> 00:56:40.042 And we need to hide that mouse pointer again 1102 00:56:41.040 --> 00:56:42.851 So to do so 1103 00:56:44.811 --> 00:56:47.130 Let's do it when Player is born 1104 00:56:47.131 --> 00:56:51.131 So at BeginPlay, let's add false 1105 00:56:53.370 --> 00:56:55.710 Let's process it like so 1106 00:56:56.561 --> 00:56:58.561 Now, compile 1107 00:57:03.131 --> 00:57:04.412 So we get the cursor 1108 00:57:04.412 --> 00:57:06.962 Restart, and it's gone again 1109 00:57:12.261 --> 00:57:14.450 So it is working well 1110 00:57:15.150 --> 00:57:18.651 But it only begins after I click 1111 00:57:19.402 --> 00:57:23.502 So we need a bit of editing for that 1112 00:57:23.802 --> 00:57:26.050 At PlayerController 1113 00:57:26.301 --> 00:57:28.901 We have SetInputMode 1114 00:57:29.102 --> 00:57:30.702 So with this InputMode 1115 00:57:30.702 --> 00:57:33.780 At FInputMode we have these three 1116 00:57:33.781 --> 00:57:37.581 So for now, generally, it says GameAndUI 1117 00:57:37.581 --> 00:57:39.970 But if we say GameOnly 1118 00:57:39.971 --> 00:57:42.071 It won't accept any clicks 1119 00:57:42.372 --> 00:57:44.372 And for UIOnly 1120 00:57:44.373 --> 00:57:47.773 It will not get any input from the screen 1121 00:57:47.773 --> 00:57:51.591 So we can have more control using these 1122 00:57:51.592 --> 00:57:54.442 At first, we can go with GameOnly 1123 00:57:54.970 --> 00:57:58.261 For this, we can use the parenthesis 1124 00:57:58.262 --> 00:58:00.062 And with GameOver 1125 00:58:00.063 --> 00:58:03.663 At GameOver we can say UI Only 1126 00:58:04.011 --> 00:58:06.541 So we do that 1127 00:58:06.541 --> 00:58:09.291 And over here at processing GameOver 1128 00:58:09.292 --> 00:58:10.942 It's UI Only 1129 00:58:12.290 --> 00:58:14.891 So by setting this up 1130 00:58:15.041 --> 00:58:17.291 It will control things better 1131 00:58:17.692 --> 00:58:19.442 So compile 1132 00:58:24.740 --> 00:58:25.410 And run 1133 00:58:25.411 --> 00:58:28.511 So even without the click, I can move it right away 1134 00:58:32.091 --> 00:58:33.791 It works 1135 00:58:33.792 --> 00:58:35.242 And after it is destroyed 1136 00:58:35.991 --> 00:58:39.091 It pauses and we get the UI 1137 00:58:39.991 --> 00:58:42.342 And no input at the game 1138 00:58:42.342 --> 00:58:45.781 And with Restart, we can press the key right away to move 1139 00:58:45.782 --> 00:58:47.782 That's how it processes it 1140 00:58:48.331 --> 00:58:52.020 That was on C++ based shooter game production 1141 00:58:52.021 --> 00:58:53.021 Thank you 1142 00:58:53.370 --> 00:58:57.520 Let's summarize what we've learned this chapter 1143 00:58:57.621 --> 00:58:58.621 Processing Collision Individual Collision Response Setup NotifyActorBeginOverlap() function detects partial collision 1144 00:58:58.622 --> 00:58:59.622 Calls OnComponentBeginOverlap delegate Copy entire parameter + paste and delete the comma between data type and variable 1145 00:58:59.623 --> 00:59:00.623 MeshComp -> SetCollisionEnabled() function declared BoxComp -> SetGenerateOverLapEvent() function declared 1146 00:59:00.624 --> 00:59:01.624 SetCollisionResponseToChannel() function to set individual channel 1147 00:59:01.625 --> 00:59:02.625 Set as Preset Creating collision response setting every time for object is not efficient 1148 00:59:02.625 --> 00:59:03.625 Create New Profile, create Player, Bullet, Enemy at Collision Presets 1149 00:59:03.626 --> 00:59:04.626 BoxComp -> function SetCollisionProfileName() declared Set the right collision Profile for each class 1150 00:59:04.627 --> 00:59:05.727 GameOver UI Production At Blueprint folder, select Widget Blueprint at User Interface 1151 00:59:05.727 --> 00:59:06.978 ALL CLASSES -> select GameOverWidget Drag and drop Canvas Panel to set up UI screen 1152 00:59:06.828 --> 00:59:08.079 Even with the resolution change, central anchor makes sure everything is centered Create variables and implement using bind 1153 00:59:07.979 --> 00:59:09.380 Event connection for buttons To connect button, declare function NativeConstruct() At OnClicked delegate, connect existing functions using AddDynamic 1154 00:59:08.631 --> 00:59:10.731 Quit button : UKismetSystemLibrary::QuitGame Restart button : OpenLevel at GamePlayStatics 1155 00:59:10.632 --> 00:59:12.032 To creat UI, declare CreateWidget To show it on screen, declare AddtoVieport 1156 00:59:12.032 --> 00:59:13.032 The End