1 00:00:23.600 --> 00:00:30.231 Hello, this is Kim Hyun-Jin, and I'm in charge of Unreal Engine Basics for Immersive Contents 2 00:00:30.232 --> 00:00:36.670 Today, we will learn about how to spawn an actor after a certain amount of time passes 3 00:00:37.020 --> 00:00:41.565 To decide whether that time has passed, we will be learning about 4 00:00:41.900 --> 00:00:45.250 How to use Set Time Node and Delay Node 5 00:00:45.476 --> 00:00:48.876 Spawning Actor After A Certain Time 6 00:00:49.548 --> 00:00:54.748 Let's learn about spawning an actor after a certain time 7 00:00:55.663 --> 00:00:58.413 First, let's create a new Blueprint class 8 00:00:59.100 --> 00:01:01.250 Go to Content Browser 9 00:01:02.083 --> 00:01:03.983 Right click 10 00:01:04.600 --> 00:01:07.150 Choose 'Blueprint Class' 11 00:01:07.151 --> 00:01:09.851 Let's choose 'Actor' 12 00:01:10.687 --> 00:01:13.087 Let's name it 13 00:01:15.421 --> 00:01:18.521 BP_AIActorManager 14 00:01:22.964 --> 00:01:25.214 Double click to open it 15 00:01:27.042 --> 00:01:28.392 For this actor 16 00:01:31.269 --> 00:01:39.677 Let's make it spawn an AI Actor 17 00:01:42.071 --> 00:01:44.621 After a certain amount of time passes 18 00:01:46.275 --> 00:01:48.775 In order to realize this 19 00:01:49.647 --> 00:01:54.797 We need to start with the concept of Delta Seconds 20 00:01:56.825 --> 00:02:00.476 Delta Seconds mean the amount of time needed 21 00:02:00.987 --> 00:02:04.737 Whenever we call an Event Tick Node 22 00:02:06.725 --> 00:02:09.775 Say, we clicked on 'Play' just now 23 00:02:10.746 --> 00:02:13.446 Then this will call our Tick events several times, right? 24 00:02:14.370 --> 00:02:17.120 This Tick event is called once 25 00:02:17.581 --> 00:02:19.881 And the second Tick 26 00:02:19.881 --> 00:02:22.781 Let's say this took 0.1 second 27 00:02:23.675 --> 00:02:26.125 And it is called again 28 00:02:26.458 --> 00:02:30.258 And this is also another 0.1 second 29 00:02:32.175 --> 00:02:34.125 The same 0.1 here 30 00:02:35.225 --> 00:02:39.225 Then, at this point, for this Tick event 31 00:02:40.098 --> 00:02:42.898 How much time has passed since the start? 32 00:02:44.325 --> 00:02:46.575 0.1 second, and three times, right? 33 00:02:47.766 --> 00:02:50.916 Meaning, 0.3 seconds, correct? 34 00:02:56.425 --> 00:03:02.590 So, when we spawn an actor after a certain time 35 00:03:03.275 --> 00:03:06.075 This accumulates these Delta Seconds 36 00:03:06.075 --> 00:03:08.575 And once it hits the set number 37 00:03:08.575 --> 00:03:11.675 Than this spawns an actor 38 00:03:12.669 --> 00:03:16.869 For example, let's say that after every 0.5 second 39 00:03:16.869 --> 00:03:20.120 We will spawn one AI Actor 40 00:03:20.613 --> 00:03:22.413 So when we press 'Start' 41 00:03:22.413 --> 00:03:29.125 Tick Event goes, once, twice, three times, four, five, six times 42 00:03:29.125 --> 00:03:33.925 The spawning happens whenever this is called 43 00:03:33.925 --> 00:03:34.625 Why is that? 44 00:03:35.025 --> 00:03:36.025 It's because every 0.1 second is 45 00:03:36.026 --> 00:03:38.026 One, two, three, four, five 46 00:03:38.126 --> 00:03:41.627 In total, 0.5 second has accumulated 47 00:03:41.627 --> 00:03:48.512 So this will spawn an AI Actor, once 48 00:03:49.275 --> 00:03:50.875 And then 49 00:03:50.999 --> 00:03:56.039 After five times of this 50 00:03:57.725 --> 00:04:04.373 This will again spawn an AI Actor 51 00:04:06.125 --> 00:04:10.375 For a movement, we say vt, and this value t 52 00:04:10.627 --> 00:04:13.059 This means we multiply it by Delta Seconds, right? 53 00:04:13.059 --> 00:04:16.239 Let me explain why we multiply this 54 00:04:16.825 --> 00:04:20.125 Let's say we have a great computer 55 00:04:25.985 --> 00:04:29.685 This computer, whenever it processes something 56 00:04:29.823 --> 00:04:34.773 Let's say it can process something four times in a second 57 00:04:37.025 --> 00:04:39.325 Now we have a bad computer 58 00:04:47.987 --> 00:04:53.537 This bad computer, in the same duration of a second 59 00:04:54.025 --> 00:04:57.775 Let's say it can process something twice 60 00:05:00.462 --> 00:05:06.062 And let's say that we're processing a movement 61 00:05:07.125 --> 00:05:09.375 And when this processes it once 62 00:05:10.025 --> 00:05:15.025 This code will make a character move by a meter 63 00:05:16.375 --> 00:05:22.075 Then, this great computer will call this movement by a meter four times, right? 64 00:05:22.675 --> 00:05:24.975 Then how far has the character moved? 65 00:05:25.625 --> 00:05:26.875 Four meters in total 66 00:05:28.525 --> 00:05:34.125 And this bad computer, since it runs the same code 67 00:05:34.125 --> 00:05:39.075 It makes the character move a meter whenever it processes the code once 68 00:05:39.075 --> 00:05:40.341 Same one meter 69 00:05:41.573 --> 00:05:42.473 Then what happens? 70 00:05:42.473 --> 00:05:46.475 After a second, this character moves two meters 71 00:05:47.375 --> 00:05:54.075 Then here, whether it is a great or a bad computer, with the same program 72 00:05:55.025 --> 00:05:58.525 With a great computer, the character moves more 73 00:05:58.525 --> 00:05:59.325 In the same duration of time 74 00:05:59.375 --> 00:06:01.414 And for the bad computer, it moves less 75 00:06:01.664 --> 00:06:05.611 Then this program is a very unfair one 76 00:06:07.304 --> 00:06:09.204 Therefore, despite differences in capability 77 00:06:09.204 --> 00:06:13.861 All characters should move a certain amount if given the same amount of time 78 00:06:15.375 --> 00:06:17.425 Which means, let's try this 79 00:06:19.152 --> 00:06:22.552 We said a great computer processes this four times in a second 80 00:06:22.553 --> 00:06:26.786 This means that processing it once takes 0.25 seconds 81 00:06:27.625 --> 00:06:29.325 0.25 seconds 82 00:06:34.368 --> 00:06:38.668 While this bad computer takes 0.5 second each 83 00:06:41.447 --> 00:06:43.597 So to this distance being traveled 84 00:06:43.638 --> 00:06:46.338 Let's multiply it by this time that each process takes 85 00:06:47.283 --> 00:06:50.183 And then let's try adding all the values 86 00:06:50.533 --> 00:06:52.800 Then, for a great computer 87 00:06:53.650 --> 00:06:57.900 You will get 0.25 for each 88 00:06:59.850 --> 00:07:01.100 And once you add them all up 89 00:07:03.500 --> 00:07:05.750 The final result is 1 90 00:07:06.450 --> 00:07:10.050 Let's do the same for our bad computer 91 00:07:10.051 --> 00:07:15.700 Then this becomes 0.5 and 0.5, when summed it's also 1 92 00:07:16.800 --> 00:07:19.850 This will make sure that both move a meter 93 00:07:20.400 --> 00:07:21.400 It's the same now, see? 94 00:07:24.200 --> 00:07:27.400 What of this procedure made them the same? 95 00:07:27.950 --> 00:07:33.800 It's when we multiplied the time duration for each process 96 00:07:36.200 --> 00:07:38.650 So what is this time duration in other words? 97 00:07:39.250 --> 00:07:41.400 It is Delta Seconds 98 00:07:44.500 --> 00:07:47.951 So, when we move an AI Actor 99 00:07:49.865 --> 00:07:52.465 We multiply it by Delta Seconds 100 00:07:52.925 --> 00:07:57.923 In order to make the movement exactly same for all computers 101 00:07:58.207 --> 00:08:04.305 Same thing, for Player, we want to make it move the same for all computers 102 00:08:04.315 --> 00:08:07.181 That's why we multiplied by Delta Seconds here as well 103 00:08:10.575 --> 00:08:17.925 So, let's use Delta Seconds to check for our time duration 104 00:08:18.025 --> 00:08:20.569 And then spawn an Actor 105 00:08:23.082 --> 00:08:26.132 First, let's create two variables 106 00:08:26.593 --> 00:08:29.393 At VARIABLES, click on the plus button 107 00:08:30.386 --> 00:08:32.136 And its name, let's say 108 00:08:33.625 --> 00:08:35.225 'CreateTime' 109 00:08:36.425 --> 00:08:40.175 Data type is 'Float' 110 00:08:41.225 --> 00:08:44.425 And then, VARIABLES, plus button again 111 00:08:45.247 --> 00:08:47.797 Let's name this 'CurrentTime' 112 00:08:50.375 --> 00:08:53.475 Data type, same thing, let's say 'Float' 113 00:08:54.425 --> 00:08:59.025 Compile, and let's choose our CreateTime 114 00:08:59.725 --> 00:09:03.775 And set its default value as 1 115 00:09:05.725 --> 00:09:07.925 This CreateTime variable 116 00:09:08.825 --> 00:09:11.525 Does its job at a certain time 117 00:09:11.525 --> 00:09:17.071 And this means that an Actor will be spawned once in every second 118 00:09:19.725 --> 00:09:25.125 At Event Tick Node, we will accumulate the time 119 00:09:26.975 --> 00:09:31.525 Let's drag Delta Seconds, and plus 120 00:09:34.775 --> 00:09:37.575 Drag in CurrentTime at our left 121 00:09:38.425 --> 00:09:39.425 And bring it here using 'get' 122 00:09:41.775 --> 00:09:44.825 Now, let's add this value 123 00:09:45.775 --> 00:09:49.925 Next, again, drag in CurrentTime 124 00:09:49.925 --> 00:09:51.775 This time, use 'set' to bring it 125 00:09:53.525 --> 00:09:57.325 Then, this value, which is a sum of Delta Seconds and CurrentTime 126 00:09:57.325 --> 00:10:00.325 This value goes into CurrentTime again 127 00:10:00.975 --> 00:10:03.275 Now it runs this 128 00:10:05.025 --> 00:10:10.775 Let's say that the value for Delta Seconds is 0.5 129 00:10:11.175 --> 00:10:13.675 CurrentTime starts with 0, correct? 130 00:10:13.676 --> 00:10:15.775 Add the two, and what do we have? 131 00:10:16.375 --> 00:10:17.975 We have 0.5 132 00:10:17.976 --> 00:10:19.776 And this 0.5 goes where? 133 00:10:19.776 --> 00:10:24.575 It goes back to CurrentTime 134 00:10:26.625 --> 00:10:29.925 Then, when the Tick Event is called again 135 00:10:30.725 --> 00:10:33.525 CurrentTime now is not 0, what is it? 136 00:10:33.526 --> 00:10:35.180 It becomes 0.5 137 00:10:35.425 --> 00:10:38.375 So when wee add it to Delta Seconds, it becomes 1 138 00:10:39.125 --> 00:10:41.725 So, again, CurrentTime becomes 139 00:10:42.925 --> 00:10:45.425 This value 1 140 00:10:47.675 --> 00:10:51.492 And when another Event Tick runs 141 00:10:51.925 --> 00:10:55.075 CurrentTime, because it's now 1, not 0.5, 142 00:10:55.643 --> 00:10:57.643 It will add 1 with 0.5 143 00:10:57.644 --> 00:11:01.026 Which makes CurrentTime 1.5 again 144 00:11:03.932 --> 00:11:09.206 So this keeps accumulating Delta Seconds to count time 145 00:11:11.162 --> 00:11:13.112 Let's try and print this as well 146 00:11:13.113 --> 00:11:17.325 Right click, 'Print String' 147 00:11:18.549 --> 00:11:20.249 And connect to the Execution Pin 148 00:11:20.250 --> 00:11:26.193 And CurrentTime, with the value it has, add Instring, compile 149 00:11:26.725 --> 00:11:28.125 Moving back to Action Level 150 00:11:29.075 --> 00:11:32.075 Let's drag in our BP_AIActorManager 151 00:11:33.725 --> 00:11:36.425 And place it at the Viewport 152 00:11:37.225 --> 00:11:39.025 Make sure this Output Log window 153 00:11:39.825 --> 00:11:41.875 Is visible over here 154 00:11:44.125 --> 00:11:46.075 When we press 'Play' 155 00:11:48.075 --> 00:11:48.875 1 156 00:11:48.876 --> 00:11:49.625 2 157 00:11:49.626 --> 00:11:50.475 3 158 00:11:50.476 --> 00:11:51.422 4 159 00:11:51.423 --> 00:11:52.024 5 160 00:11:52.024 --> 00:11:55.416 It looks as if it is going in real time 161 00:11:55.417 --> 00:11:57.770 The value matches the flow of time in reality 162 00:12:00.623 --> 00:12:02.473 So, what does this part do? 163 00:12:03.625 --> 00:12:08.178 It allows time to pass 164 00:12:10.975 --> 00:12:13.875 And then, this CurrentTime value 165 00:12:14.875 --> 00:12:17.520 It determines if this is bigger than 1 166 00:12:17.670 --> 00:12:21.870 Meaning, if it is bigger than this CreateTime value 167 00:12:22.075 --> 00:12:23.075 What does that mean? 168 00:12:24.175 --> 00:12:26.125 It means that a second has passed 169 00:12:27.725 --> 00:12:31.625 Drag in this CurrentTime 170 00:12:31.626 --> 00:12:37.002 And add a sign to ask if the left is bigger, select 'Greater' 171 00:12:39.675 --> 00:12:45.575 And then drag in CreateTime variable in our left by using 'get' 172 00:12:46.775 --> 00:12:51.125 So this compares the values of CurrentTime and CreateTime 173 00:12:53.575 --> 00:12:54.975 And then we ask 174 00:12:54.976 --> 00:12:57.625 If CurrentTime value is 175 00:12:58.225 --> 00:13:00.775 Bigger than that of CreateTime 176 00:13:00.775 --> 00:13:02.275 Then this becomes True 177 00:13:03.375 --> 00:13:07.075 If it is less, it returns False 178 00:13:07.925 --> 00:13:10.125 So we ask this, with what? 179 00:13:10.126 --> 00:13:11.259 With an if statement 180 00:13:11.417 --> 00:13:16.829 So, right click and search for 'if' and you will get a node called 'Branch' 181 00:13:16.866 --> 00:13:18.903 Add this node 182 00:13:21.575 --> 00:13:25.025 And this compared value goes to this Condition 183 00:13:26.075 --> 00:13:30.375 Then, with these two values, we arrive at either True or False 184 00:13:31.258 --> 00:13:34.758 Let's have this Branch run 185 00:13:37.425 --> 00:13:38.425 What does this mean? 186 00:13:39.825 --> 00:13:40.825 It means, if 187 00:13:44.575 --> 00:13:47.025 If a second has passed 188 00:13:47.742 --> 00:13:48.742 Which is this, right? 189 00:13:50.175 --> 00:13:51.175 And here 190 00:13:51.626 --> 00:13:56.683 I said 'a second' because the default value for CreateTime is 1 191 00:13:56.683 --> 00:14:00.113 If it is 2, that means 'if two seconds have passed' 192 00:14:02.364 --> 00:14:04.064 When this is True, right? 193 00:14:04.065 --> 00:14:06.506 If this is True, what do we do? 194 00:14:06.507 --> 00:14:08.925 We create an Actor 195 00:14:08.925 --> 00:14:11.408 If False, we don't do anything 196 00:14:12.650 --> 00:14:15.600 This time, let's right click and 197 00:14:15.600 --> 00:14:23.300 Add a node called 'Spawn Actor from Class' 198 00:14:26.400 --> 00:14:30.100 Let's connect it so that it runs when True 199 00:14:31.950 --> 00:14:34.850 We have this first class Item here 200 00:14:34.850 --> 00:14:36.900 Click on 'Select Class' 201 00:14:36.900 --> 00:14:44.850 And this will show us all the Blueprint classes we created, as well as the default classes at Unreal 202 00:14:45.295 --> 00:14:48.895 So what class are we trying to create? 203 00:14:49.100 --> 00:14:51.400 It is BP_AIActor 204 00:14:51.401 --> 00:14:57.091 So let's search for BP_AIActor and we have it here 205 00:14:57.650 --> 00:14:59.900 Select BP_AIActor 206 00:15:01.850 --> 00:15:04.350 Second, 'Spawn Tranform' 207 00:15:05.150 --> 00:15:07.250 It asks, when creating this Actor 208 00:15:07.251 --> 00:15:14.847 What location, rotation value, and scale value it will have 209 00:15:16.350 --> 00:15:21.350 So now, let's spawn it at where AI Actor Manager is 210 00:15:21.350 --> 00:15:27.650 And for size and rotation, let's keep it default 211 00:15:28.650 --> 00:15:34.550 For BP_AIManager, size and rotation are set as default 212 00:15:34.551 --> 00:15:40.341 Only the location changes, since we place it at the Actor Level 213 00:15:40.342 --> 00:15:43.261 So all we need is its location value 214 00:15:44.750 --> 00:15:49.500 So right click on this 'Spawn Transform' pin 215 00:15:50.000 --> 00:15:53.250 And select the menu 'Split Struct Pin' 216 00:15:53.351 --> 00:15:57.401 Like so here, Location, Rotation, and Scale 217 00:15:57.401 --> 00:16:00.801 We can put in values for each of them 218 00:16:02.550 --> 00:16:08.250 Here, we just need to set Location for that of our AI Manager 219 00:16:08.500 --> 00:16:10.150 So, right click 220 00:16:10.850 --> 00:16:14.900 Add 'Get Actor Location' node 221 00:16:16.200 --> 00:16:22.450 And then, this value will be connected to our Spawn Transform, or the location part 222 00:16:24.050 --> 00:16:25.200 What does this mean? 223 00:16:26.650 --> 00:16:28.700 It means, let's spawn 224 00:16:32.049 --> 00:16:33.049 BP_AIActor 225 00:16:36.319 --> 00:16:37.819 And where? 226 00:16:37.819 --> 00:16:40.369 At BP_AIActor 227 00:16:40.369 --> 00:16:41.419 At Manager 228 00:16:45.651 --> 00:16:46.651 At Location 229 00:16:49.501 --> 00:16:51.501 Let's compile 230 00:16:51.501 --> 00:16:53.251 Let's move to our Actual Level 231 00:16:54.201 --> 00:16:57.701 Let's remove this BP_AIActor now 232 00:16:58.631 --> 00:17:00.731 Let's try and play now 233 00:17:00.731 --> 00:17:04.401 When we play, it keeps adding itself, right? 234 00:17:05.901 --> 00:17:11.151 It is spawning, but not once every second, it keeps coming 235 00:17:13.351 --> 00:17:15.151 This is happening because 236 00:17:16.257 --> 00:17:18.708 We've accumulated CreateTime 237 00:17:18.708 --> 00:17:21.701 Let's say it is now at 1.2 seconds mark 238 00:17:22.313 --> 00:17:25.413 Then, since it's greater than CreateTime 239 00:17:26.001 --> 00:17:30.851 This statement becomes True, and it spawns an Actor 240 00:17:33.851 --> 00:17:36.251 And it goes back here 241 00:17:37.701 --> 00:17:41.201 And what is CreateTime at this point? 242 00:17:41.201 --> 00:17:42.351 It is 1.2 seconds 243 00:17:43.603 --> 00:17:46.553 Now, let's say we added more Delta Seconds 244 00:17:46.553 --> 00:17:49.803 And that it is now bigger than 1.2, which is 1.3 seconds 245 00:17:51.449 --> 00:17:54.599 Then, now, it is greater than CreateTime again 246 00:17:55.501 --> 00:17:57.001 So it is being spawned again 247 00:17:58.001 --> 00:18:00.801 Instead of waiting for another second, it just spawns again 248 00:18:00.801 --> 00:18:03.351 It only waits for the initial second 249 00:18:03.351 --> 00:18:09.087 And then it keeps spawning without waiting 250 00:18:10.474 --> 00:18:11.724 What do we do for this? 251 00:18:13.351 --> 00:18:16.101 After spawning BP_AIActor 252 00:18:16.101 --> 00:18:20.951 We need to reset CurrentTime that has counted time back to 0 253 00:18:22.851 --> 00:18:26.301 Now, bring in CurrentTime at our left 254 00:18:26.901 --> 00:18:28.151 By using 'set' 255 00:18:28.801 --> 00:18:33.101 And then we just put in the value 0 for CurrentTime 256 00:18:34.601 --> 00:18:37.701 So that it runs this 257 00:18:38.401 --> 00:18:39.401 'Accumulated Time' 258 00:18:41.401 --> 00:18:42.401 'Reset' 259 00:18:46.184 --> 00:18:50.434 Compile, and at the Actual Level 260 00:18:50.434 --> 00:18:51.684 Let's play it 261 00:18:51.685 --> 00:18:52.635 Then, just like so 262 00:18:52.635 --> 00:18:53.301 One 263 00:18:53.301 --> 00:18:54.030 Two 264 00:18:54.030 --> 00:18:54.601 Three 265 00:18:55.386 --> 00:18:57.486 One is spawned every second, see? 266 00:18:59.201 --> 00:19:01.651 We are seeing error here because 267 00:19:02.701 --> 00:19:07.951 When AI Actor and Player collide, both are destroyed 268 00:19:08.601 --> 00:19:12.351 And whenever an AI Actor is spawned, its node looks for Player 269 00:19:12.351 --> 00:19:15.819 And since there is no Player left, we are seeing an error 270 00:19:16.751 --> 00:19:19.501 For our test purpose 271 00:19:19.501 --> 00:19:22.801 Let's make our Player not be destroyed 272 00:19:22.801 --> 00:19:26.499 So double click on BP_Player to open 273 00:19:27.851 --> 00:19:32.901 And for our on Components Begin Overlap Node 274 00:19:32.901 --> 00:19:36.101 Let's remove the part where it destroys itself 275 00:19:38.851 --> 00:19:42.401 Next, save and compile 276 00:19:42.401 --> 00:19:45.851 Back at the Actual Level, play again and 277 00:19:46.755 --> 00:19:53.855 Now we see AI Actor spawning and approaching as I move 278 00:19:57.401 --> 00:19:59.351 And what happens when we collide? 279 00:20:02.501 --> 00:20:03.501 It gets destroyed 280 00:20:09.567 --> 00:20:12.917 Using SetTimer Node 281 00:20:13.851 --> 00:20:17.451 Now, let's use a SetTimer Node 282 00:20:17.451 --> 00:20:21.701 So that it implements the same thing we just talked about 283 00:20:22.501 --> 00:20:26.051 Back at our BeginPlay Node, right click 284 00:20:26.644 --> 00:20:33.094 And add a node named 'SetTimer by Function Name' 285 00:20:35.651 --> 00:20:39.951 With this node, for every 'time' 286 00:20:39.951 --> 00:20:44.901 It calls a same function to 'Function Name' 287 00:20:46.001 --> 00:20:47.001 And here 288 00:20:49.901 --> 00:20:55.501 We will make this node that spawns BP_AIActor into a function 289 00:20:55.501 --> 00:20:59.751 So that it calls that function right away 290 00:21:01.401 --> 00:21:07.351 To our left, at FUNCTIONS, click on the plus button to create a function 291 00:21:08.951 --> 00:21:14.851 Let's call it 'CreateAIActor' 292 00:21:18.051 --> 00:21:20.201 At its Event Graph window 293 00:21:21.251 --> 00:21:27.451 Let's copy SpawnActor BP_AIActor Node and Get Actor Location Node 294 00:21:28.201 --> 00:21:31.351 And paste it at CreateAIActor Node 295 00:21:33.818 --> 00:21:36.918 And connect the Execution Node 296 00:21:39.151 --> 00:21:41.501 Back to Event Graph 297 00:21:43.151 --> 00:21:50.001 Click on the function name at SetTime by Function Name 298 00:21:50.551 --> 00:21:56.601 And write the function name, 'CreateAIActor' 299 00:21:58.751 --> 00:22:04.001 For 'time', bring 'Create Time' using 'get' 300 00:22:05.651 --> 00:22:08.301 And connect 301 00:22:10.001 --> 00:22:13.301 Now, since this action needs to repeat itself 302 00:22:13.301 --> 00:22:18.051 Let's tick the box that says 'Looping' 303 00:22:19.951 --> 00:22:26.801 And connect Begin Play to SetTimer by Function Name 304 00:22:28.715 --> 00:22:32.265 This will spawn at Timer 305 00:22:32.265 --> 00:22:36.165 And also spawn at where we measure the time 306 00:22:36.751 --> 00:22:41.101 So let's disconnect the Exec Pin at Event Tick 307 00:22:44.026 --> 00:22:50.376 And compile, back to Actual Level, let's play it 308 00:22:50.376 --> 00:22:54.401 And we see the same spawning every other second 309 00:22:56.881 --> 00:22:59.331 Using Delay Node 310 00:23:01.513 --> 00:23:06.613 Next, let's use Delay Node to spawn actors 311 00:23:06.614 --> 00:23:09.764 In order to prevent duplicate spawns 312 00:23:09.764 --> 00:23:14.882 Disconnect the Execution Pin that starts at Begin Play 313 00:23:14.883 --> 00:23:17.507 And back to Event Tick 314 00:23:17.951 --> 00:23:23.201 At the bottom, right click and search for 'Delay' 315 00:23:24.301 --> 00:23:26.801 And we get a Delay Node at the bottom 316 00:23:26.801 --> 00:23:28.201 Let's add that 317 00:23:29.640 --> 00:23:35.090 And connect the Execution Pin from the Event Tick so that it comes over here 318 00:23:35.990 --> 00:23:43.380 And this duration, or CreateTime, bring it in using 'get' and connect it 319 00:23:45.520 --> 00:23:53.900 Next, let's use our CreateAIActor function and connect it here so that it runs 320 00:23:55.040 --> 00:24:00.600 And now, compile, and back to our Actual Level and play 321 00:24:00.600 --> 00:24:07.610 Like this, we see how it spawns one AI Actor per every second 322 00:24:08.560 --> 00:24:10.610 And what is the difference here? 323 00:24:10.610 --> 00:24:13.100 In order to repeat a behavior 324 00:24:13.100 --> 00:24:18.850 SetTime Node has the 'looping' option checked 325 00:24:18.850 --> 00:24:23.280 as True, and it only runs once at Begin Play 326 00:24:31.000 --> 00:24:39.000 While this one, it does not run the next one before our duration passes 327 00:24:39.000 --> 00:24:44.000 Meaning, even if it repeats, it won't continue until a duration passes 328 00:24:44.450 --> 00:24:47.750 After this duration passes 329 00:24:47.750 --> 00:24:52.200 Then it runs this and checks again 330 00:24:53.750 --> 00:24:58.000 You can use whatever is more convenient for you 331 00:24:58.250 --> 00:25:02.700 But in the beginning, I recommend that 332 00:25:02.700 --> 00:25:06.600 You use the first method where we make the time pass ourselves 333 00:25:07.250 --> 00:25:12.700 And use an if statement in order for our desired action 334 00:25:16.400 --> 00:25:20.000 Let's now apply all the things we have learned 335 00:25:20.400 --> 00:25:26.650 And spawn and actor that moves upward from this Player position 336 00:25:27.000 --> 00:25:30.500 And let's make it a bit fast 337 00:25:32.000 --> 00:25:35.800 At Content Browser, right click 338 00:25:35.800 --> 00:25:39.920 'Blueprint Class' and choose 'Actor' 339 00:25:39.920 --> 00:25:44.750 Let's name it BP_Bullet 340 00:25:47.160 --> 00:25:50.510 Double click to open 341 00:25:50.510 --> 00:25:56.129 For this bullet, we will just code it so that it moves upward 342 00:25:56.779 --> 00:25:58.640 At Event Graph 343 00:25:59.440 --> 00:26:01.240 Right click 344 00:26:02.290 --> 00:26:07.860 Search for 'Get Actor Location' and add it 345 00:26:10.240 --> 00:26:16.310 And right click again to add 'Get Actor Forward Vector' 346 00:26:18.960 --> 00:26:21.810 Now, let's create a variable 347 00:26:21.810 --> 00:26:26.470 At VARIABLES, click on the plus button and create our Speed variable 348 00:26:27.520 --> 00:26:30.180 Data type is 'Float' 349 00:26:31.030 --> 00:26:36.119 Compile, and let's set its default value as 600 350 00:26:37.919 --> 00:26:41.030 Forward Vector, multiply 351 00:26:42.760 --> 00:26:47.830 And let's bring in Speed using 'get' and multiply it 352 00:26:52.239 --> 00:26:56.939 And then multiply it again by the result we have 353 00:26:56.939 --> 00:26:59.119 And multiply it by this Delta Time 354 00:27:04.450 --> 00:27:09.500 Next, add another Plus node here 355 00:27:09.500 --> 00:27:11.900 Add it with the current location 356 00:27:12.500 --> 00:27:18.850 Right click to add 'Set Actor Location Node' 357 00:27:19.300 --> 00:27:22.000 Put it into New Location 358 00:27:24.050 --> 00:27:28.000 And connect Exec Pin from Event Tick to Select Location 359 00:27:29.750 --> 00:27:33.000 Now, let's go to Viewport and touch up its appearance 360 00:27:33.450 --> 00:27:39.400 Click on Add, choose 'Static Mesh' 361 00:27:40.650 --> 00:27:45.000 At the Details window to the right, go to 'Static Mesh' and choose 'None' 362 00:27:45.350 --> 00:27:47.800 And choose 'Capsule' 363 00:27:50.400 --> 00:27:54.000 See this 'Shape Narrow Capsule'? 364 00:27:54.000 --> 00:27:56.050 Choose this capsule 365 00:27:57.250 --> 00:28:02.600 Compile, and choose any color you like for this material 366 00:28:05.900 --> 00:28:10.000 And let's tilt it a bit to this side 367 00:28:10.000 --> 00:28:14.600 So this green, this green part of Location at Transform 368 00:28:15.900 --> 00:28:18.300 Make it 90 and it rotates the other way, see? 369 00:28:18.300 --> 00:28:21.200 -90 will rotate it this way around 370 00:28:23.000 --> 00:28:25.300 It may be a bit too big 371 00:28:25.300 --> 00:28:29.000 So let's go back to Actual Level and see by adding our BP_Bullet 372 00:28:29.000 --> 00:28:31.200 Oh, it's not too big 373 00:28:33.000 --> 00:28:37.000 If it is too big for you 374 00:28:37.000 --> 00:28:40.300 You can go back and reduce the Scale values of our BP_Bullet 375 00:28:40.300 --> 00:28:41.750 I will leave this as it is now 376 00:28:44.350 --> 00:28:48.000 Compile, back to Actual Level 377 00:28:48.000 --> 00:28:52.000 Add BP_Bullet here and play 378 00:28:52.000 --> 00:28:54.250 Now we see that it is moving upward 379 00:28:55.122 --> 00:28:58.172 And we will keep it at our Player location 380 00:28:58.172 --> 00:29:02.722 And make it spawn every certain amount of time 381 00:29:03.000 --> 00:29:04.700 Then what happens? 382 00:29:04.700 --> 00:29:07.750 It spawns, it moves up, another spawns, it moves up 383 00:29:07.750 --> 00:29:09.200 That's what we will see 384 00:29:10.400 --> 00:29:13.240 Let's remove this BP_Bullet here 385 00:29:14.501 --> 00:29:16.301 Back to BP_Player 386 00:29:17.640 --> 00:29:19.490 Let's create a variable 387 00:29:19.540 --> 00:29:23.190 FUNCTIONS, click on the plus button 388 00:29:23.740 --> 00:29:28.220 Let's name it CreateBullet 389 00:29:30.240 --> 00:29:38.460 Right click, add 'Spawn Actor From Class' node 390 00:29:39.360 --> 00:29:44.490 Click on this area where we choose the class 391 00:29:45.240 --> 00:29:50.120 And set our BP_Bullet here 392 00:29:52.279 --> 00:29:54.279 Next, right click here 393 00:29:54.279 --> 00:29:58.459 Let's now bring in 'Get Actor Transform' 394 00:30:01.160 --> 00:30:04.210 And put it right into Spawn Transform 395 00:30:04.210 --> 00:30:05.360 What does this do? 396 00:30:05.360 --> 00:30:10.110 It sets the location, rotation and scale values 397 00:30:10.110 --> 00:30:12.170 Of our Player at once 398 00:30:13.451 --> 00:30:15.751 Let's not connect our Exec Pin 399 00:30:19.170 --> 00:30:21.889 Back to our Event Graph 400 00:30:22.839 --> 00:30:27.989 At Begin Play, let's use our Timer node 401 00:30:28.139 --> 00:30:30.409 To spawn our Bullet Actor 402 00:30:31.559 --> 00:30:38.789 Right click and select 'Set Timer by Function Name' 403 00:30:39.839 --> 00:30:41.689 For function name 404 00:30:42.289 --> 00:30:48.189 Bring in our CreateBullet 405 00:30:48.189 --> 00:30:49.510 And tick for Looping 406 00:30:50.360 --> 00:30:55.760 Let's set the time value as 0.5 407 00:30:57.160 --> 00:30:58.289 And then 408 00:31:00.420 --> 00:31:05.730 Connect it with the Exec Pin from our 'Add Mapping Context' 409 00:31:07.280 --> 00:31:12.330 Compile, back to Actual Level, play 410 00:31:12.330 --> 00:31:16.080 Like so, every 0.5 second 411 00:31:16.080 --> 00:31:19.430 This spawns an Actor called Bullet 412 00:31:22.290 --> 00:31:23.640 And here 413 00:31:23.640 --> 00:31:26.990 When a bullet and an AI Actor collide 414 00:31:26.990 --> 00:31:30.280 Then our bullet actor should disappear 415 00:31:32.520 --> 00:31:36.670 So at Edit, go to 'Project Settings' 416 00:31:37.570 --> 00:31:40.410 At 'Engine', go to 'Collision' tab 417 00:31:41.160 --> 00:31:45.960 Let's use New Object channel to create a channel called Bullet 418 00:31:48.240 --> 00:31:52.240 And for default response, I will set it as 'ignore' 419 00:31:52.240 --> 00:31:54.430 And then click on 'Accept' 420 00:31:56.819 --> 00:31:58.719 Back to BP_Bullet 421 00:31:59.451 --> 00:32:04.801 Choose 'Static Mesh' and at Details, move to Collision tab 422 00:32:05.269 --> 00:32:10.559 And for this Collision preset, go to its dropdown menu and choose 'Custom' 423 00:32:12.959 --> 00:32:17.909 And change 'Collision Enabled' to 'Query Only' 424 00:32:17.909 --> 00:32:22.930 And 'Object Type', let's set it to Bullet that we made 425 00:32:23.680 --> 00:32:28.230 Other than that, keep everything as 'Ignore' 426 00:32:28.680 --> 00:32:34.570 Let's just go to this AI part for Object Response 427 00:32:35.020 --> 00:32:38.230 And set it as 'Overlap' 428 00:32:40.440 --> 00:32:42.429 And now, scroll down 429 00:32:44.559 --> 00:32:47.779 When 'On Component Begin Overlap' 430 00:32:48.201 --> 00:32:50.951 We will remove the both 431 00:32:50.951 --> 00:32:54.301 So let's click on this button to add a node 432 00:32:56.840 --> 00:33:00.800 And here, at 'Other Actor', drag the cursor 433 00:33:00.800 --> 00:33:05.050 And search for 'destroy' to get 'Destroy Actor' 434 00:33:05.050 --> 00:33:06.650 Add this node 435 00:33:07.600 --> 00:33:09.650 And then right click again 436 00:33:09.650 --> 00:33:16.850 And add another 'Destroy Actor' 437 00:33:16.850 --> 00:33:19.559 And also connect the Exec Pin 438 00:33:19.559 --> 00:33:23.070 This means, when we collide, it removes you and me 439 00:33:24.559 --> 00:33:25.850 Let's compile 440 00:33:27.051 --> 00:33:31.151 At BP_Player, choose this Box Component 441 00:33:31.200 --> 00:33:33.600 At 'Collision' 442 00:33:33.600 --> 00:33:37.599 You should make sure that Bullet is ignoring any collision 443 00:33:37.599 --> 00:33:39.149 Or, this will happen 444 00:33:39.149 --> 00:33:40.799 Let's say we set it as Overlap 445 00:33:40.799 --> 00:33:46.319 Then every time a bullet spawns, it will disappear, right? 446 00:33:46.319 --> 00:33:49.880 It cannot do that when colliding with Player 447 00:33:49.880 --> 00:33:52.199 So make sure to set it as Ignore 448 00:33:53.099 --> 00:33:58.749 Now, at BP_AIActor 449 00:33:58.749 --> 00:34:00.789 Choose 'Sphere' component 450 00:34:01.889 --> 00:34:04.089 And move to Collision tab 451 00:34:04.089 --> 00:34:06.629 And expand on this Collision preset 452 00:34:06.629 --> 00:34:12.279 Here, Bullet should be set as 'Overlap' 453 00:34:12.279 --> 00:34:15.050 So that Bullet and AIActor collide with each other 454 00:34:16.000 --> 00:34:21.480 So compile, at Actual Level, let's try playing it 455 00:34:22.480 --> 00:34:28.720 Like so, whenever Bullet Actor and AI Actor collide 456 00:34:28.720 --> 00:34:30.770 They disappear 457 00:34:33.160 --> 00:34:39.959 See how whenever BP_Bullet and BP_AIActor meet, they disappear 458 00:34:39.959 --> 00:34:43.479 And let's add a sound effect for that 459 00:34:47.000 --> 00:34:53.440 Let's disconnect the Exec Pin connected to this actor destroying node 460 00:34:53.440 --> 00:34:58.110 And let's add a sound effect for explosion here 461 00:34:59.360 --> 00:35:04.560 Right click, search for 'Play Sound' 462 00:35:04.560 --> 00:35:06.239 And we have 'Play Sound 2D' 463 00:35:07.401 --> 00:35:09.501 Add this node 464 00:35:09.801 --> 00:35:13.991 And we get a list of sounds we can choose from 465 00:35:16.221 --> 00:35:18.671 Go to 'Select Asset' 466 00:35:18.671 --> 00:35:22.811 And we see that list of sounds we can use 467 00:35:23.401 --> 00:35:28.900 Now, search for 'explo...' and we get 'Explosion01' 468 00:35:30.001 --> 00:35:32.851 Choose this file 469 00:35:32.851 --> 00:35:35.251 And connect the Exec Pin 470 00:35:35.251 --> 00:35:38.251 It's a very simple way to play a sound 471 00:35:40.401 --> 00:35:46.130 Compile, back to Actual Level, play 472 00:35:46.830 --> 00:35:53.201 And we now hear the sound effect for every collision 473 00:35:55.001 --> 00:35:57.251 When you study Unreal on your own 474 00:35:57.701 --> 00:36:03.380 I recommend that you also work on adding sound effects 475 00:36:03.380 --> 00:36:07.551 Whenever we spawn a BP_Bullet as well 476 00:36:10.161 --> 00:36:12.711 Now, after certain time passes 477 00:36:12.711 --> 00:36:17.521 It keeps adding BP_AIActor or BP_Bullet 478 00:36:17.571 --> 00:36:20.691 And there is a problem with this 479 00:36:23.001 --> 00:36:24.851 When we play it 480 00:36:25.351 --> 00:36:27.951 See the bullets that are going upward 481 00:36:27.951 --> 00:36:33.761 And the BP_AIActors that are going downward past Player? 482 00:36:35.280 --> 00:36:41.260 Let's pause here and check out our Outliner window to the right 483 00:36:41.261 --> 00:36:46.451 We have a ton of BP_AIActor and BP_Bullet here 484 00:36:48.401 --> 00:36:51.520 These actors that are here 485 00:36:54.361 --> 00:36:58.771 They do not get destroyed; they remain so until the end 486 00:37:02.851 --> 00:37:06.871 This AI Actor just moves this way forever 487 00:37:07.571 --> 00:37:10.071 And with this happening 488 00:37:10.071 --> 00:37:14.691 If we run this content for long enough 489 00:37:14.691 --> 00:37:19.650 There will be a myriad of un-destroyed actors 490 00:37:19.650 --> 00:37:23.800 That will slow down the program 491 00:37:24.000 --> 00:37:25.931 And in a worst case scenario 492 00:37:25.931 --> 00:37:29.541 The program may shut itself down 493 00:37:32.211 --> 00:37:41.211 So we need to make sure that whenever BP_AIActor or BP_Bullet goes beyond this screen 494 00:37:41.211 --> 00:37:44.411 That they get destroyed as well 495 00:37:46.531 --> 00:37:52.331 And you already know how to implement this 496 00:37:53.531 --> 00:37:58.891 Which is, first create an Actor 497 00:37:58.891 --> 00:38:01.391 And this Actor will 498 00:38:01.391 --> 00:38:04.341 Destroy any actor that 499 00:38:04.341 --> 00:38:08.121 Collide into it 500 00:38:10.171 --> 00:38:12.171 So let's create this actor 501 00:38:12.171 --> 00:38:14.221 Right click 502 00:38:14.221 --> 00:38:18.081 Blueprint Class, choose 'Actor' 503 00:38:18.381 --> 00:38:22.461 Let's name it 'DestroyZone' 504 00:38:24.690 --> 00:38:27.090 Double click to open 505 00:38:27.890 --> 00:38:33.221 Click on 'Add' to add a Static Mesh 506 00:38:34.821 --> 00:38:41.331 And at Details, at Static Mesh menu, search for 'Cube' 507 00:38:41.331 --> 00:38:43.151 And add it here 508 00:38:44.351 --> 00:38:46.351 This DestroyZone Actor, 509 00:38:46.351 --> 00:38:50.651 It won't be visible in our play screen 510 00:38:50.851 --> 00:38:55.071 Meaning, we do not need any particular material for this 511 00:38:56.611 --> 00:39:01.761 And at Edit, go to 'Project Settings' 512 00:39:01.761 --> 00:39:04.630 At Engine, go to 'Collision' tab 513 00:39:04.630 --> 00:39:06.521 And let's create one more Object Channel 514 00:39:07.051 --> 00:39:09.451 Choose 'New Object Channel' 515 00:39:09.451 --> 00:39:11.451 And let's name it DestroyZone 516 00:39:16.471 --> 00:39:19.971 Let's set 'Default Response' as 'Ignore' 517 00:39:19.971 --> 00:39:24.470 Now, click on 'Accept' and close the window 518 00:39:25.951 --> 00:39:27.751 Compile once again 519 00:39:28.811 --> 00:39:32.161 At DestroyZone, choose 'Static Mesh' 520 00:39:32.161 --> 00:39:36.121 Scroll down the Details, at Collision tab 521 00:39:36.121 --> 00:39:38.621 At the dropdown menu of 'Collision' preset 522 00:39:38.621 --> 00:39:40.321 Choose 'Custom' 523 00:39:41.101 --> 00:39:46.421 And for 'Collision Enabled', choose 'QueryOnly' 524 00:39:46.421 --> 00:39:51.941 And for 'Collision Process', choose ignore, and for everything else as well 525 00:39:51.941 --> 00:39:59.830 So that only Bullet and AI, these two will overlap, or collide 526 00:40:00.980 --> 00:40:06.341 And then scroll down at 'Event' tab 527 00:40:06.341 --> 00:40:11.671 For On Component Begin Overlap, click on the plus button to add a node 528 00:40:13.021 --> 00:40:16.921 At Other Actor Pin, drag the ouse out 529 00:40:16.921 --> 00:40:20.140 And add 'Destroy Actor Node' 530 00:40:22.181 --> 00:40:24.681 Meaning, for this DestroyZone 531 00:40:24.681 --> 00:40:29.220 Only Bullet and AI actors can collide with this 532 00:40:29.220 --> 00:40:31.170 So this collision event 533 00:40:31.170 --> 00:40:35.501 It is only called when these two actors collide 534 00:40:35.501 --> 00:40:38.781 And it will destroy that actor that collides with this 535 00:40:40.700 --> 00:40:42.400 Compile 536 00:40:42.400 --> 00:40:46.300 And let's go to BP_Bullet and check one thing 537 00:40:46.300 --> 00:40:50.740 Choose 'Static Mesh', and at 'Collision' tab 538 00:40:50.740 --> 00:40:56.740 Let's change the setting to say that it will 'Overlap' or collide into DestroyZone 539 00:40:56.851 --> 00:41:00.291 Again, at Content Drawer 540 00:41:00.291 --> 00:41:05.931 At Actual Practice, double click on BP_AIActor to open it 541 00:41:05.931 --> 00:41:09.091 Here, go to our Sphere Collision Component 542 00:41:10.041 --> 00:41:15.531 At 'Collision' tab, expand on Collision Presets 543 00:41:15.531 --> 00:41:19.981 And for DestroyZone, tick for 'Overlap' 544 00:41:21.931 --> 00:41:24.131 And back to Actual Level 545 00:41:24.131 --> 00:41:30.490 We will add this DestroyZone at our level 546 00:41:30.490 --> 00:41:32.531 Change the size with our Scale Tool 547 00:41:32.531 --> 00:41:37.800 Drag on this green to make it longer 548 00:41:40.450 --> 00:41:46.371 We need to set it so that it is not visible in our play screen 549 00:41:46.371 --> 00:41:51.531 This cannot show us whether these actors are 550 00:41:51.531 --> 00:41:52.810 Being destroyed or not 551 00:41:52.810 --> 00:41:57.371 So press F8 to zoom out a little 552 00:41:57.371 --> 00:42:01.171 And let's force this Player to move a bit 553 00:42:01.171 --> 00:42:05.190 It will collide into it, but it will not be destroyed 554 00:42:07.090 --> 00:42:09.040 Let's pause there 555 00:42:09.040 --> 00:42:14.891 At DestroyZone, we should change this Object Type at Collision 556 00:42:14.891 --> 00:42:19.891 As of now, this Object Type is set as WorldDynamic 557 00:42:19.891 --> 00:42:25.151 That's why the collision with AI Actor and Bullet Actor had been ignored 558 00:42:26.651 --> 00:42:32.571 Let's go to the dropdown menu of World to set it as DestroyZone 559 00:42:32.571 --> 00:42:36.231 Compile again and play 560 00:42:37.931 --> 00:42:42.090 Let's zoom out and move our Player 561 00:42:42.090 --> 00:42:47.350 See these two actors; they are destroyed when they bump into this 562 00:42:49.050 --> 00:42:56.410 This means, if we make this big wall of DestroyZone here 563 00:42:56.410 --> 00:43:01.260 All actors that try to move out of the area will get destroyed 564 00:43:02.810 --> 00:43:06.410 Let's summarize what we have learned today 565 00:43:06.410 --> 00:43:14.970 The equation of 'Duration of time = Current time Time required to call the Tick Function' 566 00:43:14.970 --> 00:43:18.530 Has helped us measure the amount of time having passed 567 00:43:18.530 --> 00:43:25.171 And we also learned how to spawn an actor after a certain time 568 00:43:25.171 --> 00:43:30.490 We also learned about how to use SetTimer Node and Delay Node 569 00:43:31.576 --> 00:43:35.752 Spawn Actor after a Certain Time Accumulate Delta Seconds and spawn an actor when it reaches a number 570 00:43:35.752 --> 00:43:38.347 Multiply by Delta Seconds to make the movement the same for all environments 571 00:43:38.347 --> 00:43:41.598 Using SetTimer Node SetTimer by Function Name 572 00:43:41.598 --> 00:43:45.365 Every 'time', call the same function as Function Name; to repeat this, tick on 'Looping' 573 00:43:45.365 --> 00:43:52.251 Using Delay Node Search for Delay at Event Tick Duration: Runs itself again after a certain time Add sound effect for when the actor gets destroyed with collision