﻿1
00:00:04,740 --> 00:00:05,820
‫Hello and welcome.

2
00:00:05,820 --> 00:00:12,540
‫In this lecture, we're going to be creating actors and objects in our scene while we are playing.

3
00:00:12,540 --> 00:00:19,020
‫So if I hit spacebar, it adds in a ball and it adds the impulse to the new projectile that we have

4
00:00:19,020 --> 00:00:23,850
‫created, allowing us to create much more dynamic scenes and games.

5
00:00:23,850 --> 00:00:25,710
‫Let's dive in and see how this is done.

6
00:00:27,000 --> 00:00:33,870
‫So ideally, these projectiles would not be in the scene when we start, because that's not how projectiles

7
00:00:33,870 --> 00:00:34,500
‫work.

8
00:00:34,500 --> 00:00:42,600
‫You tend to create them when you want to shoot in a game and that is called spawning in the same way

9
00:00:42,600 --> 00:00:46,320
‫as you might spawn an NPC in any game that you play.

10
00:00:46,320 --> 00:00:51,420
‫Well, we can spawn actors into our level as we're playing as well.

11
00:00:51,420 --> 00:00:57,840
‫So let's go ahead and delete all but one of the projectiles in our scene and we'll see why in a second.

12
00:00:57,840 --> 00:01:03,720
‫We'll use one of them as a reference to figure out where we want our projectiles to spawn.

13
00:01:03,720 --> 00:01:09,300
‫But we do want to go ahead and go over to our level blueprint.

14
00:01:09,300 --> 00:01:16,050
‫And over here, what we want to do is disconnect the space bar event from the add impulse just for now.

15
00:01:16,050 --> 00:01:22,410
‫The way you can do this is by clicking either on the execution pin coming out of the space bar event

16
00:01:22,410 --> 00:01:24,630
‫or on the one coming in to add impulse.

17
00:01:24,630 --> 00:01:27,780
‫And that just goes ahead and removes the wire between the two.

18
00:01:28,050 --> 00:01:32,430
‫And now what we want to do is dragging off our press event.

19
00:01:32,430 --> 00:01:36,690
‫I want to search for a spawn actor node.

20
00:01:36,690 --> 00:01:41,640
‫There's a node called Spawn Actor from class and that's the one we want.

21
00:01:41,640 --> 00:01:46,440
‫You can see that having dragged off the execution pin, it automatically connects it up to the input

22
00:01:46,440 --> 00:01:48,630
‫pin of this spawn actor node.

23
00:01:49,020 --> 00:01:54,690
‫Now there's a couple of properties we want to configure to tell the node how to do its job.

24
00:01:54,750 --> 00:02:00,420
‫First of all, we need to tell it what it should be creating which class, which blueprint class should

25
00:02:00,420 --> 00:02:01,980
‫it be creating an instance of?

26
00:02:02,010 --> 00:02:07,500
‫Well, we got a handy little dropdown here and it's got a search box so we can search for projectile.

27
00:02:07,560 --> 00:02:10,170
‫And BP projectile is the only one that shows up.

28
00:02:10,170 --> 00:02:11,400
‫So we can select that.

29
00:02:11,610 --> 00:02:17,850
‫So we can see that the spawning is essentially just creating an object while we're playing.

30
00:02:17,850 --> 00:02:20,550
‫Now, what about this node here?

31
00:02:20,550 --> 00:02:22,530
‫The next one down is Spawn.

32
00:02:22,530 --> 00:02:23,250
‫Transform.

33
00:02:23,250 --> 00:02:24,360
‫What's a transform?

34
00:02:24,360 --> 00:02:30,720
‫Well, a transform is just the combination of the location, rotation and scale of an object.

35
00:02:30,720 --> 00:02:36,900
‫We use these three things together so much in games that it's just given a name which is transform.

36
00:02:36,900 --> 00:02:44,880
‫And what we can do is if we go over to our minimal default level and see the viewport, we can move

37
00:02:44,880 --> 00:02:46,380
‫our BP projectile around.

38
00:02:46,380 --> 00:02:51,120
‫And looking in the details pane, you can see that there's a section called Transform and indeed the

39
00:02:51,120 --> 00:02:54,570
‫properties underneath it are called location, rotation and scale.

40
00:02:54,570 --> 00:02:57,900
‫And you can see the X, Y and Z values for each.

41
00:02:57,900 --> 00:03:04,200
‫So we've got this projectile and quite usefully it's got 60 X and 120 Z.

42
00:03:04,200 --> 00:03:10,350
‫I'm just going to make a note of that because if we go back to the blueprint and right click on the

43
00:03:10,350 --> 00:03:13,650
‫Transform Node, we can click the split struct pin.

44
00:03:13,650 --> 00:03:16,200
‫Now, don't worry about what that means exactly just yet.

45
00:03:16,200 --> 00:03:17,970
‫We'll cover that in a later lecture.

46
00:03:17,970 --> 00:03:24,480
‫But what we've got now is is split out the transform into its component parts such as the location,

47
00:03:24,480 --> 00:03:25,650
‫rotation and scale.

48
00:03:25,980 --> 00:03:32,700
‫So that just allows us to put the newly created projectile in a certain location.

49
00:03:32,700 --> 00:03:40,530
‫So X is going to be 60, Y was zero and said was 120 and that's going to give us the correct location.

50
00:03:40,530 --> 00:03:44,100
‫And we don't need to worry about the rotation and scale the defaults.

51
00:03:44,100 --> 00:03:45,810
‫There should be just fine.

52
00:03:45,870 --> 00:03:52,440
‫So if we go ahead and hit play and then if I hit spacebar, you can see it creates a second projectile

53
00:03:52,440 --> 00:03:57,900
‫in exactly the location that the first projectile was and go ahead and create as many of these as I

54
00:03:57,900 --> 00:04:00,840
‫like just by keeping on hitting spacebar.

55
00:04:00,840 --> 00:04:09,600
‫Now the final thing to note is that there is a return value pin as the output to Aspen actor.

56
00:04:09,600 --> 00:04:12,600
‫Now we've used this term return quite a few times.

57
00:04:12,600 --> 00:04:14,460
‫Return pin or return value.

58
00:04:14,470 --> 00:04:16,500
‫It's just the output of a node.

59
00:04:16,500 --> 00:04:21,990
‫It's data or objects that come out as a result of executing that node.

60
00:04:22,230 --> 00:04:24,600
‫So this return value, what is it?

61
00:04:24,600 --> 00:04:30,540
‫Let's hover over it and you can see it says the beep projectile object, reference, return value.

62
00:04:30,540 --> 00:04:33,990
‫And underneath it it says it's the constructed object.

63
00:04:33,990 --> 00:04:38,850
‫So it's the object that we have spawned, essentially the new projectile.

64
00:04:38,850 --> 00:04:45,390
‫And so we can now get rid of the reference to the cube in our blueprint because we no longer want to

65
00:04:45,390 --> 00:04:46,920
‫be adding an impulse to the cube.

66
00:04:46,920 --> 00:04:51,120
‫We actually want to be adding it to the projectile that we've created instead.

67
00:04:51,120 --> 00:04:54,570
‫So that's going to be your challenge to hook up the impulse.

68
00:04:54,570 --> 00:04:56,040
‫I'd like you to hook up.

69
00:04:56,040 --> 00:05:01,410
‫First of all, the execution pins, the correct order should be the add impulse should happen after

70
00:05:01,410 --> 00:05:02,310
‫the spawning.

71
00:05:02,490 --> 00:05:03,210
‫We need to.

72
00:05:03,310 --> 00:05:11,930
‫Hook up the data pin as well so that we are getting the static mesh from the newly created projectile.

73
00:05:11,940 --> 00:05:14,430
‫And where should we be adding the impulse to?

74
00:05:14,460 --> 00:05:18,900
‫What is it that we're adding it to from that new projectile?

75
00:05:18,930 --> 00:05:20,520
‫Pause the video and have a go.

76
00:05:24,580 --> 00:05:25,060
‫Okay.

77
00:05:25,060 --> 00:05:25,990
‫Welcome back.

78
00:05:26,020 --> 00:05:31,540
‫So you may have guessed that what we're trying to get the static mesh from is the projectile, as I

79
00:05:31,540 --> 00:05:36,270
‫said, but that then it's that static mesh that we're trying to add the impulse to.

80
00:05:36,280 --> 00:05:41,860
‫So we're creating a new projectile, we're getting its static mesh component, and then we're adding

81
00:05:41,860 --> 00:05:42,670
‫an impulse to it.

82
00:05:42,670 --> 00:05:48,820
‫And now we need to just hook up the execution pins to make sure that ad impulse is indeed run after

83
00:05:48,820 --> 00:05:50,200
‫we spawn the actor.

84
00:05:50,200 --> 00:05:51,340
‫So let's see what that looks like.

85
00:05:51,340 --> 00:05:57,490
‫If we hit play and we hit the space bar, you can see that the newly created projectile that spawns

86
00:05:57,490 --> 00:06:02,890
‫into the level gets a little impulse added to it, and we can increase the value of that impulse if

87
00:06:02,890 --> 00:06:08,380
‫we wanted to, to make it jump a little bit higher into the air, which is just a little bit more fun,

88
00:06:08,380 --> 00:06:12,280
‫isn't it, when things jump up nice and high and that's it.

89
00:06:12,280 --> 00:06:19,780
‫Basically, we've created the basics of spawning in a projectile, so I will see you in the next lecture.

