1 00:00:23.582 --> 00:00:29.580 Hello, this is Kim Hyun-Jin on Unreal Engine Basics for Immersive Contents 2 00:00:30.000 --> 00:00:35.680 Today, we will learn how to get the event for actor collision 3 00:00:35.700 --> 00:00:43.000 To visualize the particles of that location of collision, while destroying that actor 4 00:00:43.842 --> 00:00:46.492 Getting Event for Actor Collision 5 00:00:47.360 --> 00:00:51.660 Let's get the events for actor collision 6 00:00:52.000 --> 00:00:57.440 At Unreal, there are Block and Overlap 7 00:00:58.080 --> 00:01:02.000 Block is something physical 8 00:01:03.000 --> 00:01:08.200 When a ball hits the ground, it bounces, it rolls away 9 00:01:08.200 --> 00:01:12.940 But for Overlap, we do not see whether there is a collision 10 00:01:13.020 --> 00:01:17.000 Because it does not have any physical result; it just passes through 11 00:01:18.800 --> 00:01:22.800 Let's see how these are different 12 00:01:23.400 --> 00:01:27.660 At Content Browser, let's create a Blueprint Class 13 00:01:28.000 --> 00:01:32.740 Right click, Blueprint Class, choose 'Actor' 14 00:01:34.000 --> 00:01:39.440 Let's name it BP_CollisionTest 15 00:01:40.580 --> 00:01:42.580 Double click to open 16 00:01:43.060 --> 00:01:45.880 Let's add a Static Mesh Component 17 00:01:46.000 --> 00:01:52.820 Click on Add, search for Static Mesh 18 00:01:54.600 --> 00:01:56.780 Let's choose its form as well 19 00:01:57.000 --> 00:02:02.000 At Details, go to Static Mesh, click on 'none' 20 00:02:02.000 --> 00:02:07.600 And search for 'cube' to make it a cube 21 00:02:10.520 --> 00:02:14.780 And compile to get this part where we set its material 22 00:02:14.780 --> 00:02:22.820 Compile, and choose any material you want 23 00:02:23.740 --> 00:02:26.740 I will go with yellow 24 00:02:28.420 --> 00:02:34.800 At Static Mesh and go to Details, there is this part called Collision 25 00:02:34.800 --> 00:02:39.660 Let's expand on this Collision Preset 26 00:02:39.660 --> 00:02:50.280 These are some options on how this actor will process a collision 27 00:02:51.700 --> 00:02:54.971 Now, what we have for Collision Preset is 28 00:02:55.611 --> 00:02:58.320 Block-all-dynamic 29 00:02:59.660 --> 00:03:03.640 Let's expand this and change to Custom 30 00:03:03.703 --> 00:03:08.103 Then we can change all these things below 31 00:03:09.240 --> 00:03:14.931 See how Collision Enabled is set as 32 00:03:14.931 --> 00:03:18.460 Collision Enabled Query and Physics 33 00:03:18.980 --> 00:03:25.840 It means it will process both Block and Overlap 34 00:03:26.940 --> 00:03:33.251 At its dropdown menu, we have No Collision, Query Only, 35 00:03:33.251 --> 00:03:43.121 Physics only, Collision-enabled, Probe only, and Query and Probe 36 00:03:44.461 --> 00:03:46.711 We need to know about No Collision 37 00:03:46.751 --> 00:03:50.800 So set it as No Collision, which simply means that there will be no collision 38 00:03:51.461 --> 00:03:57.920 And Query Only means it only processes Overlaps 39 00:03:57.920 --> 00:04:03.420 Physics Only, only the Bocks 40 00:04:04.141 --> 00:04:11.261 Collision Enabled means it processes both Block and Overlap 41 00:04:12.721 --> 00:04:15.981 Down here, for collision Response 42 00:04:16.721 --> 00:04:22.201 All the things below are checked for Block 43 00:04:22.441 --> 00:04:27.961 This means this will only allow for Blocks 44 00:04:29.721 --> 00:04:33.511 Let's make this actor move physically 45 00:04:33.531 --> 00:04:36.601 We have a tab called Physics 46 00:04:36.601 --> 00:04:40.441 And we have Simulate Physics, tick on that 47 00:04:40.541 --> 00:04:45.021 And we also have Enable Gravity option ticked 48 00:04:45.021 --> 00:04:47.461 It means it will use gravity 49 00:04:47.761 --> 00:04:52.221 Let's compile, save, and go to Actual Level 50 00:04:52.701 --> 00:04:58.201 Let's put some BP_Collision tests in front of Player 51 00:04:58.901 --> 00:05:00.101 Let's move it a bit up 52 00:05:01.921 --> 00:05:09.921 And play, now we see how it collides with the ground 53 00:05:11.041 --> 00:05:14.621 Let's now move Player to collide 54 00:05:14.819 --> 00:05:19.600 Now, see how it just pushes around the cube 55 00:05:21.119 --> 00:05:23.599 This is the Block processing 56 00:05:26.142 --> 00:05:32.102 Now, let's try these options for Block to Overlap 57 00:05:32.541 --> 00:05:39.002 Compile and play here, and we do not get physical collisions 58 00:05:39.212 --> 00:05:41.812 It just falls down into the ground 59 00:05:43.260 --> 00:05:46.480 With all the options for Overlap 60 00:05:46.480 --> 00:05:52.800 It means that it only Overlaps with other actors 61 00:05:54.000 --> 00:06:00.000 For Overlap, it seems that there is no collision 62 00:06:01.000 --> 00:06:05.460 But it is calculating internally whether there has been a collision 63 00:06:07.000 --> 00:06:14.000 So for a collision, we could make it act a certain way with that as an event 64 00:06:17.000 --> 00:06:20.000 Let's take a look at the options at Collision tab 65 00:06:23.000 --> 00:06:28.360 Object Type is setting actors into a certain group 66 00:06:28.760 --> 00:06:35.800 We have Player And AI, and for these, their Static Mesh Components are 67 00:06:36.000 --> 00:06:40.280 Set into a group called World Dynamic 68 00:06:40.460 --> 00:06:43.610 And you may want to switch up the group a bit 69 00:06:43.610 --> 00:06:46.100 For that, we can create an object type 70 00:06:46.400 --> 00:06:52.480 We can create an object type to, for example, set Player into Player Type 71 00:06:52.480 --> 00:07:00.460 And AI into AI Object Type, to group them differently 72 00:07:02.780 --> 00:07:07.780 For Collision Enabled, let's say Player is set as 'No Collision' 73 00:07:07.920 --> 00:07:12.650 It means it processes for neither Block nor Overlap 74 00:07:12.650 --> 00:07:14.880 Neither Block nor Overlap 75 00:07:15.660 --> 00:07:20.010 Query Only means it only processes Overlaps 76 00:07:20.010 --> 00:07:23.560 Physics only, Blocks only 77 00:07:24.000 --> 00:07:29.680 Collision Enabled, both Overlap and Block 78 00:07:30.700 --> 00:07:34.350 We have Response option here 79 00:07:34.530 --> 00:07:38.340 For Response, there is Ignore, Overlap, and Block 80 00:07:39.540 --> 00:07:42.820 Ignore ignores all collisions 81 00:07:42.820 --> 00:07:45.770 Overlap processes only overlaps 82 00:07:45.770 --> 00:07:49.140 Block, only blocks 83 00:07:49.140 --> 00:07:52.000 And let's look at this in more details 84 00:07:54.000 --> 00:07:56.580 We have Player and AI 85 00:07:58.000 --> 00:08:03.580 Let's say the object type of Player is 'Player' 86 00:08:04.220 --> 00:08:08.020 And that of AI, 'AI' 87 00:08:09.620 --> 00:08:12.970 For Collision Enabled, 88 00:08:12.970 --> 00:08:18.660 Let's say I used Collision Enabled for both 89 00:08:20.600 --> 00:08:28.040 And for Object Response, we have all the object types listed like so 90 00:08:28.740 --> 00:08:36.520 World Dynamic, their own types, so Player and AI as well 91 00:08:36.760 --> 00:08:42.420 And there is a box to tick on 92 00:08:47.040 --> 00:08:49.740 Let's say Ignore here 93 00:08:51.520 --> 00:08:53.780 Overlap here 94 00:08:54.740 --> 00:08:56.880 And Block here 95 00:08:58.100 --> 00:09:03.720 Same thing, we have the Objet Response tab set up for AI 96 00:09:05.481 --> 00:09:12.240 And for this, for Player, it ignores collision with World Dynamic 97 00:09:14.121 --> 00:09:18.860 And between Players, they Overlap 98 00:09:19.360 --> 00:09:23.180 And with AI, it Blocks 99 00:09:23.180 --> 00:09:26.160 That's the setup we can have for each 100 00:09:27.740 --> 00:09:32.420 Now for AI, it Overlaps with World Dynamic, for instance 101 00:09:33.360 --> 00:09:36.760 Ignore collision with Player 102 00:09:36.760 --> 00:09:41.700 And Ignore collision with AI, we could set it up like so 103 00:09:43.100 --> 00:09:47.850 And for Player, what collision does it have with AI? 104 00:09:47.850 --> 00:09:50.440 It has Block 105 00:09:51.080 --> 00:09:55.120 And for AI, it Ignores collision with Player 106 00:09:55.120 --> 00:10:01.580 And with this, when these two collide, there is no Block happening 107 00:10:01.620 --> 00:10:09.000 Here, Ignore is the priority; so it follows the option for AI 108 00:10:11.820 --> 00:10:17.400 And let's say we changed AI Actor and Player collision to Overlap 109 00:10:17.720 --> 00:10:24.240 Then when they collide, it is either Block or Overlap 110 00:10:24.240 --> 00:10:28.300 And between these, it prioritizes Overlap 111 00:10:29.820 --> 00:10:35.640 So to make it Block, both should be 112 00:10:37.220 --> 00:10:43.160 Ticked for Block so that it happens 113 00:10:44.241 --> 00:10:51.520 So the prioritization goes, Ignore first 114 00:10:51.520 --> 00:10:58.300 And then Overlap, and finally Block 115 00:11:01.221 --> 00:11:06.001 Let's remove our BP_CollisionTest Actor for now 116 00:11:06.981 --> 00:11:12.041 When AI Actor approaches Player Actor 117 00:11:12.041 --> 00:11:18.740 When they collide, let's destroy AI Actor 118 00:11:18.880 --> 00:11:23.584 And add an effect in that locationn 119 00:11:25.324 --> 00:11:31.181 So first, let's set things up for their collision 120 00:11:33.381 --> 00:11:37.921 Open BP_Player, add a Component 121 00:11:37.981 --> 00:11:43.281 At Add Component, search for Box 122 00:11:43.792 --> 00:11:46.893 And you get Box Collision 123 00:11:48.181 --> 00:11:50.961 Add this Box Collision 124 00:11:51.921 --> 00:11:56.061 Box Collision Component does not have its form 125 00:11:56.514 --> 00:11:59.234 It only has an area for collision 126 00:11:59.781 --> 00:12:04.601 So when we look at it at Viewport 127 00:12:04.606 --> 00:12:09.406 We see a yellow box here 128 00:12:10.581 --> 00:12:15.461 We could check for collision at an area 129 00:12:16.016 --> 00:12:18.256 That is identical to the form of the content 130 00:12:18.561 --> 00:12:23.582 Or we could make it a little bigger than 131 00:12:23.621 --> 00:12:26.301 This given area here to check for collision 132 00:12:27.661 --> 00:12:32.241 If we use it for this Collision at Static Mesh, it won't have such extra space 133 00:12:32.941 --> 00:12:37.621 So let's add Box Collision Component 134 00:12:38.041 --> 00:12:45.061 And to the right, at Shape, we have option for Box Extent 135 00:12:45.441 --> 00:12:48.401 This decides the width, length and height of it 136 00:12:48.543 --> 00:12:51.417 It is set as 32, 32 and 32 137 00:12:52.057 --> 00:12:56.077 Which is smaller than this cube here 138 00:12:56.817 --> 00:13:03.960 When we change it to 50, 50, 50, it is exactly the same 139 00:13:05.360 --> 00:13:09.480 For Static Mesh Cube, I think it was 100, 100, 100 140 00:13:09.480 --> 00:13:15.480 But here, we set Box Extent as 50, 50, 50 141 00:13:15.480 --> 00:13:19.560 And the size is identical 142 00:13:21.000 --> 00:13:25.050 If I want 100 for width 143 00:13:25.050 --> 00:13:29.420 You just set the half of that value 144 00:13:31.000 --> 00:13:36.380 If we want more space for collision check, we make this bigger 145 00:13:37.000 --> 00:13:43.100 Then, the form stays, but the collision area 146 00:13:43.100 --> 00:13:47.960 It gets bigger than the form itself 147 00:13:49.500 --> 00:13:54.040 For now, let's set the size the same, 50, 50, 50 148 00:13:55.280 --> 00:13:59.360 And this Box Collision Component 149 00:13:59.440 --> 00:14:05.480 Drag it to drop down at Default Scene Root 150 00:14:06.000 --> 00:14:12.000 Then this Box Collision Component becomes the top component 151 00:14:12.000 --> 00:14:18.000 And then we have its child, Static Mesh for form 152 00:14:20.000 --> 00:14:24.200 Now, it will collide with Box Collision 153 00:14:24.200 --> 00:14:27.000 As well as with Static Mesh 154 00:14:28.280 --> 00:14:32.400 So let's disable one of the two 155 00:14:32.400 --> 00:14:36.050 Choose Static Mesh Component 156 00:14:36.050 --> 00:14:43.060 At Collision tab, expand Collision Preset 157 00:14:43.060 --> 00:14:46.000 And set its preset as 'No Collision' 158 00:14:47.300 --> 00:14:51.650 All the menus at Collision Preset 159 00:14:51.650 --> 00:14:58.050 They are the saved values for option settings 160 00:14:58.050 --> 00:15:00.460 That Unreal has made for us in adavance 161 00:15:01.000 --> 00:15:05.100 So using 'No Collision' option makes 162 00:15:05.100 --> 00:15:10.320 Object Type as World Static, Collision Enabled as No Collision 163 00:15:10.320 --> 00:15:13.970 It means, whatever other setting is done 164 00:15:13.970 --> 00:15:19.000 With this component, there will be no collision processed 165 00:15:20.000 --> 00:15:24.350 Now next, choose Box Collision Component 166 00:15:24.350 --> 00:15:31.000 At Collision tab, expand on Collision Preset and make it Custom 167 00:15:32.000 --> 00:15:36.000 Let's keep our Collision Enabled 168 00:15:36.000 --> 00:15:42.000 Query Only, it only processes Overlaps 169 00:15:43.000 --> 00:15:48.740 And Collision Response, let's set it as Ignore for now 170 00:15:50.000 --> 00:15:53.700 Now, let's set Object Type 171 00:15:53.700 --> 00:15:58.950 Click on what says World Dynamic, and we see all the 172 00:15:58.950 --> 00:16:02.660 Default Object Types set by Unreal 173 00:16:04.000 --> 00:16:10.320 These are not enough for all object groups 174 00:16:11.000 --> 00:16:17.420 So we can make our own Object Type to set it here 175 00:16:18.000 --> 00:16:24.680 For that, go to Edit, Project Settings 176 00:16:26.000 --> 00:16:28.000 And we get this window 177 00:16:29.000 --> 00:16:35.580 To the left, at Engine, we have a menu called Collision 178 00:16:36.000 --> 00:16:43.700 Choose that menu, and at Object Channel 179 00:16:43.700 --> 00:16:47.240 We can set for Object Type 180 00:16:48.000 --> 00:16:52.560 To the right, click on New Object Channel 181 00:16:53.200 --> 00:16:55.740 And we get a small window like so 182 00:16:56.000 --> 00:16:59.820 Here, name it 'Player' 183 00:17:01.000 --> 00:17:05.500 And Default Response as Ignore 184 00:17:06.000 --> 00:17:11.720 Default Response means that whenever a new actor is spawned 185 00:17:12.000 --> 00:17:17.250 The response for Player will be Ignore 186 00:17:17.250 --> 00:17:19.260 That is the default setting we are adding 187 00:17:20.340 --> 00:17:22.040 And then click on 'Accept' 188 00:17:22.040 --> 00:17:26.600 And that's how we add the Object Type 189 00:17:28.360 --> 00:17:33.740 Close the window, back to BP_Player 190 00:17:34.000 --> 00:17:37.300 We need to compile it once 191 00:17:37.300 --> 00:17:40.060 To renew this Object Type list 192 00:17:40.300 --> 00:17:42.740 So compile now 193 00:17:44.000 --> 00:17:48.040 And click on Object Type to expand 194 00:17:48.040 --> 00:17:53.500 Now we see Player at the end 195 00:17:55.000 --> 00:17:57.680 So let's switch it into Player 196 00:17:59.080 --> 00:18:06.280 Here, at the end, it now has Ignore for 197 00:18:06.420 --> 00:18:09.420 Ignoring collision with Player object 198 00:18:10.620 --> 00:18:18.040 Why is it Ignore by default? It is because when we made our Player object type 199 00:18:18.040 --> 00:18:23.700 We set its default value as Ignore 200 00:18:24.500 --> 00:18:29.000 If we said Block there, when we compile 201 00:18:29.020 --> 00:18:35.580 This Player Collision Response option will have Block ticked in default 202 00:18:36.180 --> 00:18:42.720 Let's check that again when we set for AI Object Type later 203 00:18:44.360 --> 00:18:49.320 Let's now open BP_AIActor 204 00:18:50.000 --> 00:18:54.880 Same with Player, let's add a Collision Component 205 00:18:55.000 --> 00:19:02.940 Click on Add, and search for Sphere to get Sphere Collision 206 00:19:03.740 --> 00:19:06.380 Add Sphere Collision 207 00:19:07.660 --> 00:19:15.540 Let's drag Sphere Collision component into Default Scene Root 208 00:19:17.000 --> 00:19:21.660 Now, choose Static Mesh Component for the exterior form 209 00:19:22.000 --> 00:19:28.700 At Collision tab, click on Collision Preset, set as No Collision 210 00:19:30.000 --> 00:19:36.780 And back to Sphere Component, let's set for collision options 211 00:19:38.000 --> 00:19:40.940 Expand Collision Preset 212 00:19:41.840 --> 00:19:48.900 Overlap is now set as All Dynamic, so click on it to change to Custom 213 00:19:50.580 --> 00:19:53.580 Leave Collision Enabled as it is for now 214 00:19:53.580 --> 00:20:01.160 For Object Type, we will be making an AI Object Channel to set it as AI 215 00:20:02.880 --> 00:20:08.860 At the end here, Player is set as Ignore 216 00:20:11.000 --> 00:20:17.450 So, for Collision Response, check for Ignore so that 217 00:20:17.450 --> 00:20:23.020 It ignores all collisions for all object types 218 00:20:24.000 --> 00:20:30.900 And for this AI, let's make it Overlap with Player 219 00:20:31.660 --> 00:20:37.350 Then this AI Player will Overlap with any actors 220 00:20:37.350 --> 00:20:41.120 That have object type as Player 221 00:20:42.840 --> 00:20:46.840 Now, let's create the AI Object Type 222 00:20:47.000 --> 00:20:55.140 Edit, Project Settings, Engine, choose Collision 223 00:20:55.140 --> 00:21:00.060 At Object Channels, choose New Object Channel 224 00:21:01.340 --> 00:21:03.680 Let's name it AI 225 00:21:04.000 --> 00:21:08.820 Now, Default Response is Overlap 226 00:21:09.760 --> 00:21:11.760 And Accept 227 00:21:13.780 --> 00:21:15.380 Close the window 228 00:21:15.380 --> 00:21:22.220 Now, if we haven't compiled it, we see no AI under Object Type 229 00:21:22.440 --> 00:21:25.580 So compile 230 00:21:25.580 --> 00:21:32.500 And click on Object Type, and now we see AI at the end 231 00:21:34.140 --> 00:21:35.740 Choose AI 232 00:21:37.240 --> 00:21:42.760 And at the end, at Collision Response, we have AI added 233 00:21:42.760 --> 00:21:49.180 We chose Overlap as default, so we see Overlap as selected here 234 00:21:49.980 --> 00:21:54.380 Of course, at BP_Player, try and compile 235 00:21:54.380 --> 00:21:59.920 And we also see AI here, whose default setup is Overlap 236 00:22:02.620 --> 00:22:11.180 Now, at BP_AIActor, let's go to Collision Response and change AI option to Ignore 237 00:22:11.420 --> 00:22:15.560 This will make AI types overlap with each other 238 00:22:17.600 --> 00:22:21.820 That's it with the collision settings 239 00:22:22.780 --> 00:22:25.380 But when we play here 240 00:22:25.840 --> 00:22:30.060 It seems that they collide, but we do not get any cues, right? 241 00:22:30.360 --> 00:22:37.940 So let's print a sentence to tell us that there is a collision 242 00:22:39.300 --> 00:22:42.700 So at BP_Player Blueprint 243 00:22:43.087 --> 00:22:47.987 Choose Box Collision Component 244 00:22:47.987 --> 00:22:53.261 At Details, scroll down for Events 245 00:22:54.221 --> 00:22:59.540 Here, we have On Component Begin Overlap 246 00:22:59.540 --> 00:23:03.520 And a plus button 247 00:23:03.520 --> 00:23:06.120 Click on that button 248 00:23:06.120 --> 00:23:10.340 And where it allows for Event Graph and Blueprint Node 249 00:23:10.905 --> 00:23:13.585 We get another Event Node 250 00:23:14.326 --> 00:23:21.221 This Event Node runs automatically whenever this Overlap happens 251 00:23:22.361 --> 00:23:26.881 And in the list, we have Other Actor 252 00:23:27.081 --> 00:23:32.100 This Other Actor Pin contains BP_Player 253 00:23:32.156 --> 00:23:36.837 And the Actor it collides into 254 00:23:38.577 --> 00:23:44.961 So let's make it print the actor name that has collided into BP_Player 255 00:23:46.681 --> 00:23:51.701 So click over Other Actor Pin 256 00:23:51.841 --> 00:23:54.880 And search for Get Display 257 00:23:55.777 --> 00:24:00.237 And under Utilities, we have 'Get Display Name' 258 00:24:00.797 --> 00:24:03.781 Choose that node 259 00:24:05.181 --> 00:24:08.694 This node returns the actor name 260 00:24:09.769 --> 00:24:16.730 It returns this name at Outliner, at Actual Level 261 00:24:18.300 --> 00:24:25.680 So when BP_AIActor is the one, it will say 'BP_AIActor' here 262 00:24:26.640 --> 00:24:29.000 Let's add a node here 263 00:24:29.000 --> 00:24:35.000 Let's drag in Return Value and use Append 264 00:24:36.000 --> 00:24:42.000 Which means it adds more characters following this name 265 00:24:42.680 --> 00:24:45.760 Let's just say 'Collision with' 266 00:24:46.000 --> 00:24:50.220 'Collision with so-and-so, exclamation mark' 267 00:24:51.600 --> 00:24:57.000 Then the result of combining A and B will be at Return Value 268 00:24:58.000 --> 00:25:00.000 Let's print that 269 00:25:00.000 --> 00:25:06.750 Right click, Print String, and this final content 270 00:25:06.890 --> 00:25:10.140 Let's connect it to In String of Print String Node 271 00:25:11.000 --> 00:25:19.460 And whenever there is a collision, let's say that this Print String happens 272 00:25:21.000 --> 00:25:27.000 Compile, go to Actual Level, play 273 00:25:28.000 --> 00:25:36.700 When collision starts, we get 'Collision with BP_AIActor' 274 00:25:36.700 --> 00:25:38.440 As printed on the screen 275 00:25:40.000 --> 00:25:49.100 Choose Box Collision Component again, and this time go to On Component and Overlap 276 00:25:49.280 --> 00:25:54.240 Let's add this event using the plus button 277 00:25:55.000 --> 00:26:00.000 This is called when Overlap is over 278 00:26:01.420 --> 00:26:05.420 So Actor approaches, and when collision happens, what is being called? 279 00:26:06.000 --> 00:26:09.500 On Component Begin Overlap 280 00:26:10.420 --> 00:26:13.700 And now, it is in collision 281 00:26:14.000 --> 00:26:19.240 And what happens when the collision ends? 282 00:26:20.440 --> 00:26:24.120 On Component End Overlap is called 283 00:26:25.000 --> 00:26:35.800 Let's get these three nodes, copy and paste using Ctrl C and Ctrl V 284 00:26:36.000 --> 00:26:42.760 Let's print the same thing when On Component End Overlap is run 285 00:26:44.000 --> 00:26:49.000 Let's connect it to get name from Other Actor 286 00:26:50.000 --> 00:26:57.000 And then for B, 'End of Collision with so-and-so, exclamation mark' 287 00:26:59.000 --> 00:27:07.080 Compile, back to Actual Level, play; it is called for collision 288 00:27:07.080 --> 00:27:12.720 And also called when the collision ends 289 00:27:14.420 --> 00:27:16.800 Let's move to BP_AIActor 290 00:27:16.820 --> 00:27:21.060 See Sphere Collision Component here? 291 00:27:21.060 --> 00:27:27.940 Choose that component, scroll down Details and we have the same event here 292 00:27:28.660 --> 00:27:32.620 On Component Begin Overlap, let's add the event 293 00:27:33.660 --> 00:27:41.580 Same thing, from Other Actor, drag out to add Get Display Name 294 00:27:41.980 --> 00:27:47.480 Add Append Node and write 'Collision with' 295 00:27:47.480 --> 00:27:50.680 And print it 296 00:27:53.100 --> 00:27:55.100 Connect the Exec Pin 297 00:27:55.480 --> 00:27:59.180 Return Value, connect it to Print String 298 00:28:00.800 --> 00:28:05.440 Compile, and before we play it, let's think about it 299 00:28:05.940 --> 00:28:10.040 AI Actor and Player are in collision 300 00:28:11.200 --> 00:28:15.020 We made sure that this event at Player is called 301 00:28:16.100 --> 00:28:21.550 And we want to see whether the ones we just added, On Component Begin Overlap 302 00:28:21.550 --> 00:28:24.360 Also run as well 303 00:28:25.340 --> 00:28:31.740 Play, and collision with BP_Player 304 00:28:31.752 --> 00:28:37.572 And Collision with BP_AIActor; we have different things printed 305 00:28:39.133 --> 00:28:42.520 For BP_Player, what is this Other Actor? 306 00:28:42.794 --> 00:28:43.794 It is AI Actor 307 00:28:44.021 --> 00:28:48.681 That's why it prints 'Collision with AI Actor' 308 00:28:48.960 --> 00:28:54.400 And for this AI Actor, who is Other Actor of this On Component Begin Overlap? 309 00:28:54.640 --> 00:29:02.000 Player, right? That's why it prints 'Collision with Player' 310 00:29:03.000 --> 00:29:10.000 This shows us that we can get event from each for a collision of two things 311 00:29:11.560 --> 00:29:15.000 Same thing End Overlap 312 00:29:16.260 --> 00:29:19.880 Let's add On Component End Overlap 313 00:29:20.400 --> 00:29:24.060 And copy and paste these three nodes 314 00:29:25.000 --> 00:29:31.720 For Other Actor, for Get Display Name, choose Object 315 00:29:32.520 --> 00:29:36.520 And say 'End of Collision with so-and-so' 316 00:29:39.260 --> 00:29:41.860 And connect to the Exec Pin 317 00:29:42.000 --> 00:29:47.480 Compile, back to Actual Level, play 318 00:29:49.000 --> 00:29:56.000 We get two events of collision, and later 319 00:29:56.000 --> 00:29:58.960 Two events printed for end of collision 320 00:29:59.000 --> 00:30:03.900 Though, each has different name for to what it collides into 321 00:30:06.008 --> 00:30:09.158 Particles on Collision Location 322 00:30:09.781 --> 00:30:14.261 Now, let's add Particle for the collision location 323 00:30:14.841 --> 00:30:19.061 And destroy the AI Actor collided 324 00:30:20.361 --> 00:30:23.161 At BP_Player Blueprint 325 00:30:25.061 --> 00:30:30.900 Let's remove all the content for On Component Begin OVerlap 326 00:30:32.121 --> 00:30:36.461 ANd let's destroy this Other Actor that collided 327 00:30:36.941 --> 00:30:42.381 So over at Other Actor, click to drag 328 00:30:42.741 --> 00:30:47.861 And search for Destroy Actor 329 00:30:48.601 --> 00:30:53.641 And like so, we have Destroy Actor on top 330 00:30:53.641 --> 00:30:55.780 Add the node 331 00:30:56.861 --> 00:30:59.540 Then it connects automatically to Exec Pin 332 00:30:59.941 --> 00:31:01.681 And what does it mean? 333 00:31:02.221 --> 00:31:06.620 When Player collides into it, what do we do to that Actor? 334 00:31:06.799 --> 00:31:08.660 It destroys that Actor 335 00:31:09.601 --> 00:31:14.451 Compile and play 336 00:31:14.451 --> 00:31:16.961 And when they collide, it disappears 337 00:31:17.621 --> 00:31:21.761 It also disappears from this Outliner 338 00:31:23.521 --> 00:31:26.081 So in case of collision 339 00:31:26.437 --> 00:31:28.437 What if we want to destroy 340 00:31:28.621 --> 00:31:32.621 Both the Other Actor as well as Player itself? 341 00:31:33.161 --> 00:31:34.881 What do we do for that? 342 00:31:34.921 --> 00:31:41.881 Right click, add another Destroy Actor node 343 00:31:43.280 --> 00:31:45.980 And just connect the Exec Pin 344 00:31:48.080 --> 00:31:50.220 What does this node do? 345 00:31:51.000 --> 00:31:57.420 Destroy the Actor that collided into Player 346 00:32:01.000 --> 00:32:06.000 And the one after, destroy Player itself 347 00:32:09.000 --> 00:32:12.000 The one that destroys me has 'Self' as the target 348 00:32:12.000 --> 00:32:14.000 Meaning, destroying me or Player 349 00:32:14.000 --> 00:32:18.340 And destroying the actor that collides has 'Other Actor' set here 350 00:32:18.340 --> 00:32:21.000 Meaning, destroy Other Actor 351 00:32:22.620 --> 00:32:25.320 We had something similar to this before 352 00:32:25.460 --> 00:32:34.560 At BP_AIActor, we had importing location of Player at Begin Play 353 00:32:35.580 --> 00:32:41.760 This target could be either Self or other Actor 354 00:32:42.600 --> 00:32:49.880 And that made a difference in whose location it imported 355 00:32:51.800 --> 00:32:56.220 And the same thing is happening here 356 00:32:57.000 --> 00:33:03.960 Compile, at Actual Level, play and in collision 357 00:33:04.000 --> 00:33:09.000 We see both actors disappearing 358 00:33:10.620 --> 00:33:14.000 Let's modify this same action a little 359 00:33:14.000 --> 00:33:20.000 Let's snap this collision part 360 00:33:21.000 --> 00:33:23.000 And move it upward 361 00:33:23.560 --> 00:33:29.000 And let's have on Component Begin Overlap just destroy me 362 00:33:30.000 --> 00:33:32.000 Compile 363 00:33:32.000 --> 00:33:35.000 And at BP_AIActor 364 00:33:37.000 --> 00:33:42.380 Let's remove the connected node to On Component Begin Overlap 365 00:33:43.000 --> 00:33:48.560 Right click anywhere, add a Destroy Actor node 366 00:33:48.560 --> 00:33:53.500 And let's set target as self here 367 00:33:55.000 --> 00:33:58.720 Compile, and what happens? 368 00:33:59.000 --> 00:34:03.620 When Player collides, this is called; it destroys me 369 00:34:04.000 --> 00:34:08.000 And for AI, the same node runs 370 00:34:08.000 --> 00:34:10.000 So it destroys this another self 371 00:34:12.000 --> 00:34:16.000 So we can see that it again destroys both 372 00:34:17.000 --> 00:34:22.000 So whether to process it all at once 373 00:34:22.000 --> 00:34:25.000 Or at each other's part 374 00:34:25.000 --> 00:34:28.340 That's a decision you should make for your working environment 375 00:34:30.000 --> 00:34:35.000 Let me change it back here so that everything is processed at Player's end 376 00:34:36.000 --> 00:34:40.640 Remove Destroy Actor at BP_AIActor 377 00:34:41.000 --> 00:34:44.400 Back to Player, and in between 378 00:34:47.000 --> 00:34:51.000 Connect this Other Actor destroying node 379 00:34:51.000 --> 00:34:54.000 And connect that with the one that destroys Player 380 00:34:56.000 --> 00:35:01.580 Let's remove On Component End Overlap 381 00:35:02.000 --> 00:35:06.600 We just need to get event for the beginning 382 00:35:06.600 --> 00:35:09.700 So we will just leave our Begin Overlap node 383 00:35:11.000 --> 00:35:14.000 Remember how we talked about the node Sequence last time? 384 00:35:14.000 --> 00:35:17.000 We will also be using Sequence here 385 00:35:17.000 --> 00:35:20.460 To section them in order 386 00:35:22.280 --> 00:35:25.240 Let's disconnect the Exec node 387 00:35:27.260 --> 00:35:32.160 Right click, search for Sequence 388 00:35:32.460 --> 00:35:34.380 Add a Sequence node 389 00:35:36.460 --> 00:35:39.460 Connect Exec Pin to Sequence 390 00:35:39.460 --> 00:35:43.620 First, we need to connect it to 391 00:35:43.640 --> 00:35:46.780 'Then 0' of our destroy-other-actor node 392 00:35:47.000 --> 00:35:52.000 And for destroy-me node, connect to 'Then 1' 393 00:35:53.000 --> 00:35:56.660 So this will be number 0 and number 1 394 00:35:59.000 --> 00:36:02.000 Now, when in collision, they are destroyed 395 00:36:02.000 --> 00:36:05.000 And what happens is 396 00:36:05.000 --> 00:36:10.580 To this location of AI Actor in collision 397 00:36:11.000 --> 00:36:14.000 We will add an effect 398 00:36:15.000 --> 00:36:18.000 Which in Unreal is called a Particle 399 00:36:20.000 --> 00:36:25.000 So under Content Browser, next to Content Folder 400 00:36:25.000 --> 00:36:27.000 See Startup Content? 401 00:36:27.000 --> 00:36:30.000 We have a Particles folder there 402 00:36:30.000 --> 00:36:34.000 And in that folder 403 00:36:34.000 --> 00:36:38.000 We have some sample Partilces 404 00:36:38.000 --> 00:36:42.000 Here, let's add this P-Explosion effect 405 00:36:42.000 --> 00:36:45.000 To be displayed on screen 406 00:36:45.000 --> 00:36:47.280 Double click on it 407 00:36:47.580 --> 00:36:49.720 To get a preview 408 00:36:50.280 --> 00:36:52.280 Let's close that 409 00:36:53.000 --> 00:36:56.000 Back to BP_Player 410 00:36:56.000 --> 00:36:58.000 Right click 411 00:36:58.000 --> 00:37:01.000 Spawn Emitter 412 00:37:04.000 --> 00:37:06.540 We have a node called At Location 413 00:37:06.540 --> 00:37:10.000 Choose that node 414 00:37:10.720 --> 00:37:13.840 And choose Add Pin of Sequence 415 00:37:14.000 --> 00:37:15.940 So that Then 2 416 00:37:16.700 --> 00:37:19.980 Let's connect it to Spawn Emitter at Location 417 00:37:22.000 --> 00:37:25.000 And see this first in the list? 418 00:37:25.000 --> 00:37:28.000 Emitter Template 419 00:37:28.000 --> 00:37:32.000 Click on selection Action of it 420 00:37:32.000 --> 00:37:36.000 And we see all the list of Particles we saw before 421 00:37:36.000 --> 00:37:40.000 And here, we said we are using 422 00:37:40.000 --> 00:37:42.000 P-Explosion 423 00:37:42.000 --> 00:37:45.000 So let's select that 424 00:37:46.000 --> 00:37:49.000 And Location means 425 00:37:49.000 --> 00:37:51.440 Where we are going to show 426 00:37:51.440 --> 00:37:54.400 This Particle on screen 427 00:37:54.400 --> 00:37:57.180 And we can choose the location 428 00:37:57.180 --> 00:37:59.300 Of where AI Actor is getting destroyed 429 00:38:00.440 --> 00:38:04.440 So let's drag it from Other Actor Pin 430 00:38:05.000 --> 00:38:10.000 And search for 'Get Actor Location' 431 00:38:10.000 --> 00:38:12.560 To add a node 432 00:38:12.560 --> 00:38:16.200 And connect that value to Location here 433 00:38:18.000 --> 00:38:20.000 As we change to Sequence 434 00:38:20.000 --> 00:38:22.440 We just left that other-actor-destroying part 435 00:38:22.440 --> 00:38:26.000 And its target as 'Self' 436 00:38:27.000 --> 00:38:32.000 We had 'Other Actor' connected before 437 00:38:35.000 --> 00:38:38.000 Compile, and at Actual Level 438 00:38:38.000 --> 00:38:39.780 Let's play 439 00:38:39.780 --> 00:38:43.680 It is destroyed but there is no Particle 440 00:38:43.700 --> 00:38:45.280 Let's pause 441 00:38:45.280 --> 00:38:47.560 And we get an error message 442 00:38:48.120 --> 00:38:50.120 This is because 443 00:38:50.520 --> 00:38:52.440 The order is not right 444 00:38:53.140 --> 00:38:56.140 We destroy Other Actor 445 00:38:56.380 --> 00:38:57.380 So it is destroyed 446 00:38:57.760 --> 00:39:01.640 So it is not in Outliner anymore, it is gone 447 00:39:01.840 --> 00:39:04.600 And what are we doing after that? 448 00:39:06.220 --> 00:39:09.720 We are adding a Particle 449 00:39:10.000 --> 00:39:12.000 Where on the screen? 450 00:39:12.000 --> 00:39:15.000 To the location of Other Actor 451 00:39:15.000 --> 00:39:18.000 So, even before Spawn Emitter at Location node 452 00:39:18.000 --> 00:39:20.000 Runs at all 453 00:39:20.000 --> 00:39:22.000 Other Actor is already gone 454 00:39:22.000 --> 00:39:24.000 That's why 455 00:39:24.000 --> 00:39:26.000 It has no idea what Other Actor is 456 00:39:26.000 --> 00:39:28.000 Because it is destroyed 457 00:39:28.000 --> 00:39:32.000 That's why we get an error and the Particle does not work 458 00:39:33.760 --> 00:39:36.000 Then what do we do? 459 00:39:36.000 --> 00:39:40.000 We should first show the effect 460 00:39:40.000 --> 00:39:44.000 And then destroy Other Actor 461 00:39:44.000 --> 00:39:46.000 This is a very important point here 462 00:39:46.000 --> 00:39:49.460 Whenever you work with these nodes 463 00:39:49.460 --> 00:39:52.360 You need to think about 464 00:39:52.380 --> 00:39:56.000 What should come first 465 00:39:56.000 --> 00:40:00.000 So right click on Then 2 466 00:40:00.000 --> 00:40:03.000 And Remove 467 00:40:03.000 --> 00:40:06.000 We can just create one more 468 00:40:06.000 --> 00:40:08.000 Before Then 0 469 00:40:08.000 --> 00:40:11.000 So right click on Then 0 470 00:40:11.000 --> 00:40:15.000 And see Insert Execution Pin Before? 471 00:40:15.000 --> 00:40:17.000 Select that menu 472 00:40:17.000 --> 00:40:19.000 And it will create another Exec Pin 473 00:40:19.000 --> 00:40:22.520 Before the current location 474 00:40:22.520 --> 00:40:26.000 Below means it will be positioned later 475 00:40:26.000 --> 00:40:28.000 For us, we need it before 476 00:40:28.000 --> 00:40:31.000 So choose Before 477 00:40:31.000 --> 00:40:34.440 And the ones after are 478 00:40:34.440 --> 00:40:36.000 Now Then 1 and Then 2 479 00:40:36.000 --> 00:40:38.220 And we get a new Then 0 480 00:40:38.760 --> 00:40:40.720 So this part now goes to 481 00:40:40.720 --> 00:40:45.000 Spawn Emitter at Location 482 00:40:45.000 --> 00:40:48.000 Let's reorganize the nodes 483 00:40:49.720 --> 00:40:52.720 I've set the nodes like so 484 00:40:53.000 --> 00:40:55.000 Let's compile 485 00:40:55.000 --> 00:40:57.000 Back to Actual Level 486 00:40:57.000 --> 00:40:59.000 And Play 487 00:40:59.000 --> 00:41:01.000 For every collision now 488 00:41:01.000 --> 00:41:05.000 We see an effect 489 00:41:05.000 --> 00:41:07.000 Let's summarize 490 00:41:07.000 --> 00:41:09.000 What we learned today 491 00:41:09.000 --> 00:41:11.000 First, we learned about 492 00:41:11.000 --> 00:41:13.000 How to set things up for a collision 493 00:41:13.000 --> 00:41:16.000 We also learned about 494 00:41:16.000 --> 00:41:20.000 How to change Object Channel to make it collide into a certain actor 495 00:41:20.000 --> 00:41:23.000 We also used Collision Preset 496 00:41:23.000 --> 00:41:25.000 So that we can change all collision options 497 00:41:25.000 --> 00:41:27.000 At once 498 00:41:27.000 --> 00:41:29.000 And we also learned to add 499 00:41:29.000 --> 00:41:31.000 A Particle effect for 500 00:41:31.000 --> 00:41:34.000 An actor collision 501 00:41:34.564 --> 00:41:35.721 Getting Event for Actor Collision Make it collide with a particular actor with Object Channel setting 502 00:41:35.721 --> 00:41:36.688 Blueprint Class - Actor - Add Static Mesh Component Static Mesh - Details - Expand Collision Preset 503 00:41:36.688 --> 00:41:37.688 Physics - Tick Simulate Physics - Tick Enable Gravity - Compile and save 504 00:41:37.792 --> 00:41:38.792 Ignore, Overlap, and Block for Object Response 505 00:41:38.903 --> 00:41:39.903 Edit - Project Settings - Engine - Collision - Object Channels - Object Type 506 00:41:40.021 --> 00:41:41.021 Using Collision Preset to change all collision options at once - Add Collision Component - Search for and add Sphere Collision 507 00:41:41.143 --> 00:41:42.143 Name change for actor : Other Actor - Search for Get Display - Utilities - Get Display Name 508 00:41:42.195 --> 00:41:43.195 Call Message for Beginning and End of Actor : On Component Begin/End Overlap 509 00:41:43.262 --> 00:41:44.262 Each actor can get event for the collision event 510 00:41:44.395 --> 00:41:45.395 Adding Particle for Collision Location How to add Particle effect for Actor collision 511 00:41:45.440 --> 00:41:46.440 Drag in Other Actor, search for Destroy Actor Particle: Effect for that collision event 512 00:41:46.452 --> 00:41:47.452 Content Browser - Content - Starter Content - Particles 513 00:41:47.515 --> 00:41:48.515 Choose Spawn Emitter at Location Node, Location to choose where to add the effect 514 00:41:48.589 --> 00:41:49.589 Make sure what comes first when creating nodes