Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds

Actors and Pawns

Save for later
  • 420 min read
  • 2015-02-23 00:00:00

article-image

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.)

Actors versus pawns

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.

Creating a world to put your actors in

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:actors-and-pawns-img-0

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:actors-and-pawns-img-1

Perform the following steps to create a project:

  1. Select the New Project tab at the top of the screen.
  2. Click on the C++ tab (the second subtab).
  3. Then select Basic Code from the available projects listing.
  4. Set the directory where your project is located (mine is Y:Unreal Projects). Choose a hard disk location with a lot of space (the final project will be around 1.5 GB).
  5. Name your project. I called mine GoldenEgg.
  6. Click on Create Project to finalize project creation.

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:actors-and-pawns-img-2

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:actors-and-pawns-img-3

The UE4 editor

We will explore the UE4 editor here. We'll start with the controls since it is important to know how to navigate in Unreal.

Editor controls

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:

  • Use the arrow keys to move around in the scene
  • Press Page Up or Page Down to go up and down vertically
  • Left mouse click + drag it left or right to change the direction you are facing
  • Left mouse click + drag it up or down to dolly (move the camera forward and backward, same as pressing up/down arrow keys)
  • Right mouse click + drag to change the direction you are facing
  • Middle mouse click + drag to pan the view
  • Right mouse click and the W, A, S, and D keys to move around the scene

Play mode controls

Click on the Play button in the bar at the top, as shown in the following screenshot. This will launch the play mode.actors-and-pawns-img-4

Once you click on the Play button, the controls change. In play mode, the controls are as follows:

Unlock access to the largest independent learning library in Tech for FREE!
Get unlimited access to 7500+ expert-authored eBooks and video courses covering every tech area you can think of.
Renews at ₹800/month. Cancel anytime
  • The W, A, S, and D keys for movement
  • The left or right arrow keys to look toward the left and right, respectively
  • The mouse's motion to change the direction in which you look
  • The Esc key to exit play mode and return to edit mode

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

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.actors-and-pawns-img-5

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.actors-and-pawns-img-6

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.actors-and-pawns-img-7

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.actors-and-pawns-img-8

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).

Starting from scratch

If you want to start creating a level from scratch, simply click on File and navigate to New Level..., as shown here:actors-and-pawns-img-9

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.actors-and-pawns-img-10

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?):actors-and-pawns-img-11

Summary

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.

Resources for Article:


Further resources on this subject: