﻿1
00:00:04,500 --> 00:00:05,430
‫Hello and welcome.

2
00:00:05,430 --> 00:00:12,390
‫In this lecture, we're going to be learning about setting location calling functions in C++ so that

3
00:00:12,390 --> 00:00:16,740
‫we can bring a cube to a new location when we start playing.

4
00:00:16,740 --> 00:00:19,500
‫As you can see here, this cube suddenly appeared when we started playing.

5
00:00:19,500 --> 00:00:23,520
‫Let's dive in and see how functions work in C++.

6
00:00:23,580 --> 00:00:31,320
‫So let's take a look at how functions translate from Blueprint over into C++, particularly using functions

7
00:00:31,320 --> 00:00:32,010
‫at this stage.

8
00:00:32,010 --> 00:00:36,390
‫We'll have a look at how to create our own later on in this section.

9
00:00:36,570 --> 00:00:40,260
‫So to refresh your memory, this is what a function looks like in Blueprint.

10
00:00:40,260 --> 00:00:45,630
‫You can see we have a node, we've got input pins on the left, output pins on the right, and we can

11
00:00:45,630 --> 00:00:50,910
‫plug things like a variable into an input pin to do the same thing in C++.

12
00:00:50,910 --> 00:00:55,170
‫Looks like this you use again function names have no spaces in them.

13
00:00:55,170 --> 00:01:00,720
‫So instead of having a set actor location node as separate words, we have it all run together using

14
00:01:00,720 --> 00:01:03,690
‫camel case and then we have our parentheses.

15
00:01:03,690 --> 00:01:10,440
‫And inside the parentheses we have a list of inputs and these inputs could be more than one.

16
00:01:10,440 --> 00:01:14,460
‫You can have them comma separated, but for the first instance we're going to just have one.

17
00:01:14,550 --> 00:01:18,000
‫And these inputs are actually called arguments.

18
00:01:18,000 --> 00:01:20,670
‫Don't ask me why I don't want to have an argument about it.

19
00:01:20,670 --> 00:01:27,870
‫So we are going to have to put these variables in, but you don't have to pass variables.

20
00:01:27,870 --> 00:01:29,130
‫Variables are just one way of doing it.

21
00:01:29,130 --> 00:01:30,960
‫You can pass values as well.

22
00:01:30,960 --> 00:01:36,600
‫So if we had a situation like this where we wanted just to set the location to 1 to 3, we can do that

23
00:01:36,600 --> 00:01:44,820
‫in C++ as well by using the F Vector constructor directly inside the parentheses for the function.

24
00:01:44,820 --> 00:01:51,060
‫So that means that we set it to a specific value rather than the value contained inside a variable.

25
00:01:51,060 --> 00:01:52,620
‫So let's give that a go.

26
00:01:52,620 --> 00:01:59,790
‫We'll go over to Visual Studio code and we're going to have a look at the Begin play just after we have

27
00:01:59,790 --> 00:02:01,710
‫updated the My Vector.

28
00:02:01,950 --> 00:02:07,470
‫I'm going to add a couple of new lines and I'm going to start typing set actor location, make sure

29
00:02:07,470 --> 00:02:13,020
‫you type it correctly because names have to match exactly in C++, then you open your parentheses and

30
00:02:13,020 --> 00:02:18,360
‫in here we are going to construct a new F vector value.

31
00:02:18,360 --> 00:02:22,950
‫So we're going to type F vector open parentheses again.

32
00:02:22,950 --> 00:02:28,470
‫And in here we are actually passing in arguments to the constructor for F Vector.

33
00:02:28,470 --> 00:02:33,750
‫So this is very much like calling a function and then passing the value of that function into another

34
00:02:33,750 --> 00:02:34,320
‫function.

35
00:02:34,320 --> 00:02:36,870
‫But we'll talk more about that sort of stuff later on.

36
00:02:36,870 --> 00:02:43,560
‫And what we can do here is type in one, comma two, comma three, and that means that the f vector

37
00:02:43,560 --> 00:02:48,990
‫one, two, three is going to be passed into set actor location and then we can put a semicolon at the

38
00:02:48,990 --> 00:02:50,910
‫end of the completed line.

39
00:02:50,910 --> 00:02:53,070
‫So let's go into unreal.

40
00:02:53,070 --> 00:02:56,490
‫Let's go ahead and compile the code.

41
00:02:56,490 --> 00:03:02,550
‫And for us to be able to see the effect of this, we need to go to our moving platform actor and you'll

42
00:03:02,550 --> 00:03:07,530
‫notice there are actually no components on this actor, which means that it can't actually have a position

43
00:03:07,530 --> 00:03:09,840
‫because only components can give it a position.

44
00:03:09,840 --> 00:03:16,170
‫So we can go ahead and add something like a cube to this moving platform actor or go to the ad in the

45
00:03:16,170 --> 00:03:24,720
‫details pane and we go down to Cube and that gives us a cube and we can go ahead and hit play and see

46
00:03:24,720 --> 00:03:27,210
‫whether we're able to set this act as location.

47
00:03:27,210 --> 00:03:32,700
‫We can click on the moving platform and then we can eject using the eject button in the toolbar and

48
00:03:32,700 --> 00:03:34,110
‫then double click on moving platform.

49
00:03:34,110 --> 00:03:37,980
‫And you can see it takes us to the moving platform's location.

50
00:03:37,980 --> 00:03:45,090
‫And with that selected in the outlier or in the scene view, we can have a look at the details pane

51
00:03:45,090 --> 00:03:45,810
‫and we can see that.

52
00:03:45,810 --> 00:03:51,720
‫Sure enough, the transform says that its location is one, two, three.

53
00:03:51,720 --> 00:03:55,530
‫We've set that correctly in C++ code.

54
00:03:55,530 --> 00:04:02,250
‫Now for this next part, it's going to be just confusing if we are setting the Y value of my vector

55
00:04:02,610 --> 00:04:04,500
‫from the my x variable.

56
00:04:04,500 --> 00:04:06,780
‫So let's delete that line and begin play for me.

57
00:04:06,780 --> 00:04:13,380
‫That's line 19 and I'll delete a few of the extra empty lines there so that we've just got one between

58
00:04:13,380 --> 00:04:16,080
‫the super big in play and set actor location.

59
00:04:16,320 --> 00:04:22,230
‫Then I'd like to challenge you to use a variable instead of constructing the f vector in place.

60
00:04:22,230 --> 00:04:26,580
‫So replace the F vector constructor that we're using.

61
00:04:26,610 --> 00:04:31,800
‫Update the my vector so that it has a different location.

62
00:04:31,800 --> 00:04:35,010
‫Can you bring it so that it is closer to the player?

63
00:04:35,010 --> 00:04:40,680
‫When we hit play, the cube is actually positioned somewhere where the player can see it.

64
00:04:40,680 --> 00:04:42,480
‫Pause the video and have a go.

65
00:04:45,390 --> 00:04:47,080
‫Hello and welcome back.

66
00:04:47,100 --> 00:04:54,120
‫So the way we do this is by removing this F vector and it's parentheses and it's arguments, and that's

67
00:04:54,120 --> 00:04:55,260
‫what they're called, remember?

68
00:04:55,260 --> 00:05:02,520
‫And then in as the argument to set actor location, we are going to type my vector.

69
00:05:02,520 --> 00:05:09,630
‫So it's going to use the value inside the my vector variable to set the actor's location on begin play

70
00:05:09,630 --> 00:05:10,920
‫when we begin playing.

71
00:05:10,920 --> 00:05:14,220
‫So let's go into unreal let's stop play for now.

72
00:05:14,220 --> 00:05:18,750
‫Let's have a look at the location of our third person character.

73
00:05:18,750 --> 00:05:22,110
‫We can see that there is this is the location here.

74
00:05:22,110 --> 00:05:25,080
‫What I can actually do, you could copy each of these manually.

75
00:05:25,080 --> 00:05:30,510
‫You could actually just right click on the location, click copy, go over to your moving platform.

76
00:05:30,780 --> 00:05:38,280
‫And where we have my vector, we can right click and hit paste and it's going to paste the entire vector

77
00:05:38,280 --> 00:05:39,540
‫right in there.

78
00:05:39,540 --> 00:05:44,010
‫So now we know that I'm moving Platform Cube is over here at 000.

79
00:05:44,010 --> 00:05:48,810
‫But if I hit play, well, actually not very much happens because I forgot to compile.

80
00:05:48,810 --> 00:05:53,280
‫This is the thing to always remember that we do need to compile any changes to C++.

81
00:05:53,280 --> 00:05:59,340
‫So we must hit that compile button and only when that is complete will we actually see the changes that

82
00:05:59,340 --> 00:05:59,790
‫we've made.

83
00:05:59,790 --> 00:06:01,500
‫So let's go ahead and hit play.

84
00:06:01,500 --> 00:06:02,310
‫And there you go.

85
00:06:02,310 --> 00:06:06,870
‫We've got the cube standing right in front of our player.

86
00:06:06,870 --> 00:06:11,610
‫So we've successfully moved it in begin play using C++ code.

87
00:06:11,610 --> 00:06:12,390
‫Great stuff.

88
00:06:12,390 --> 00:06:14,070
‫I'll see you in the next lecture.

