﻿1
00:00:04,350 --> 00:00:05,490
‫Hello and welcome.

2
00:00:05,490 --> 00:00:10,680
‫In this lecture, we're going to be learning about how we can access what is on the other side of a

3
00:00:10,680 --> 00:00:17,760
‫pointer so that our mover component can get properties from the actor that it lives on, such as getting

4
00:00:17,760 --> 00:00:21,780
‫the name of the actor or getting its location.

5
00:00:21,780 --> 00:00:24,210
‫Let's dive in and see how we can do this.

6
00:00:24,540 --> 00:00:29,730
‫So it's all very well to be able to get a pointer or get an address of an actor.

7
00:00:29,730 --> 00:00:33,660
‫But we do need to be able to actually do stuff with the actor itself.

8
00:00:34,050 --> 00:00:39,630
‫And the process for doing this is a little bit tricky to understand if we just looking at the actor.

9
00:00:39,630 --> 00:00:47,460
‫So we're going to have a look at doing some pointers to floats just here within that tick component.

10
00:00:47,460 --> 00:00:54,210
‫So let's start off by creating a float, which we're going to call my float and set this to a value

11
00:00:54,210 --> 00:00:54,990
‫of five.

12
00:00:55,500 --> 00:01:01,740
‫Then we're going to create a float pointer, which I'm going to call your float, and we're going to

13
00:01:01,740 --> 00:01:06,360
‫set that to be the address of the my float.

14
00:01:06,570 --> 00:01:09,900
‫So these are both pointing to the same address in memory.

15
00:01:09,900 --> 00:01:17,010
‫The difference is that your float is an address, so I can't just print out the value.

16
00:01:17,010 --> 00:01:28,710
‫So if I wanted to do a u log and I wanted to say your float value is equal to percent F, then I put

17
00:01:28,710 --> 00:01:29,940
‫in your float.

18
00:01:29,940 --> 00:01:36,150
‫This isn't going to work because your float is a pointer, not an actual float.

19
00:01:36,600 --> 00:01:41,100
‫So what we need to do is essentially.

20
00:01:41,870 --> 00:01:44,960
‫Get the value at that location.

21
00:01:45,290 --> 00:01:51,620
‫So the way we can do this, if I were to store it in a new float variable called float value, then

22
00:01:51,620 --> 00:01:56,780
‫I use the D referencing operator, which is actually a star as well.

23
00:01:56,780 --> 00:02:00,710
‫And we put this before the thing that we want to d reference.

24
00:02:00,710 --> 00:02:04,760
‫So we then give it a pointer to D reference, which in this case is your float.

25
00:02:05,030 --> 00:02:09,980
‫Now it's a little bit strange that we use these stars in two different contexts.

26
00:02:09,980 --> 00:02:16,010
‫So one, we're using the star after the type which tells us that it's a float pointer.

27
00:02:16,010 --> 00:02:18,970
‫And when you're using it with a type, it means that it's a pointer.

28
00:02:18,980 --> 00:02:25,760
‫When you use a star before a pointer expression, what you're doing there is you're saying, Get me

29
00:02:25,760 --> 00:02:28,070
‫the value at this location.

30
00:02:28,340 --> 00:02:33,200
‫So then that gets the value and copies it into float value and now float value.

31
00:02:33,200 --> 00:02:36,680
‫We can just print out like so.

32
00:02:36,680 --> 00:02:41,200
‫So with all those contortions, let's go ahead and compile it and see it in action.

33
00:02:41,210 --> 00:02:42,230
‫Let's hit play.

34
00:02:42,230 --> 00:02:48,170
‫And sure enough, it's saying your float value is five, which is the value we had originally.

35
00:02:48,800 --> 00:02:53,630
‫Now, usually we don't store the intermediate value in a variable because that's wasteful.

36
00:02:53,630 --> 00:02:55,640
‫It's creating a copy that we don't need.

37
00:02:55,640 --> 00:03:00,800
‫So what we can do instead is just use that directly in the expression where we need it.

38
00:03:00,800 --> 00:03:07,940
‫So your float value would be star, your float like so, and that's going to work in exactly the same

39
00:03:07,940 --> 00:03:11,600
‫way, except this time it doesn't make a copy into a needless variable.

40
00:03:11,630 --> 00:03:16,490
‫Now suppose we wanted to get the name of the owner actor here.

41
00:03:16,490 --> 00:03:23,390
‫Well, the way we would do this, let's remove this stuff that we were doing with the floats is we would

42
00:03:23,390 --> 00:03:25,490
‫d reference that owner pointer.

43
00:03:25,490 --> 00:03:29,830
‫So we do star owner which actually gets us to the actor itself.

44
00:03:29,840 --> 00:03:36,920
‫Then we can put a pair of brackets around the owner and then we can do a dot.

45
00:03:36,920 --> 00:03:44,990
‫So we've got the actor out of this expression now we can use a dot to get something in from inside the

46
00:03:44,990 --> 00:03:53,030
‫actor so we can do get actor, name or label, which is going to return us a f string so we can do f

47
00:03:53,030 --> 00:04:04,550
‫string name equals to this and then we can print out mover owner percent SW And then instead of using

48
00:04:04,550 --> 00:04:07,760
‫owner here, we're going to start name or then bring that.

49
00:04:07,760 --> 00:04:10,430
‫We need to put the star in front of a name.

50
00:04:10,430 --> 00:04:13,250
‫That's yet another use for that star operator.

51
00:04:13,250 --> 00:04:15,230
‫We've already encountered three of them.

52
00:04:15,230 --> 00:04:16,700
‫One is with this string.

53
00:04:16,700 --> 00:04:18,020
‫That's the first time we've seen it.

54
00:04:18,020 --> 00:04:23,240
‫Then it's here with the type and it's also here for D, referencing lots and lots of uses for exactly

55
00:04:23,240 --> 00:04:24,680
‫the same character.

56
00:04:24,770 --> 00:04:27,050
‫But that's how it is with C++.

57
00:04:27,080 --> 00:04:29,120
‫Let's go and try it out and hit play.

58
00:04:29,660 --> 00:04:35,180
‫And now you can see that it's printing out the name of the actors that the mover is attached to.

59
00:04:35,180 --> 00:04:42,440
‫So we've gone reach through that pointer with the D referencing operator and been able to call a function

60
00:04:42,440 --> 00:04:44,600
‫on a different object.

61
00:04:44,600 --> 00:04:50,780
‫Now there's actually a much more compact syntax for doing this because it's so common for us to want

62
00:04:50,780 --> 00:04:59,090
‫to get a function or property from a pointer object instead of having to do this with the parentheses

63
00:04:59,090 --> 00:05:02,390
‫and as they d referencing operator, we can merge this all into one.

64
00:05:02,390 --> 00:05:09,530
‫We can remove all of this or move the dot and instead we use this arrow operator so we do owner arrow,

65
00:05:09,530 --> 00:05:14,960
‫get actor, name or label and this does exactly the same thing, except it's a lot easier to write.

66
00:05:14,960 --> 00:05:21,680
‫So generally speaking will end up with the rule where if we have got a pointer, we use the arrow operator.

67
00:05:21,680 --> 00:05:29,360
‫If we are using a struct like an F string or an F vector, we use the dot operator.

68
00:05:29,420 --> 00:05:37,010
‫So I'd like you to print the actor's location using this new knowledge of how we can use pointers.

69
00:05:37,010 --> 00:05:40,730
‫So I'd like you to call get actor location.

70
00:05:40,730 --> 00:05:46,880
‫You're going to be using the arrow operator to look through the pointer and call that function on the

71
00:05:46,880 --> 00:05:47,330
‫object.

72
00:05:47,330 --> 00:05:51,410
‫At the other end, you're going to store the F vector that results from that.

73
00:05:51,410 --> 00:06:00,770
‫Then you're going to call two compact string store the result in a new F string variable and print that

74
00:06:00,770 --> 00:06:02,060
‫to the log.

75
00:06:02,090 --> 00:06:04,220
‫Pause the video and have a go.

76
00:06:07,520 --> 00:06:07,880
‫Okay.

77
00:06:07,880 --> 00:06:08,840
‫Welcome back.

78
00:06:08,840 --> 00:06:23,390
‫So I'm going to create a new F vector called owner location and I'm going to do owner arrow, get actor

79
00:06:23,690 --> 00:06:24,890
‫location.

80
00:06:24,890 --> 00:06:27,650
‫Then I'm going to convert this to a string.

81
00:06:27,650 --> 00:06:35,660
‫So I'm going to have an F string called owner location string, and that's going to be equal to the

82
00:06:35,660 --> 00:06:42,760
‫owner location dot to compact string like so okey doke.

83
00:06:42,770 --> 00:06:45,020
‫So now we've got our own location string.

84
00:06:45,020 --> 00:06:46,880
‫We can print that to the log.

85
00:06:46,880 --> 00:06:57,290
‫I'm going to say that the mover owner is this with location percent s and that percent s we're going

86
00:06:57,290 --> 00:07:06,710
‫to have another star owner location string like so and then hit control alt f 11 and we'll go ahead

87
00:07:06,710 --> 00:07:14,630
‫and hit play and they go we have got both the name of the actor as well as its location printed out

88
00:07:14,630 --> 00:07:15,860
‫as a string.

89
00:07:15,860 --> 00:07:21,440
‫So now we can see the power of having pointers and being able to call functions on pointers.

90
00:07:21,440 --> 00:07:28,520
‫It allows us to communicate between different instances of classes and makes our objects far more useful.

91
00:07:28,520 --> 00:07:30,290
‫I'll see you in the next lecture.

