﻿1
00:00:04,360 --> 00:00:05,440
‫Hello and welcome.

2
00:00:05,440 --> 00:00:09,970
‫In this lecture, we're going to be introducing this piece of code here, the RT actor range, and see

3
00:00:09,970 --> 00:00:15,010
‫how it allows us to iterate over all of the actors in a given level.

4
00:00:15,010 --> 00:00:16,810
‫Let's dive in and see how it works.

5
00:00:17,410 --> 00:00:24,760
‫So at the moment in the pawn killed of our kill all game mode we are calling game has ended on the player

6
00:00:24,760 --> 00:00:31,750
‫controller but in actual fact game has ended is a function on all controllers where there A.I or player

7
00:00:31,750 --> 00:00:38,620
‫controllers and we should probably be notifying the AI controllers as well that the game has ended and

8
00:00:38,620 --> 00:00:43,210
‫that's certainly going to be the case or it's going to make it easier to do a win condition as well

9
00:00:43,210 --> 00:00:46,240
‫because we won't necessarily have the player pawn coming in here.

10
00:00:46,870 --> 00:00:50,140
‫So how do we go ahead and do this?

11
00:00:50,140 --> 00:00:57,160
‫Well, I'm going to create a new function in the KML game mode, a private one called End Game, which

12
00:00:57,160 --> 00:00:59,500
‫is going to be responsible for this act.

13
00:00:59,500 --> 00:01:02,710
‫So End Game and it's going to need some information.

14
00:01:02,710 --> 00:01:04,780
‫It's going to need to know who has won.

15
00:01:04,780 --> 00:01:06,730
‫Has it been the player or has it been the A.I.?

16
00:01:06,760 --> 00:01:11,800
‫So I'm going to create a bool here called B is player winner.

17
00:01:12,160 --> 00:01:18,970
‫And that is going to be what tells us whether or not we should be telling the AI that it's won or telling

18
00:01:18,970 --> 00:01:19,930
‫the player that it's won.

19
00:01:19,930 --> 00:01:22,660
‫Because remember in here our game has ended.

20
00:01:22,660 --> 00:01:26,740
‫Takes a boolean telling the controller whether or not it is one of the winners.

21
00:01:27,490 --> 00:01:31,960
‫So what we're going to have to do is figure out, first of all, let's go ahead and create the implementation.

22
00:01:31,960 --> 00:01:35,380
‫So I'm going to do my control shift P and then create implementation.

23
00:01:35,950 --> 00:01:41,650
‫And then we're going to have to figure out how we can find all of the controllers in our scene so that

24
00:01:41,650 --> 00:01:45,580
‫we can call game has ended on those controllers.

25
00:01:46,390 --> 00:01:51,880
‫Now the way we're going to do this is using a an engine helper call.

26
00:01:51,880 --> 00:01:57,570
‫So if we go to hash include, we're going to use engine utils, first of all.

27
00:01:57,570 --> 00:02:05,620
‫And that's going to bring into scope the helper that I want and the helper is called T Actor Range and

28
00:02:05,620 --> 00:02:08,260
‫T actor range is a template thing.

29
00:02:08,260 --> 00:02:11,500
‫So we can do the angle brackets here.

30
00:02:11,590 --> 00:02:18,760
‫We can then put a controller and then the parentheses and get world.

31
00:02:18,760 --> 00:02:20,050
‫Now what's this going to do?

32
00:02:20,080 --> 00:02:27,520
‫It's going to return us a range object, which is basically sort of like a list that goes over all of

33
00:02:27,520 --> 00:02:28,840
‫the controllers.

34
00:02:28,840 --> 00:02:35,800
‫That's why we've got that controller parameter in there in the world a.k.a the level, and we can use

35
00:02:35,800 --> 00:02:37,240
‫this in a for loop.

36
00:02:37,240 --> 00:02:39,610
‫So let me start wrapping this in a for loop.

37
00:02:39,610 --> 00:02:44,200
‫So we're going to do a for over the A controller.

38
00:02:44,200 --> 00:02:49,270
‫So the thing that is the variable that we're going to be ranging over is going to be an A controller

39
00:02:49,270 --> 00:02:51,190
‫pointer, which I'm going to call controller.

40
00:02:52,180 --> 00:02:56,140
‫And then we use the colon for what we're going to range over.

41
00:02:56,140 --> 00:02:58,240
‫It's going to be this T active range.

42
00:02:58,450 --> 00:03:03,160
‫And then we can put our closing parentheses and our curly brackets.

43
00:03:03,160 --> 00:03:04,900
‫So what's this saying?

44
00:03:04,900 --> 00:03:11,950
‫It's saying that we're going to do a four loop over every controller in the world and it's going to

45
00:03:11,950 --> 00:03:14,380
‫be in this variable called controller.

46
00:03:15,120 --> 00:03:17,700
‫And now there's a couple of things that you might need to know.

47
00:03:17,700 --> 00:03:22,050
‫So one thing is that we can query a controller for whether or not it's a player control without having

48
00:03:22,050 --> 00:03:22,530
‫to cast.

49
00:03:22,530 --> 00:03:28,380
‫We can actually just do controller arrow and then I think I'm going to actually need to include my controller

50
00:03:28,380 --> 00:03:28,620
‫here.

51
00:03:28,620 --> 00:03:37,080
‫So hash include at the top, we're going to do a game framework forward slash controller H and now Autocomplete

52
00:03:37,080 --> 00:03:38,400
‫will probably work.

53
00:03:38,400 --> 00:03:39,030
‫Yes, it has.

54
00:03:39,030 --> 00:03:41,790
‫So what we can do is obviously we can call game has ended.

55
00:03:41,790 --> 00:03:46,530
‫That's what my first autocomplete here but also we can say is player controller.

56
00:03:46,530 --> 00:03:52,140
‫Basically it's going to say is this thing in the world of player controller and that will allow us to

57
00:03:52,140 --> 00:03:58,410
‫decide whether or not we should be passing in true or false to game has ended.

58
00:03:58,410 --> 00:04:04,890
‫So my challenge to you is to fill out this for loop by calling game has ended with the correct boolean

59
00:04:04,890 --> 00:04:05,880
‫parameter.

60
00:04:06,240 --> 00:04:12,570
‫So we're going to do this so that basically it should be true if the if the controller that we're talking

61
00:04:12,570 --> 00:04:18,990
‫to the controller currently in the for loop is a player controller and the boolean that we had passed

62
00:04:18,990 --> 00:04:23,700
‫in says that the player controller is the winner should also be true.

63
00:04:23,700 --> 00:04:31,290
‫If it is not a player controller and not the player, the player is the winner basically saying if this

64
00:04:31,290 --> 00:04:38,190
‫is an ally and the I is the winner false if the player controller but the player isn't the winner and

65
00:04:38,190 --> 00:04:40,890
‫false if not the player controller, but the player is the winner.

66
00:04:40,890 --> 00:04:43,530
‫You kind of see where this is going, hopefully.

67
00:04:43,530 --> 00:04:46,680
‫So pause the video and have a go at implementing it like this.

68
00:04:46,680 --> 00:04:47,940
‫You might use if statements.

69
00:04:47,940 --> 00:04:53,820
‫You might use some other logic to allow you to calculate this boolean pause video and have a go.

70
00:04:54,930 --> 00:04:55,380
‫Okay.

71
00:04:55,380 --> 00:04:55,950
‫Welcome back.

72
00:04:55,950 --> 00:04:57,930
‫So you could do this a number of ways.

73
00:04:57,930 --> 00:05:05,250
‫One way might be to say if the bee is player, control a winner and then we're going to put something

74
00:05:05,250 --> 00:05:14,430
‫in this if statement we might do a bool up here to decide that basically B is player controller.

75
00:05:15,210 --> 00:05:18,990
‫Which we're going to save from the fact that we do a controller.

76
00:05:19,840 --> 00:05:23,740
‫Arrow the is player controller like so.

77
00:05:24,130 --> 00:05:28,310
‫And then we might say, okay, well we want to call controller.

78
00:05:28,330 --> 00:05:31,060
‫Arrow game has ended.

79
00:05:31,210 --> 00:05:33,280
‫We're going to pass in the null pointer for now.

80
00:05:33,280 --> 00:05:40,690
‫And then we're going to say, well, if it is a player that is the winner and we are a player controller,

81
00:05:40,690 --> 00:05:43,300
‫then yes, basically go with that value.

82
00:05:43,300 --> 00:05:44,980
‫So play a controller.

83
00:05:45,010 --> 00:05:48,100
‫Otherwise, if it's not the player controller, it's going to have lost.

84
00:05:48,100 --> 00:05:55,360
‫And we can just negate this so we can say else there we're going to do call the controller game has

85
00:05:55,360 --> 00:06:02,710
‫ended with not is player controller basically because we're saying the player is not the winner, the

86
00:06:02,710 --> 00:06:04,900
‫eye is the winner in this statement.

87
00:06:04,900 --> 00:06:11,710
‫And so what we want to do is say that the depends on whether basically the opposite of whether the player

88
00:06:11,710 --> 00:06:14,380
‫has won, which is to say that the eye has won.

89
00:06:14,680 --> 00:06:17,370
‫So that's one way of doing it for sure.

90
00:06:17,380 --> 00:06:22,990
‫But there is another and simpler way, which is simply to say, are we the winner?

91
00:06:22,990 --> 00:06:26,020
‫So be is winner.

92
00:06:26,530 --> 00:06:36,790
‫And this can simply be to say that whether you are the player controller is equal to be is player winner.

93
00:06:36,970 --> 00:06:42,910
‫Now let's think about this a little bit more and I'll just complete this fully and then we'll talk about

94
00:06:42,910 --> 00:06:43,000
‫it.

95
00:06:43,000 --> 00:06:52,060
‫So we're going to say controller game has ended is going to be the null pointer with the be is winner

96
00:06:52,060 --> 00:06:53,050
‫passed in here.

97
00:06:53,950 --> 00:06:56,630
‫Now, why does this statement work?

98
00:06:56,650 --> 00:06:58,630
‫Well, let's think about the cases, right?

99
00:06:58,630 --> 00:07:04,300
‫So we have a player controller in here and the player is the winner, then?

100
00:07:04,300 --> 00:07:06,730
‫Yes, we are the winner and they are equal.

101
00:07:06,730 --> 00:07:07,720
‫True and true.

102
00:07:08,290 --> 00:07:13,660
‫How about if this is not the player controller and the player is not the winner?

103
00:07:13,690 --> 00:07:15,370
‫Well, then this is false.

104
00:07:15,370 --> 00:07:21,570
‫And this over here is also false so that the two of them are equal and the result is a winner.

105
00:07:21,580 --> 00:07:22,100
‫Is that true?

106
00:07:22,120 --> 00:07:27,370
‫Yes, because if we are the AI and the AI is the winner, then we should be the winner.

107
00:07:27,880 --> 00:07:33,370
‫Otherwise, if these two are not equal, i.e. that we've got an AI controller, but the player is the

108
00:07:33,370 --> 00:07:39,190
‫winner, or we've got the player controller and the AI is the winner, then we're going to have a true

109
00:07:39,190 --> 00:07:40,960
‫and false or a false and true.

110
00:07:41,170 --> 00:07:45,280
‫These two aren't going to be equal and the boolean is going to evaluate to false.

111
00:07:45,280 --> 00:07:50,980
‫So you can see that in each of the cases and I've gone through all of the cases there, this ends up

112
00:07:50,980 --> 00:07:51,730
‫with the right answer.

113
00:07:51,730 --> 00:07:53,740
‫So we know that this is the right answer.

114
00:07:53,740 --> 00:07:58,390
‫This is the great thing about Booleans is that usually you can evaluate all of the cases because you

115
00:07:58,390 --> 00:08:00,400
‫can say, okay, well, what are the cases?

116
00:08:00,400 --> 00:08:01,870
‫It's going to be true and true.

117
00:08:01,870 --> 00:08:02,980
‫It's going to be true and false.

118
00:08:02,980 --> 00:08:03,970
‫It's going to be false and true.

119
00:08:03,970 --> 00:08:05,280
‫It's going to be false and false.

120
00:08:05,290 --> 00:08:06,940
‫You can evaluate all those cases.

121
00:08:06,940 --> 00:08:12,610
‫If all of those cases are correct, then you know you've got a correct Boolean statement.

122
00:08:13,090 --> 00:08:13,600
‫Cool.

123
00:08:13,600 --> 00:08:15,880
‫So that's how we're going to calculate the B is winner.

124
00:08:15,880 --> 00:08:18,460
‫Finally, we just need to call our end game mode.

125
00:08:18,460 --> 00:08:24,280
‫At the moment we're doing a direct call to the play controller game has ended and what I actually want

126
00:08:24,280 --> 00:08:31,630
‫to do here is go ahead and call end game and we want to pass in false because this is a situation where

127
00:08:31,630 --> 00:08:36,630
‫the player has actually lost and that's basically what we want to achieve.

128
00:08:36,640 --> 00:08:42,340
‫Now, one more thing to note here is that this null pointer we've been passing in is going to lead us

129
00:08:42,400 --> 00:08:50,590
‫to problems down the road, because if the player has actually won, it's going to try and take away

130
00:08:50,590 --> 00:08:52,900
‫the focus from our player pawn.

131
00:08:52,900 --> 00:09:01,270
‫So what we want to pass in here is simply that the focus should be on the controller, dot get pawn.

132
00:09:01,660 --> 00:09:08,920
‫And that's basically saying that you should put the focus of your own player controller, be it basically

133
00:09:08,920 --> 00:09:10,630
‫where should your camera be pointing?

134
00:09:10,630 --> 00:09:12,550
‫It should still be pointing on your pawn.

135
00:09:12,970 --> 00:09:17,170
‫Why is it important that we do this and why is there this option here in the first place?

136
00:09:17,170 --> 00:09:23,890
‫Well, in a lot of games, you often or a lot of match style games, you might have that if the game

137
00:09:23,890 --> 00:09:27,400
‫has ended, you want to go and follow the pawn.

138
00:09:27,400 --> 00:09:28,300
‫That was the winner.

139
00:09:28,300 --> 00:09:34,300
‫So imagine like a Fortnite scenario, you often go and follow the person who killed you.

140
00:09:34,330 --> 00:09:36,430
‫This is the mechanism for doing this.

141
00:09:36,430 --> 00:09:40,470
‫You basically pass in the pawn of the person who did the killing.

142
00:09:40,480 --> 00:09:41,800
‫That's not what we're doing in our game.

143
00:09:41,800 --> 00:09:45,460
‫We're going to carry on looking at Apple and whether we'd win or we die.

144
00:09:45,460 --> 00:09:46,990
‫So that's pretty much it for the lecture.

145
00:09:46,990 --> 00:09:50,110
‫Let's just compile and see whether it's working.

146
00:09:50,110 --> 00:09:53,440
‫Let's dive on over into Unreal and hit play.

147
00:09:53,470 --> 00:09:56,110
‫Let's go and get ourselves killed.

148
00:09:56,110 --> 00:09:56,980
‫There you go.

149
00:09:56,980 --> 00:09:58,750
‫Everything's working as before.

150
00:09:58,750 --> 00:10:03,220
‫We're still getting that call to the player controller and then we restart.

151
00:10:03,220 --> 00:10:03,790
‫Great stuff.

152
00:10:03,790 --> 00:10:06,460
‫So in this lecture, just to recap, what have we seen?

153
00:10:06,460 --> 00:10:14,260
‫Well, we've seen how we can iterate over actors in the level in order to do something like calling

154
00:10:14,260 --> 00:10:16,930
‫a function on each of those actors.

155
00:10:16,930 --> 00:10:23,110
‫Next lecture we will be using the T actor range again, this time to calculate whether the player has

156
00:10:23,110 --> 00:10:23,680
‫won.

157
00:10:23,680 --> 00:10:24,400
‫See you there.

