﻿1
00:00:04,430 --> 00:00:05,360
‫Hello and welcome.

2
00:00:05,360 --> 00:00:09,830
‫In this lecture, we're going to be learning about something called the world object, a very important

3
00:00:09,830 --> 00:00:10,820
‫object in Unreal.

4
00:00:10,820 --> 00:00:16,340
‫I'm going to see how we can get the current time in our game from this object and print it out to the

5
00:00:16,340 --> 00:00:18,500
‫console by the end of this lecture.

6
00:00:18,500 --> 00:00:20,690
‫So let's dive in and see how this works.

7
00:00:21,230 --> 00:00:28,280
‫So to be able to do line tracers or sweeps, we need to understand another concept, another type of

8
00:00:28,280 --> 00:00:34,550
‫object that exists in unreal land, and that object is the world.

9
00:00:34,550 --> 00:00:37,640
‫So we've dealt a lot with levels.

10
00:00:37,640 --> 00:00:41,540
‫So if we go to our content draw, we've dealt with maps as well.

11
00:00:41,540 --> 00:00:46,790
‫So the map and level we've kind of talked about as being synonymous.

12
00:00:46,790 --> 00:00:51,050
‫However, a world is kind of there in the beginning.

13
00:00:51,050 --> 00:00:59,120
‫In the beginning was the new world and the new world is the type, is the class for basically the environment

14
00:00:59,120 --> 00:01:01,940
‫that we're seeing when we play a game.

15
00:01:02,300 --> 00:01:05,360
‫But it's not just necessarily one level.

16
00:01:05,360 --> 00:01:12,830
‫You can load a level which is called a you level in C++, which is just a collection of the actors that

17
00:01:12,830 --> 00:01:14,750
‫we should bring into the new world.

18
00:01:14,750 --> 00:01:19,730
‫So you can load a level into your world, but not just necessarily one level.

19
00:01:19,730 --> 00:01:23,510
‫You may load in multiple levels into a single world.

20
00:01:23,510 --> 00:01:28,280
‫And that's because often we have these streaming levels, we have very large levels where we don't want

21
00:01:28,280 --> 00:01:32,510
‫to load everything, every actor into the level in one go for performance reasons.

22
00:01:32,510 --> 00:01:38,930
‫So we split it up into multiple levels and that allows us to bring in only parts of the scene as they're

23
00:01:38,930 --> 00:01:39,860
‫required.

24
00:01:39,860 --> 00:01:44,780
‫So if we have a look at the documentation page on New World, I think it describes it rather succinctly

25
00:01:44,780 --> 00:01:51,020
‫that the world is the top level object representing a map or a sandbox in which actors and components

26
00:01:51,020 --> 00:01:52,820
‫will exist and be rendered.

27
00:01:52,820 --> 00:01:57,500
‫And if you look a little bit further down, it says that the world can be a single persistent level,

28
00:01:57,500 --> 00:02:03,890
‫basically meaning a level that will constantly be there or with potentially an optional list of streaming

29
00:02:03,890 --> 00:02:07,730
‫levels or basically levels that can be loaded whenever we want.

30
00:02:08,150 --> 00:02:10,850
‫Now, why is any of this interesting?

31
00:02:10,910 --> 00:02:14,600
‫It's interesting because it allows us to do line tracing.

32
00:02:14,600 --> 00:02:20,600
‫If we search the documentation here for line trace, then you will see that there's a bunch of functionality

33
00:02:20,600 --> 00:02:28,340
‫here, particularly the one that's most interesting to us is the line trace single by channel or the

34
00:02:28,340 --> 00:02:36,020
‫line trace multi by channel, which essentially allows us respectively to get hold of that first object

35
00:02:36,020 --> 00:02:39,170
‫hit or all of the objects hit by a line trace.

36
00:02:39,320 --> 00:02:45,350
‫And you can see that the list of arguments, especially if I look at the line trace single, the list

37
00:02:45,350 --> 00:02:52,520
‫of arguments has the start, it has the end, it has a trace channel for which to do the trace.

38
00:02:52,520 --> 00:02:58,100
‫And it actually gives us a result in the parameter list, which is a little bit strange and we will

39
00:02:58,100 --> 00:02:59,570
‫be covering that shortly.

40
00:02:59,960 --> 00:03:02,000
‫But anyway, this is the line trace.

41
00:03:02,000 --> 00:03:05,570
‫We also have the ability to do a sweep.

42
00:03:05,570 --> 00:03:09,980
‫So if we search for sweep, you can see there is a sweep multi bi channel.

43
00:03:10,010 --> 00:03:12,620
‫There's also a sweep single by channel.

44
00:03:12,620 --> 00:03:20,180
‫And here as well as the start and end, you also have a collision f collision shape type that you can

45
00:03:20,180 --> 00:03:20,690
‫pass in.

46
00:03:20,690 --> 00:03:26,900
‫Basically if we click on that F collision shape, you can follow through in the documentation in Unreal

47
00:03:26,900 --> 00:03:33,650
‫to read more about it and you can see that F collision shape basically supports being either a sphere

48
00:03:33,650 --> 00:03:36,440
‫capsule box or a line.

49
00:03:36,440 --> 00:03:43,280
‫So we're going to be using the sphere in our case like so and we'll see how to construct these later

50
00:03:43,280 --> 00:03:43,880
‫on.

51
00:03:43,880 --> 00:03:48,530
‫But you can see why we want to get hold of that new world, why it's important to us.

52
00:03:48,530 --> 00:03:52,550
‫But the question is how do we get hold of the new world?

53
00:03:52,550 --> 00:03:55,490
‫And once we've got hold of it, how do we use it?

54
00:03:55,850 --> 00:03:59,360
‫Well, let's go and have a look in Visual Studio code.

55
00:03:59,990 --> 00:04:06,710
‫On every component and every actor, there is a function called Get World.

56
00:04:06,890 --> 00:04:12,800
‫And if you type get world and then parentheses, this returns an object of type U world.

57
00:04:12,800 --> 00:04:16,070
‫In fact, a pointer to an object of type new world.

58
00:04:16,070 --> 00:04:17,090
‫So let's store that.

59
00:04:17,090 --> 00:04:23,690
‫We've got a New World pointer, which is going to be we'll just call it the world, shall we?

60
00:04:23,870 --> 00:04:25,700
‫And that's equal to get world.

61
00:04:25,700 --> 00:04:28,550
‫And then we can put a semicolon at the end there.

62
00:04:28,550 --> 00:04:34,550
‫Now, in order to actually get hold of anything from this world, we're going to use the arrow operator.

63
00:04:34,550 --> 00:04:40,310
‫So we're going to do World Arrow, and then we would be able to go and have a look at some of the details

64
00:04:40,310 --> 00:04:41,300
‫of that world.

65
00:04:41,300 --> 00:04:47,330
‫But before we do that, we need to include its header file because otherwise this C++ file, when the

66
00:04:47,330 --> 00:04:52,580
‫compiler gets to it, isn't going to know what is included inside a new world type.

67
00:04:52,580 --> 00:04:55,700
‫It has no information about a new world whatsoever.

68
00:04:55,850 --> 00:04:59,990
‫So to fix that, we need to look at our documentation for New World.

69
00:04:59,990 --> 00:05:03,470
‫Scroll to the top and look for that place where it.

70
00:05:03,570 --> 00:05:10,530
‫Says include and that gives us the include we need to use you can see include quote engine Ford slash

71
00:05:10,530 --> 00:05:18,990
‫world that's what we need so we'll just put that after I grab a H here and now if we hit control space,

72
00:05:18,990 --> 00:05:23,670
‫we should get a list of the things that we can do with this particular world.

73
00:05:23,670 --> 00:05:26,400
‫And there's many of them we've got.

74
00:05:26,400 --> 00:05:34,770
‫Obviously, we can find our line trace, we can find our sweep by multi or single.

75
00:05:34,770 --> 00:05:38,070
‫So I'd like to challenge you to print the time lapse.

76
00:05:38,070 --> 00:05:42,030
‫This is a property available on the New World object.

77
00:05:42,060 --> 00:05:48,060
‫You're going to find the time seconds property read up about it in the documentation which is linked

78
00:05:48,060 --> 00:05:53,010
‫against this lecture and store it in a variable of the appropriate type.

79
00:05:53,010 --> 00:05:58,950
‫Again, looking at the documentation will tell you what the type should be and then log that to the

80
00:05:58,950 --> 00:06:01,260
‫console again using the appropriate format.

81
00:06:01,260 --> 00:06:03,900
‫Specify a pause video and have a go.

82
00:06:07,350 --> 00:06:08,340
‫Okay welcome back.

83
00:06:08,340 --> 00:06:13,890
‫So we're going to make use of this in and the if I searched through for time in the new world documentation

84
00:06:13,890 --> 00:06:17,790
‫you can see there is a float called time seconds.

85
00:06:17,790 --> 00:06:21,360
‫That's the one that I want in this case is this is the game time.

86
00:06:21,360 --> 00:06:26,040
‫So if you slow down or speed up time, this gets slowed down or sped up as well.

87
00:06:26,040 --> 00:06:29,280
‫But there are ones where that doesn't get affected.

88
00:06:29,580 --> 00:06:30,480
‫There's different ones.

89
00:06:30,480 --> 00:06:33,570
‫You've got the time, seconds, the unpause time, seconds.

90
00:06:33,570 --> 00:06:38,700
‫There's also the real time seconds, which doesn't get paused or changed in any way.

91
00:06:38,910 --> 00:06:40,590
‫So I'm interested in the time seconds.

92
00:06:40,590 --> 00:06:43,710
‫It doesn't really matter which one we use because they're all floats anyway.

93
00:06:43,710 --> 00:06:48,360
‫So I'm going to create a float called Time and store the World Arrow Time.

94
00:06:48,360 --> 00:06:53,940
‫Seconds in there now for short, we don't actually need to put the world into its own variable.

95
00:06:53,940 --> 00:06:56,790
‫It's quite short enough to just call get world.

96
00:06:56,790 --> 00:06:57,960
‫So that's what we typically do.

97
00:06:57,960 --> 00:07:01,590
‫Will do get world then arrow time seconds like.

98
00:07:01,590 --> 00:07:12,420
‫So now we can do a log which we're going to say the current time is and then we're going to do a percent

99
00:07:12,420 --> 00:07:18,840
‫F because we are printing out a floating point number here and then we can give it the time as the inputs

100
00:07:18,840 --> 00:07:19,790
‫into the log.

101
00:07:19,800 --> 00:07:28,440
‫Now let's go control alt f 11 to live code and then we're going to open up and dock the output log.

102
00:07:29,760 --> 00:07:31,620
‫And hit play.

103
00:07:32,670 --> 00:07:39,570
‫And there you can see that we've got a current time which is counting up in seconds as the time elapses

104
00:07:39,570 --> 00:07:40,860
‫in our game like so.

105
00:07:40,860 --> 00:07:47,580
‫And if we actually hit the pause button, you notice that the time stops going and if we hit play it

106
00:07:47,580 --> 00:07:50,310
‫just resumes from where we were.

107
00:07:50,610 --> 00:07:51,150
‫He wants to.

108
00:07:51,150 --> 00:07:56,130
‫You could experiment with using the real time seconds and see whether that effect happens.

109
00:07:56,220 --> 00:07:57,690
‫But I'm not going to here.

110
00:07:57,690 --> 00:08:03,600
‫We've shown that we can get hold of this new world objects, this world object that we are currently

111
00:08:03,600 --> 00:08:07,980
‫in and that we can get properties from it using our arrow.

112
00:08:07,980 --> 00:08:11,580
‫Operator Pat yourself on the back and I'll see you in the next lecture.

