﻿1
00:00:04,320 --> 00:00:06,060
‫Hello and welcome this lecture.

2
00:00:06,060 --> 00:00:10,950
‫We're going to be looking at how we can write things to the output log and specifically how we can write

3
00:00:10,950 --> 00:00:16,290
‫the values of our variables into it that can help us debug our games.

4
00:00:16,290 --> 00:00:18,450
‫Let's dive in and see how this works.

5
00:00:19,470 --> 00:00:26,640
‫So in Blueprint we were able to write things to the screen when we wanted to quickly display some information

6
00:00:26,640 --> 00:00:30,340
‫or potentially to just debug something in the past.

7
00:00:30,360 --> 00:00:38,820
‫We have in C++ used a new property to do that, but we can actually do this using a log statement and

8
00:00:38,820 --> 00:00:43,610
‫it's a little bit complicated, unreal, which is why I've shied away from doing it until this point.

9
00:00:43,620 --> 00:00:47,850
‫So we're a bit more familiar with the C++ syntax before introducing it to you.

10
00:00:48,180 --> 00:00:56,430
‫Now, the way it works is if you've got the extension here, installed the unreal four snippets by caps

11
00:00:56,430 --> 00:01:00,570
‫and caps, this actually gets a little bit easier because you don't have to remember all of the complexity

12
00:01:00,570 --> 00:01:01,200
‫of the syntax.

13
00:01:01,200 --> 00:01:07,860
‫You just type, you log, and it will pop up with an IntelliSense dialog like this saying you log to

14
00:01:07,860 --> 00:01:13,590
‫help you write out the whole piece of code and you can hit, enter or select it with your mouse.

15
00:01:13,590 --> 00:01:18,240
‫And then what you're going to see is it's written out something that looks a bit like a function.

16
00:01:18,240 --> 00:01:21,120
‫It's not actually a function under the hood.

17
00:01:21,510 --> 00:01:27,660
‫It's got some a little bit of unreal magic going on here, but it's essentially a bit like a function.

18
00:01:27,660 --> 00:01:33,330
‫So what we're going to do here is we're passing in a couple of arguments to this function.

19
00:01:33,330 --> 00:01:40,890
‫The first one tells us what type of log category we are doing.

20
00:01:40,890 --> 00:01:44,700
‫The second one tells us the level of the log.

21
00:01:44,700 --> 00:01:46,860
‫So how urgent it is essentially.

22
00:01:47,160 --> 00:01:52,950
‫And then finally we have got this thing here, which is basically a function within a function which

23
00:01:52,950 --> 00:01:56,790
‫tells us the text that we need to print out.

24
00:01:57,060 --> 00:01:58,980
‫So how does this work?

25
00:01:58,980 --> 00:02:05,370
‫If we just leave this in our code, go over into unreal hit compile, we want to see where does it show

26
00:02:05,370 --> 00:02:05,730
‫up?

27
00:02:05,730 --> 00:02:10,230
‫Well, once the compilation has finished, we're going to go ahead and hit play.

28
00:02:10,530 --> 00:02:15,480
‫And what you're actually looking for is it's not going to be up on the screen here.

29
00:02:15,480 --> 00:02:17,520
‫It's going to be in the output.

30
00:02:17,520 --> 00:02:22,630
‫Log down here and you can see it just about here.

31
00:02:22,630 --> 00:02:28,230
‫It's saying, display your message and we've got how many messages?

32
00:02:28,230 --> 00:02:30,960
‫One, two, three, four, five.

33
00:02:31,110 --> 00:02:39,270
‫The reason for this is it's displaying the message for every single actor in our scene that is a moving

34
00:02:39,270 --> 00:02:39,930
‫platform.

35
00:02:39,960 --> 00:02:43,770
‫CP So that is why we're getting so many messages.

36
00:02:43,770 --> 00:02:48,030
‫And you can see we can change out the message to be whatever we wanted it to be here.

37
00:02:48,540 --> 00:02:57,180
‫And we could also put some more information into this message, such as the start location or the name

38
00:02:57,180 --> 00:02:59,100
‫of the actor, things like that.

39
00:02:59,280 --> 00:03:00,810
‫So here we go.

40
00:03:00,810 --> 00:03:04,980
‫So we've got an output log, we've got our message, and you can start to see what the categories I

41
00:03:04,980 --> 00:03:06,120
‫was talking about are.

42
00:03:06,120 --> 00:03:13,710
‫You can see we've got log temp here, but up above we've got log audio log audio mixer Log World.

43
00:03:13,710 --> 00:03:18,480
‫So there are different categories of logging that help us distinguish where is this message coming from?

44
00:03:18,480 --> 00:03:21,060
‫Which part of Unreal is this coming from?

45
00:03:21,060 --> 00:03:26,790
‫But log temp is mostly what we're going to use because it's just a temporary place for logging out debug

46
00:03:26,790 --> 00:03:29,340
‫messages and then there's display.

47
00:03:29,340 --> 00:03:35,130
‫This is the default level, log level, but we can have messages, be a bunch of different things.

48
00:03:35,130 --> 00:03:39,390
‫It can be display or any value from this table down here.

49
00:03:39,390 --> 00:03:43,680
‫So you see display here prints a message to the console and the log file.

50
00:03:43,680 --> 00:03:47,670
‫We've got the log down here which prints a message only to the log file and doesn't display it in the

51
00:03:47,670 --> 00:03:48,150
‫console.

52
00:03:48,150 --> 00:03:52,920
‫So this is for things where you don't really want it to show up so much, but might want to use it for

53
00:03:52,920 --> 00:03:53,400
‫debugging.

54
00:03:53,400 --> 00:03:58,770
‫If you're debugging someone's game and it ran on their machine, they're sending you a log file.

55
00:03:58,770 --> 00:04:00,270
‫Then you've got warning.

56
00:04:00,270 --> 00:04:06,870
‫This is for when things seem to be going wrong and it prints it to the log console and it is also in

57
00:04:06,870 --> 00:04:07,530
‫yellow.

58
00:04:07,560 --> 00:04:14,340
‫Then we've got error that prints it in red and then fatal, basically prints to the console and crashes

59
00:04:14,640 --> 00:04:15,480
‫the engine.

60
00:04:15,480 --> 00:04:21,720
‫So you kind of want to use this one as a last resort, but it does allow you to have different levels

61
00:04:21,720 --> 00:04:22,500
‫in the log file.

62
00:04:22,500 --> 00:04:27,330
‫And I'll just show you what it looks like if we put in different messages here.

63
00:04:27,330 --> 00:04:32,790
‫So I'm going to copy our line for logging and I'm going to make three of them.

64
00:04:32,790 --> 00:04:37,980
‫We're going to have a display, going to have a warning, and we're going to have an error.

65
00:04:37,980 --> 00:04:40,890
‫Now, these are typically the levels that we will use.

66
00:04:40,890 --> 00:04:43,980
‫So let's go ahead and have a look and see what they look like.

67
00:04:43,980 --> 00:04:49,170
‫Let's go into Unreal, hit the compile button and let's stop and restart play.

68
00:04:49,170 --> 00:04:55,290
‫And by the way, you can bring up the output log by hitting the tilde key twice.

69
00:04:55,380 --> 00:05:02,070
‫It brings up there you go, we've got our output log and you can see we've got three sets of message,

70
00:05:02,070 --> 00:05:05,970
‫the display which is just in the plain white warning, which is in yellow.

71
00:05:05,970 --> 00:05:09,690
‫So it stands out a little bit more, an error, obviously, which stands out a lot more.

72
00:05:09,690 --> 00:05:12,360
‫Now we can add data to our log messages.

73
00:05:12,360 --> 00:05:18,600
‫I'm just going to delete the warning and error lines of the log and we can add in some.

74
00:05:18,700 --> 00:05:21,280
‫Later into this string that's going to be printed out.

75
00:05:21,280 --> 00:05:27,190
‫The way we would do this is, for example, if I wanted to print out the move distance configured for

76
00:05:27,190 --> 00:05:34,480
‫a particular platform that's fairly straightforward to do, we can say configured move distance, and

77
00:05:34,480 --> 00:05:36,190
‫that's the text that's going to show up.

78
00:05:36,190 --> 00:05:37,840
‫I'm going to put a colon in here.

79
00:05:37,840 --> 00:05:44,560
‫And remember, this is all within the double quotes to make sure that we're including in the text.

80
00:05:45,010 --> 00:05:51,460
‫And then we can use a percent sign followed by the F character.

81
00:05:51,610 --> 00:05:57,360
‫And you see that gets highlighted differently because this is what is known as a format specified here.

82
00:05:57,400 --> 00:06:01,900
‫It's something that comes from C all the way back in history.

83
00:06:01,900 --> 00:06:07,540
‫And essentially usually you do a percentage sign and then some letter you can see the different letters

84
00:06:07,540 --> 00:06:08,350
‫down here.

85
00:06:08,380 --> 00:06:15,670
‫The F corresponds to a decimal floating point and you can see an example of what the output looks like

86
00:06:15,670 --> 00:06:17,410
‫over in the example column.

87
00:06:17,410 --> 00:06:26,530
‫And there's lots of other things down here we can represent with D or I a decimal integer like so.

88
00:06:26,980 --> 00:06:30,820
‫So we're using F because we've got a floating point number.

89
00:06:30,820 --> 00:06:35,230
‫And then what we have to do is add in another argument to the E log function.

90
00:06:35,230 --> 00:06:43,540
‫So make sure that you are doing this after you've closed the brackets for this text function and instead

91
00:06:43,540 --> 00:06:45,520
‫we're putting a comma after here.

92
00:06:45,520 --> 00:06:51,730
‫So between these two brackets, it should be inside of the outer set, but outside of the inner set,

93
00:06:51,730 --> 00:06:52,690
‫if that makes sense.

94
00:06:52,900 --> 00:07:00,910
‫And then what we can do is we can pass in the value of our variable so we can do the move distance variable

95
00:07:00,910 --> 00:07:04,390
‫like so let's go over into Unreal and see this in action.

96
00:07:04,390 --> 00:07:11,170
‫I hit the compile button, close down the compile window and hit play and then hit Tilde twice to bring

97
00:07:11,170 --> 00:07:11,860
‫up the log.

98
00:07:11,860 --> 00:07:17,980
‫And you can see our configured move distances showing up for the different platforms, 505 hundred for

99
00:07:17,980 --> 00:07:24,130
‫the two moving platforms and 1500 for the three pushes that we've got in the scene.

100
00:07:24,130 --> 00:07:29,620
‫So one piece of information that might be a little bit interesting or instructive is that we've previously

101
00:07:29,620 --> 00:07:36,370
‫talked about how we overshoot or we did overshoot the distance moved, and it would be interesting to

102
00:07:36,370 --> 00:07:39,490
‫know by what kind of levels that is happening.

103
00:07:39,490 --> 00:07:43,510
‫So what we could do is we could create a float variable inside the if statement.

104
00:07:43,510 --> 00:07:45,520
‫So we know that we've currently overshot.

105
00:07:45,520 --> 00:07:49,900
‫We can say overshoot a float variable called overshoot.

106
00:07:49,900 --> 00:07:56,440
‫We're going to set it equal to the distance moved minus the move distance.

107
00:07:56,440 --> 00:07:59,740
‫So that tells us how much the overshoot was.

108
00:07:59,740 --> 00:08:04,330
‫So I'd like you to have a go at logging the overshoot variable that we just created here.

109
00:08:04,330 --> 00:08:06,610
‫So use the Yule log function.

110
00:08:06,610 --> 00:08:11,470
‫Here it is for reference at least the kind of structure that you will probably be using.

111
00:08:11,470 --> 00:08:19,330
‫You can also practice using that you log autocomplete to put it in instead and then compile and test

112
00:08:19,330 --> 00:08:21,220
‫your code and see if it works.

113
00:08:21,220 --> 00:08:22,660
‫Pause the video and have a go.

114
00:08:25,690 --> 00:08:26,170
‫Okay.

115
00:08:26,170 --> 00:08:26,970
‫Welcome back.

116
00:08:26,980 --> 00:08:30,790
‫So we're going to use the autocomplete option here.

117
00:08:30,790 --> 00:08:33,280
‫I'm just going to close down my sidebar to have a little bit more space.

118
00:08:33,400 --> 00:08:40,450
‫And then inside this, if after we've created the variable, we are going to type you log and hit enter

119
00:08:40,960 --> 00:08:43,360
‫and then we're going to leave it at display.

120
00:08:43,360 --> 00:08:52,690
‫We're going to make the text platform overshot by and then we're going to use percent F and then between

121
00:08:52,690 --> 00:09:00,970
‫these two brackets, we're going to add a new argument for the overshoot variable like so now let's

122
00:09:00,970 --> 00:09:02,020
‫head back into Unreal.

123
00:09:02,050 --> 00:09:08,770
‫I hit the compile button, close down the live coding log, hit play and double tap that tilde key.

124
00:09:09,310 --> 00:09:15,340
‫And you can see that every time the platform is turning around, it is printing out a log message and

125
00:09:15,340 --> 00:09:17,560
‫saying how many units it overshot by.

126
00:09:17,560 --> 00:09:18,730
‫You can actually see the net.

127
00:09:18,730 --> 00:09:26,200
‫A lot of cases it's overshooting by quite a few, quite a noticeable amount of units, three units or

128
00:09:26,200 --> 00:09:27,190
‫0.5 units.

129
00:09:27,190 --> 00:09:30,370
‫That's basically 0.5% to three centimeters.

130
00:09:30,370 --> 00:09:35,230
‫It's enough that over the course of your game these platforms could have been drifting.

131
00:09:35,230 --> 00:09:39,250
‫And that's great that we've implemented a fix for that already.

132
00:09:39,280 --> 00:09:39,760
‫Great stuff.

133
00:09:39,760 --> 00:09:45,280
‫So hopefully now you've got another tool in your arsenal for trying to figure out what's going on inside

134
00:09:45,280 --> 00:09:45,880
‫your code.

135
00:09:45,880 --> 00:09:51,220
‫And later on when you are feeling more confident in making your own code, trying to figure out what's

136
00:09:51,220 --> 00:09:53,020
‫not working so well.

137
00:09:53,470 --> 00:09:56,020
‫Okay, I will see you in the next lecture.

