





















































In this article by William Sherif, author of the book Learning C++ by Creating Games with UE4, we will really delve into UE4 code. At first, it is going to look daunting. The UE4 class framework is massive, but don't worry. The framework is massive, so your code doesn't have to be. You will find that you can get a lot done and a lot onto the screen using relatively less code. This is because the UE4 engine code is so extensive and well programmed that they have made it possible to get almost any game-related task done easily. Just call the right functions, and voila, what you want to see will appear on the screen. The entire notion of a framework is that it is designed to let you get the gameplay you want, without having to spend a lot of time in sweating out the details.
(For more resources related to this topic, see here.)
A Pawn is an object that represents something that you or the computer's Artificial Intelligence (AI) can control on the screen. The Pawn class derives from the Actor class, with the additional ability to be controlled by the player directly or by an AI script. When a pawn or actor is controlled by a controller or AI, it is said to be possessed by that controller or AI.
Think of the Actor class as a character in a play. Your game world is going to be composed of a bunch of actors, all acting together to make the gameplay work. The game characters, Non-player Characters (NPCs), and even treasure chests will be actors.
Here, we will start from scratch and create a basic level into which we can put our game characters.
The UE4 team has already done a great job of presenting how the world editor can be used to create a world in UE4. I want you to take a moment to create your own world.
First, create a new, blank UE4 project to get started. To do this, in the Unreal Launcher, click on the Launch button beside your most recent engine installation, as shown in the following screenshot:
That will launch the Unreal Editor. The Unreal Editor is used to visually edit your game world. You're going to spend a lot of time in the Unreal Editor, so please take your time to experiment and play around with it.
I will only cover the basics of how to work with the UE4 editor. You will need to let your creative juices flow, however, and invest some time in order to become familiar with the editor.
To learn more about the UE4 editor, take a look at the Getting Started: Introduction to the UE4 Editor playlist, which is available at https://www.youtube.com/playlist?list=PLZlv_N0_O1gasd4IcOe9Cx9wHoBB7rxFl.
Once you've launched the UE4 editor, you will be presented with the Projects dialog. The following screenshot shows the steps to be performed with numbers corresponding to the order in which they need to be performed:
Perform the following steps to create a project:
Once you've done this, the UE4 launcher will launch Visual Studio. There will only be a couple of source files in Visual Studio, but we're not going to touch those now. Make sure that Development Editor is selected from the Configuration Manager dropdown at the top of the screen, as shown in the following screenshot:
Now launch your project by pressing Ctrl + F5 in Visual Studio. You will find yourself in the Unreal Engine 4 editor, as shown in the following screenshot:
We will explore the UE4 editor here. We'll start with the controls since it is important to know how to navigate in Unreal.
If you've never used a 3D editor before, the controls can be quite hard to learn. These are the basic navigation controls while in edit mode:
Click on the Play button in the bar at the top, as shown in the following screenshot. This will launch the play mode.
Once you click on the Play button, the controls change. In play mode, the controls are as follows:
What I suggest you do at this point is try to add a bunch of shapes and objects into the scene and try to color them with different materials.
Adding objects to the scene is as easy as dragging and dropping them in from the Content Browser tab. The Content Browser tab appears, by default, docked at the left-hand side of the window. If it isn't seen, simply select Window and navigate to Content Browser in order to make it appear.
Make sure that the Content Browser is visible in order to add objects to your level
Next, select the Props folder on the left-hand side of the Content Browser.
Drag and drop things from the Content Browser into your game world
To resize an object, press R on your keyboard. The manipulators around the object will appear as boxes, which denotes resize mode.
Press R on your keyboard to resize an object
In order to change the material that is used to paint the object, simply drag and drop a new material from the Content Browser window inside the Materials folder.
Drag and drop a material from the Content Browser's Materials folder to color things with a new color
Materials are like paints. You can coat an object with any material you want by simply dragging and dropping the material you desire onto the object you desire it to be coated on. Materials are only skin-deep: they don't change the other properties of an object (such as weight).
If you want to start creating a level from scratch, simply click on File and navigate to New Level..., as shown here:
You can then select between Default and Empty Level. I think selecting Empty Level is a good idea, for the reasons that are mentioned later.
The new level will be completely black in color to start with. Try dragging and dropping some objects from the Content Browser tab again.
This time, I added a resized shapes / box for the ground plane and textured it with moss, a couple of Props / SM_Rocks, Particles / P_Fire, and most importantly, a light source.
Be sure to save your map. Here's a snapshot of my map (how does yours look?):
In this article, we reviewed how the realistic environments are created with actors and monsters which are part of the game and also seen how the various kind of levels are created from the scratch.
Further resources on this subject: