‫Hello and welcome.
‫In this lecture, we're going to be learning about something called the world object, a very important
‫object in Unreal.
‫I'm going to see how we can get the current time in our game from this object and print it out to the
‫console by the end of this lecture.
‫So let's dive in and see how this works.
‫So to be able to do line tracers or sweeps, we need to understand another concept, another type of
‫object that exists in unreal land, and that object is the world.
‫So we've dealt a lot with levels.
‫So if we go to our content draw, we've dealt with maps as well.
‫So the map and level we've kind of talked about as being synonymous.
‫However, a world is kind of there in the beginning.
‫In the beginning was the new world and the new world is the type, is the class for basically the environment
‫that we're seeing when we play a game.
‫But it's not just necessarily one level.
‫You can load a level which is called a you level in C++, which is just a collection of the actors that
‫we should bring into the new world.
‫So you can load a level into your world, but not just necessarily one level.
‫You may load in multiple levels into a single world.
‫And that's because often we have these streaming levels, we have very large levels where we don't want
‫to load everything, every actor into the level in one go for performance reasons.
‫So we split it up into multiple levels and that allows us to bring in only parts of the scene as they're
‫required.
‫So if we have a look at the documentation page on New World, I think it describes it rather succinctly
‫that the world is the top level object representing a map or a sandbox in which actors and components
‫will exist and be rendered.
‫And if you look a little bit further down, it says that the world can be a single persistent level,
‫basically meaning a level that will constantly be there or with potentially an optional list of streaming
‫levels or basically levels that can be loaded whenever we want.
‫Now, why is any of this interesting?
‫It's interesting because it allows us to do line tracing.
‫If we search the documentation here for line trace, then you will see that there's a bunch of functionality
‫here, particularly the one that's most interesting to us is the line trace single by channel or the
‫line trace multi by channel, which essentially allows us respectively to get hold of that first object
‫hit or all of the objects hit by a line trace.
‫And you can see that the list of arguments, especially if I look at the line trace single, the list
‫of arguments has the start, it has the end, it has a trace channel for which to do the trace.
‫And it actually gives us a result in the parameter list, which is a little bit strange and we will
‫be covering that shortly.
‫But anyway, this is the line trace.
‫We also have the ability to do a sweep.
‫So if we search for sweep, you can see there is a sweep multi bi channel.
‫There's also a sweep single by channel.
‫And here as well as the start and end, you also have a collision f collision shape type that you can
‫pass in.
‫Basically if we click on that F collision shape, you can follow through in the documentation in Unreal
‫to read more about it and you can see that F collision shape basically supports being either a sphere
‫capsule box or a line.
‫So we're going to be using the sphere in our case like so and we'll see how to construct these later
‫on.
‫But you can see why we want to get hold of that new world, why it's important to us.
‫But the question is how do we get hold of the new world?
‫And once we've got hold of it, how do we use it?
‫Well, let's go and have a look in Visual Studio code.
‫On every component and every actor, there is a function called Get World.
‫And if you type get world and then parentheses, this returns an object of type U world.
‫In fact, a pointer to an object of type new world.
‫So let's store that.
‫We've got a New World pointer, which is going to be we'll just call it the world, shall we?
‫And that's equal to get world.
‫And then we can put a semicolon at the end there.
‫Now, in order to actually get hold of anything from this world, we're going to use the arrow operator.
‫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
‫of that world.
‫But before we do that, we need to include its header file because otherwise this C++ file, when the
‫compiler gets to it, isn't going to know what is included inside a new world type.
‫It has no information about a new world whatsoever.
‫So to fix that, we need to look at our documentation for New World.
‫Scroll to the top and look for that place where it.
‫Says include and that gives us the include we need to use you can see include quote engine Ford slash
‫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,
‫we should get a list of the things that we can do with this particular world.
‫And there's many of them we've got.
‫Obviously, we can find our line trace, we can find our sweep by multi or single.
‫So I'd like to challenge you to print the time lapse.
‫This is a property available on the New World object.
‫You're going to find the time seconds property read up about it in the documentation which is linked
‫against this lecture and store it in a variable of the appropriate type.
‫Again, looking at the documentation will tell you what the type should be and then log that to the
‫console again using the appropriate format.
‫Specify a pause video and have a go.
‫Okay welcome back.
‫So we're going to make use of this in and the if I searched through for time in the new world documentation
‫you can see there is a float called time seconds.
‫That's the one that I want in this case is this is the game time.
‫So if you slow down or speed up time, this gets slowed down or sped up as well.
‫But there are ones where that doesn't get affected.
‫There's different ones.
‫You've got the time, seconds, the unpause time, seconds.
‫There's also the real time seconds, which doesn't get paused or changed in any way.
‫So I'm interested in the time seconds.
‫It doesn't really matter which one we use because they're all floats anyway.
‫So I'm going to create a float called Time and store the World Arrow Time.
‫Seconds in there now for short, we don't actually need to put the world into its own variable.
‫It's quite short enough to just call get world.
‫So that's what we typically do.
‫Will do get world then arrow time seconds like.
‫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
‫F because we are printing out a floating point number here and then we can give it the time as the inputs
‫into the log.
‫Now let's go control alt f 11 to live code and then we're going to open up and dock the output log.
‫And hit play.
‫And there you can see that we've got a current time which is counting up in seconds as the time elapses
‫in our game like so.
‫And if we actually hit the pause button, you notice that the time stops going and if we hit play it
‫just resumes from where we were.
‫He wants to.
‫You could experiment with using the real time seconds and see whether that effect happens.
‫But I'm not going to here.
‫We've shown that we can get hold of this new world objects, this world object that we are currently
‫in and that we can get properties from it using our arrow.
‫Operator Pat yourself on the back and I'll see you in the next lecture.