Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Blueprints Visual Scripting for Unreal engine
Blueprints Visual Scripting for Unreal engine

Blueprints Visual Scripting for Unreal engine: Build professional 3D games with Unreal Engine 4's Visual Scripting system

Arrow left icon
Profile Icon Brenden Sewell
Arrow right icon
Free Trial
Full star icon Full star icon Full star icon Full star icon Half star icon 4.1 (28 Ratings)
Paperback Jul 2015 188 pages 1st Edition
eBook
S$24.99 S$35.99
Paperback
S$44.99
Subscription
Free Trial
Arrow left icon
Profile Icon Brenden Sewell
Arrow right icon
Free Trial
Full star icon Full star icon Full star icon Full star icon Half star icon 4.1 (28 Ratings)
Paperback Jul 2015 188 pages 1st Edition
eBook
S$24.99 S$35.99
Paperback
S$44.99
Subscription
Free Trial
eBook
S$24.99 S$35.99
Paperback
S$44.99
Subscription
Free Trial

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
Table of content icon View table of contents Preview book icon Preview Book

Blueprints Visual Scripting for Unreal engine

Chapter 1. Object Interaction with Blueprints

When setting out to develop a game, one of the first steps toward exploring your idea is to build a prototype. Fortunately, Unreal Engine 4 and Blueprints make it easier than ever to quickly get the essential gameplay functionality working so that you can start testing your ideas sooner. To develop some familiarity with the Unreal editor and Blueprints, we will begin by prototyping simple gameplay mechanics using some default assets and a couple of Blueprints.

In this chapter, we will cover the following topics:

  • Creating a new project and a level
  • Placing objects in a level
  • Changing an object's material through Blueprints
  • Using the Blueprint editor and connecting Blueprints together
  • Compiling, saving, and playing our game
  • Moving objects in the world with Blueprints

Creating a project and the first level

Before we can begin setting up gameplay elements, we need to create a project that will contain the content of our game. To access Unreal Engine 4 and begin setting up our project, we must first open the Epic Games Launcher, which can be downloaded from the Unreal Engine 4 website (https://www.unrealengine.com/). From the Epic Games Launcher, click on the tab labeled Unreal Engine. If you are using Unreal Engine on your computer for the first time, you will see a grayed out-button labeled Not Installed. Along the left-hand side of the launcher, you will see options.

The Library tab is the location where you will be able to access the versions of the engine you have installed and the projects you have built. Now click on the Library tab, find the yellow Install button (as seen in the following screenshot), and click on it:

Creating a project and the first level

When the engine has finished installing, the Install buttons will change to Launch buttons, as shown in the following screenshot. Click on any of the Launch buttons to open the engine.

Creating a project and the first level

Setting a template for a new project

Once you click on Launch, you will be presented with the Unreal Project Browser. This will by default take you to the Projects tab, which will show you a thumbnail view of all the projects you have created, as well as any sample projects you might choose to install. For our purposes, we want to start a new project, so click on the tab labeled New Project.

From the New Project tab, you can select a template that will give you the initial assets to use for your game; or you can choose to start a blank project. You will see two subtabs under the New Project tab, labeled Blueprint and C++. Creating a project from the content within the Blueprint tab will start your project with a basic set of behavior built using Blueprints. The C++ tab is used to create projects where at least some of the core types of behavior of the game are going to be built using the C++ programming language. Since we quickly want to get a prototype first-person shooter up and running without having to build the basic controls from scratch, we should ensure that we have the tab labeled Blueprint selected. Then we choose the First Person template, as shown here:

Setting a template for a new project

Making sense of the project settings

The next step is to adjust the project settings to our liking. The three gray boxes below the template selector allow us to select the class of hardware we are targeting (desktop/console or mobile/tablet), the graphics scalability, and whether we want to create our project with or without starter content. Leave these settings at their default values (Desktop/Console, Maximum Quality, and With Starter Content). Below these, you will see a folder path field used to designate where you would like to store your project on your hard drive, and a name field to input the name by which your project will be known. I named the project BlueprintScripting and stored it in the default Unreal Projects folder for OS X, as shown in this screenshot:

Making sense of the project settings

Creating the project

Now that we have a template selected and the project settings set up the way we like, we can create the project. To do so, click on the green Create Project button. After the engine is done with initializing the assets and setting up your project, Unreal Editor will open Level Editor, where you can create and view levels, place and modify objects, and test your game as you modify it.

Pressing the Play button, as shown in the following screenshot, along the top of the toolbar, will allow you to try the default gameplay that comes built into the First Person template. This includes player movement, shooting a simple projectile, and using projectiles to apply force to primitive box objects. In play mode, the Play button will be replaced with a Pause button and a Stop button. You can press the Pause button to temporarily halt the play session, which can be useful when you want to explore the properties of an interaction or actor that you just encountered during gameplay. Pressing the Stop button will end the play session and take you back to editing mode. Go ahead and try playing the game before we continue.

Creating the project

Adding objects to our level

Now we want to start adding our own objects to the level. The central panel you see in Level Editor is known as 3D Viewport. A viewport allows you to see the 3D content of the game, and it is important that you become familiar with navigating inside this panel. The viewport can be navigated by moving the camera around using a combination of mouse buttons and its movement. Holding down the left mouse button and dragging the mouse pointer inside the viewport moves the camera view forward and backward, or left and right. Holding down the right mouse button and moving the mouse allows you to look around by rotating the camera. Finally, holding down either the middle mouse button or a combination of both the left and right mouse buttons will allow you to drag the camera up and down.

The simplest kind of object that can be dragged into the game world in Unreal Engine 4 is called an actor. An actor is a basic object with no inherent behavior other than the ability to be rotated, moved, and scaled, but it can be expanded to include more complex behavior by attaching components. Our goal will be to create a simple target actor that will change color when shot with the included gun and projectile. We can create a simple actor by going to the Modes panel. With the Place tab selected, click on Basic and then drag the object called Cylinder into the 3D Viewport. This will create a new cylinder actor and place it in our level. You should see the actor in the 3D Viewport as well as in the Scene Outliner panel, where it will be named Cylinder by default. Right-click on this object in the Scene Outliner panel, go to Edit, and then select Rename. Rename the Cylinder object to CylinderTarget, as shown here:

Adding objects to our level

Exploring materials

Earlier, we set for ourselves the goal of changing the color of the cylinder when it is hit by a projectile. To do so, we will need to change the actor's material. A material is an asset that can be added to an actor's mesh (which defines the physical shape of the actor) to create its look. You can think of a material as paint applied on top of an actor's mesh or shape. Since an actor's material determines its color, one method of changing the color of an actor is to replace its material with a material of a different color. To do this, we will first be creating a material of our own. It will make an actor appear red.

Creating materials

We can start by creating a new folder inside the FirstPersonBP directory and calling it Materials. Navigate to the newly created folder and right-click inside empty space in the content browser, which will generate a new asset creation popup. From here, select Material to create a new material asset. You will be prompted to give the new material a name, which I have chosen to call TargetRed.

Material properties and Blueprint nodes

Double-click on TargetRed to open a new editor tab for editing the material, like this:

Material properties and Blueprint nodes

You are now looking at Material Editor, which shares many features and conventions with Blueprints. The center of this screen is called the grid, and this is where we will place all the objects that will define the logic of our Blueprints. The initial object you see in the center of the grid screen, labeled with the name of the material, is called a node. This node, as seen in the previous screenshot, has a series of input pins that other material nodes can attach to in order to define its properties.

To give the material a color, we will need to create a node that will give information about the color to the input labeled Base Color on this node. To do so, right-click on empty space near the node. A popup will appear, with a search box and a long list of expandable options. This shows all the available Blueprint node options that we can add to this Material Blueprint. The search box is context sensitive, so if you start typing the first few letters of a valid node name, you will see the list below shrink to include only those nodes that include those letters in the name. The node we are looking for is called VectorParameter, so we start typing this name in the search box and click on the VectorParameter result to add that node to our grid:

Material properties and Blueprint nodes

A vector parameter in the Material Editor allows us to define a color, which we can then attach to the Base Color input on the tall material definition node. We first need to give the node a color selection. Double-click on the black square in the middle of the node to open Color Picker. We want to give our target a bright red color when it is hit, so either drag the center point in the color wheel to the red section of the wheel, or fill in the RGB or Hex values manually. When you have selected the shade of red you want to use, click on OK. You will notice that the black box in your vector parameter node has now turned red.

Tip

Downloading the example code

You can download the example code files from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

To help ourselves remember what parameter or property of the material our vector parameter will be defining, we should name it color. You can do this by ensuring that you have the vector parameter node selected (indicated by a thin yellow highlight around the node), and then navigating to the Details panel in the editor. Enter a value for Parameter Name, and the node label will change automatically:

Material properties and Blueprint nodes

The final step is to link our color vector parameter node to the base material node. With Blueprints, you can connect two nodes by clicking and dragging one output pin to another node's input pin. Input pins are located on the left-hand side of a node, while output pins are always located to the right. The thin line that connects two nodes that have been connected in this way is called a wire. For our material, we need to click and drag a wire from the top output pin of the color node to the Base Color input pin of the material node, as shown in the following screenshot:

Material properties and Blueprint nodes

Adding substance to our material

We can optionally add some polish to our material by taking advantage of some of the other input pins on the material definition node. 3D objects look unrealistic with flat, single color materials applied, but we can add additional reflectiveness and depth by setting a value for the materials Metallic and Roughness inputs. To do so, right click in empty grid space and type scalar into the search box. The node we are looking for is called ScalarParameter.

Adding substance to our material

Once you have a scalar parameter node, select it, and go to the Details panel. A scalar parameter takes a single float value (a number with decimal values). Set Default Value to 0.1, as we want any additive effects to our material to be subtle. We should also change Parameter Name to Metallic. Finally, we click and drag the output pin from our Metallic node to the Metallic input pin of the material definition node.

We want to make an additional connection to the Roughness parameter, so right-click on the Metallic node we just created and select Duplicate. This will generate a copy of that node, without the wire connection. Select this duplicate Metallic node and then change the Parameter Name field in the Details panel to Roughness. We will keep the same default value of 0.1 for this node. Now click and drag the output pin from the Roughness node to the Roughness input pin of the Material definition node.

The final result of our Material Blueprint should look like what is shown in the following screenshot:

Adding substance to our material

We have now made a shiny red material. It will ensure that our targets will stand out when they are hit. Click on the Save button in the top-left corner of the editor to save the asset, and click again on the tab labeled FirstPersonExampleMap to return to your level.

Creating our first Blueprint

We now have a cylinder in the world, and the material we would like to apply to the cylinder when shot. The final piece of the interaction will be the game logic that evaluates that the cylinder has been hit, and then changes the material on the cylinder to our new red material. In order to create this behavior and add it to our cylinder, we will have to create a Blueprint. There are multiple ways of creating a Blueprint, but to save a couple of steps, we can create the Blueprint and directly attach it to the cylinder we created in a single click. To do so, make sure you have the CylinderTarget object selected in the Scene Outliner panel, and click on the blue Blueprint/Add Script button at the top of the Details panel. You will then see a path select window.

For this project, we will be storing all our Blueprints in the Blueprints folder, inside the FirstPersonBP folder. Since this is the Blueprint for our CylinderTarget actor, leaving the name of the Blueprint as the default, CylinderTarget_Blueprint, is appropriate.

Creating our first Blueprint

CylinderTarget_Blueprint should now appear in your content browser, inside the Blueprints folder. Double-click on this Blueprint to open a new editor tab for the Blueprint. We will now be looking at the Viewport view of our cylinder. From here, we can manipulate some of the default properties of our actor, or add more components, each of which can contain their own logic to make the actor more complex. We will explore components more in the next chapter; for now, we want to create a simple Blueprint attached to the actor directly. To do so, click on the tab labeled Event Graph above the Viewport window.

Exploring the Event Graph panel

The Event Graph panel should look very familiar, as it shares most of the same visual and functional elements as the Material Editor we used earlier. By default, the event graph opens with three unlinked event nodes that are currently unused. An event refers to some action in the game that acts as a trigger for a Blueprint to do something. Most of the Blueprints you will create follow this structure: Event (when) | Conditionals (if) | Actions (do). This can be worded as follows: when something happens, check whether X, Y, and Z are true, and if so, do this sequence of actions. A real-world example of this might be a Blueprint that determines whether or not I have fired a gun. The flow is like this: WHEN the trigger is pulled, IF there is ammo left in the gun, DO fire the gun.

The three event nodes that are present in our graph by default are three of the most commonly used event triggers. Event Begin Play triggers actions when the player first begins playing the game. Event Actor Begin Overlap triggers actions when another actor begins touching or overlapping the space containing the existing actor controlled by the Blueprint. Event Tick triggers attached actions every time a new frame of visual content is displayed on the screen during gameplay. The number of frames that are shown on the screen within a second will vary depending on the power of the computer running the game, and this will in turn affect how often Event Tick triggers the actions.

Exploring the Event Graph panel

We want to trigger a "change material" action on our target every time a projectile hits it. While we could do this by utilizing the Event Actor Begin Overlap node to detect when a projectile object was overlapping with the cylinder mesh of our target, we will simplify things by detecting only when another actor has hit our target actor. Let's start with a clean slate, by clicking and dragging a selection box over all the default events and hitting the Delete key on the keyboard to delete them.

Detecting a hit

To create our hit detection event, right-click on empty graph space and type hit in the search box. The Event Hit node is what we are looking for, so select it when it appears in the search results. Event Hit triggers actions every time another actor hits the actor controlled by this Blueprint.

Detecting a hit

Once you have the Event Hit node on the graph, you will notice that Event Hit has a number of multicolored output pins originating from it. The first thing to notice is the white triangle pin that is in the top-right corner of the node. This is the execution pin, which determines the next action to be taken in a sequence. Linking the execution pins of different nodes together enables the basic functionality of all Blueprints. Now that we have the trigger, we need to find an action that will enable us to change the material of an actor. Click and drag a wire from the execution pin to empty space to the right of the node.

Dropping a wire into empty space like this will generate a search window, allowing you to create a node and attach it to the pin you are dragging from in a single operation. In the search window that appears, make sure that the Context Sensitive box is checked. This will limit the results in the search window to only those nodes that can actually be attached to the pin you dragged to generate the search window. With Context Sensitive checked, type set material in the search box. The node we want to select is called Set Material (StaticMeshComponent).

Tip

If you cannot find the node you are searching for in the context-sensitive search, try unchecking Context Sensitive to find it from the complete list of node options. Even if the node is not found in the context-sensitive search, there is still a possibility that the node can be used in conjunction with the node you are attempting to attach it to.

The actions in the Event Hit node can be set like this:

Detecting a hit

Swapping a material

Once you have placed the Set Material node, you will notice that it is already connected via its input execution pin to the Event Hit node's output execution pin. This Blueprint will now fire the Set Material action whenever the Blueprint's actor hits another actor. However, we haven't yet set up the material that will be called when the Set Material action is called. Without setting the material, the action will fire but not produce any observable effect on the cylinder target.

To set the material that will be called, click on the drop-down field labeled Select Asset underneath Material inside the Set Material node. In the asset finder window that appears, type red in the search box to find the TargetRed material we created earlier. Clicking on this asset will attach it to the Material field inside the Set Material node.

Swapping a material

We have now done everything we need with this Blueprint to turn the target cylinder red, but before the Blueprint can be saved, it must be compiled. Compiling is the process used to convert the developer-friendly Blueprint language into machine instructions that tell the computer what operations to perform. This is a hands-off process, so we don't need to concern ourselves with it, except to ensure that we always compile our Blueprint scripts after we assemble them. To do so, hit the Compile button in the top-left corner of the editor toolbar, and then click on Save.

Now that we have set up a basic gameplay interaction, it is wise to test the game to ensure that everything is happening the way we expect. Click on the Play button, and a game window will appear directly above the Blueprint Editor. Try both shooting and running into the CylinderTarget actor you created.

Swapping a material

Improving the Blueprint

When we run the game, we see that the cylinder target does change colors upon being hit by a projectile fired from the player's gun. This is the beginning of a framework of gameplay that can be used to get enemies to respond to the player's actions. However, you also might have noticed that the target cylinder changes color even when the player runs into it directly. Remember that we wanted the cylinder target to become red only when hit by a player projectile, and not because of any other object colliding with it. Unforeseen results like this are common whenever scripting is involved, and the best way to avoid them is to check your work by playing the game as you construct it as often as possible.

To fix our Blueprint so that the cylinder target changes color only in response to a player projectile, return to the CylinderTarget_Blueprint tab and look at the Event Hit node again.

The remaining output pins on the Event Hit node are variables that store data about the event that can be passed to other nodes. The color of the pins represents the kind of data variable it passes. Blue pins pass objects, such as actors, whereas red pins contain a Boolean (true or false) variable.

You will learn more about these pin types as we get into more complicated Blueprints; for now, we only need to concern ourselves with the blue output pin labeled Other, which contains the data about which other actor performed the hitting to fire this event. This will be useful in order for us to ensure that the cylinder target changes color only when hit by a projectile fired from the player, rather than changing color because of any other actors that might bump into it.

To ensure that we are only triggering in response to a player projectile hit, click and drag a wire from the Other output pin to empty space. In this search window, type projectile. You should see some results that look similar to the following screenshot. The node we are looking for is called Cast To FirstPersonProjectile:

Improving the Blueprint

FirstPersonProjectile is a Blueprint included in Unreal Engine 4's First Person template that controls the behavior of the projectiles that are fired from your gun. This node uses casting to ensure that the action attached to the execution pin of this node occurs only if the actor hitting the cylinder target matches the object referenced by the casting node.

When the node appears, you should already see a blue wire between the Other output pin of the Event Hit node and the Object pin of the casting node. If not, you can generate it manually by clicking and dragging from one pin to the other. You should also remove the connections between the Event Hit and Set Material node execution pins so that the casting node can be linked between them. Removing a wire between two pins can be done by holding down the Alt key and clicking on a pin.

Once you have linked the three nodes, the event graph should look like what is shown in the following screenshot:

Improving the Blueprint

Now compile, save, and click on the play button again to test. This time, you should notice that the cylinder target retains its default color when you walk up and touch it, but does turn red when fired upon by your gun.

Adding movement

Now that we have a target that responds to the player shooting, we can add some sort of challenge to start making our project feel like a game. A simple way to do this is to add some movement to our target. To accomplish this, we will first have to declare that our target actor is an object that is intended to move, and then we need to set up logic within the Blueprint that will manage how it moves. Our goal will be to make the target cylinder move back and forth across our level.

Changing actor mobility and collision

To allow our target to move, we first have to change the actor's Mobility setting to Moveable. This allows an object to be manipulated while playing the game. From the main editor view, select CylinderTarget_Blueprint, and look at the Details panel. Underneath the Transform values, you can see a toggle for Mobility. Change this from Static to Moveable, as shown in the following screenshot:

Changing actor mobility and collision

Note

By default, basic actors that are placed in the world are set to static. "Static" means that the object cannot move or be manipulated during gameplay. Static objects are significantly less resource intensive to render, and this should be our default choice for non-interactive objects so that we can maximize frame rates.

It is important to note that the version of the target cylinder that we changed in the level is just one instance of the Blueprint template for the target cylinders that we have created. An instance refers to an actual object that has been created, whereas our Blueprints are descriptions of the kind of features that those instances will have once they are created.

Any changes we make to a target cylinder already inside the level will be made for that particular target cylinder only. To make changes to all future targets, we need to modify the Blueprint directly. To do so, open CylinderTarget_Blueprint again, either by navigating to the open tab in the editor, or by double-clicking on the CylinderTarget_Blueprint file in your Blueprints folder.

With the Blueprint open, we want to navigate to the Viewport tab located underneath the menu toolbar. Along the left side, you will see the Components panel, which lists all the components that make up this Blueprint. Since we want to edit a property of the physical object, or mesh, we click on component StaticMeshComponent. You will see a familiar-looking details panel. It includes the same properties and categories that we saw when we edited the target cylinder in the level editing interface. Here, we have to switch the same Mobility toggle, located beneath the Transform properties, from Static to Movable. This will ensure that all future targets created from this Blueprint will already be set to be moveable.

Because we want to target this object with our gun, we also need to ensure that the target is capable of being collided with so that our bullets don't pass through it. Still in the details panel, find the category called Collision and look for Collision Presets in the drop-down menu. There are many other options in this dropdown, and by choosing the Custom option, you can even set the object's collision interaction with different object types individually. For our purpose, we just need to ensure that this drop-down menu is set to BlockAllDynamic, which ensures that the mesh will register collisions with any other object that also has a collider.

Changing actor mobility and collision

Breaking down our goal

Now that we have made our target moveable, we are ready to set up Blueprints that tell the cylinder how to move. In order to move an object, we will need three pieces of data:

  • Where the cylinder currently is
  • What direction it is supposed to move in
  • How fast it is supposed to move in that direction

To understand where the object currently is, we need to get some information about the world itself. Specifically, what are the coordinates of the cylinder in the world? The speed and direction are the values we are going to provide to the Blueprint, though some calculations will be necessary to turn those values into information that is useful for the Blueprint to move the object.

Storing data with variables

The first step is to create the two variables we need: direction and speed. Find the panel labeled My Blueprint. You should see an empty category marker called Variables, with a + sign to the right. Click on that + sign to create your first variable.

In the Details panel, you will see a series of fields for editing your new variable. The four fields that we have to edit are the Variable Name, Variable Type, Editable, and Default Value. We want our first variable to contain information about the speed of movement, so name the variable Speed. For Variable Type, we want a variable that can hold a number that will represent our desired speed, so select Float from the drop-down menu.

Check the box next to Editable to enable the variable to be changed outside of this Blueprint. This will be useful for quickly adjusting the value to our liking once we start testing the moving target in the game. The Default Value category will likely not have a field, but will feature a message asking you to compile the Blueprint first. Do that, and a field for entering an initial value will appear. Change the default value to 200.0.

Using the same process, create a second variable called Direction. Choose Vector for Variable Type. A vector contains information about the X, Y, and Z coordinates, and in this case, we need to indicate the direction of change we want for the object movement. Make the direction variable editable and set Default Value to -10.0 for the Y axis.

Storing data with variables

Readying direction for calculations

We will now explore the steps necessary to get the information we need to provide a movement instruction. It might look intimidating at first, but we will break down each section and see how each node fits into the larger goal.

The first calculation we need to perform is to take our vector value for direction and normalize it. Normalizing is a common procedure in vector math that ensures that the vector is converted to a length of one unit, which will make it compatible with the rest of our calculations. Fortunately, there is a Blueprint node that takes care of this for us.

Click on the Direction variable we created in the My Blueprint panel, and drag it into empty space in the event graph. A small popup will appear, prompting you to select Get or Set. We want to retrieve the value we set for the direction, so choose Get to create a node containing the direction variable's value. Click on the output pin of the Direction node, and drop it into empty graph space. Type normalize in the search field and select the Normalize node underneath the category labeled Vector. This will connect your Direction variable to a node that will automatically do the normalizing calculation for us.

Readying direction for calculations

Note

It is good practice to leave comments on the sets of Blueprints as you create them. Comments can help describe what a particular set of Blueprints is intended to accomplish, which can be helpful if you are returning to a Blueprint after some time and need to make sense of your prior work. To leave a comment on a Blueprint, click and drag a selection box around the nodes you want to create a comment around to select them. Then, right-click on one of the selected nodes and select the bottom option, Create Comment from Selection.

Getting relative speed using delta time

To make our speed value relate to direction, we first need to multiply it by delta time. Delta time is based on the fact that the time taken between the frames of the gameplay can differ. By multiplying our speed value to delta seconds, we can ensure that the speed at which our object moves is the same, regardless of the game's frame rate.

To do this, drag the Speed variable onto the event graph and choose Get to create the speed node. Now, right-click on empty graph space and search for delta. Select the Get World Delta Seconds option to place the corresponding node. Finally, drag the output pin from either the delta seconds node or the speed node, and drop it into empty space. Type an asterisk in the search field (Shift + 8 on most computers) and select the Float * Float node. Finally, drag the other output pin onto the remaining input pin of the new multiplication node to multiply these two values, like this:

Getting relative speed using delta time

Translating the existing location

Now that we have a normalized vector direction and a speed value relative to time, we need to multiply these two values and then add them to the current location. First, find the StaticMeshComponent component from the Components panel and drag it onto the event graph. This will create a node from which we can extract any data contained within the mesh component of the object.

Next, we want to get the mesh's location. One of several ways to handle this is to look at the transform properties of an object and extract the location from there. Click and drag the blue output pin into empty space, and then type Get World. Select the Get World Transform option to create the node. A transform contains information about the rotation and scale of an object, in addition to its location. This will be useful because we want to ensure that we preserve the rotation and scale of our target even as it is moving, and we will need that data to create a transform value from our new movement information.

Now we want to break down the transform into its component parts so that we can use just the location in our calculations, while preserving the rotation and scale. Drag the output pin from the world transform node, and search for the Break Transform node to add to our graph.

Now we need to add the necessary nodes to add speed and direction to the location information we just extracted. Right-click on empty grid space and search and select the Make Transform node. This will mark the end of your calculations, so make sure that it is positioned to the right of all of your other nodes. The Make Transform node has three inputs, Location, Rotation, and Scale. The Rotation and Scale inputs should be connected to the rotation and scale output pins on the Break Transform node we created earlier.

Next, we need to multiply the Direction vector and the Speed float we calculated. Drag the output node of the Normalize node into empty space, and search using an asterisk. Select Vector * Float and connect the green input pin to the output of the float multiplication node that we used with speed.

Our final calculation step is to add Speed and Direction to the current location we calculated. Click on the yellow vector output pin of the new multiplication node, and drag it onto empty space. Search using + and select the Vector + Vector node. Ensure that one input pin of this addition node is connected to the previously mentioned vector multiplication node, and then connect the other input pin is connected to the Location output pin of the Break Transform node. Finally, drag the output pin of our addition node onto the Location input pin of the Make Transform node. When you are finished, the result should look like what is shown in the following screenshot:

Translating the existing location

Updating location

Now that we have the transform calculated, we can adjust the location of our target actor by this value. We used delta time to make our speed and direction changes consistent across frames, and as a consequence, we can simply use the Event Tick node to fire our move action every frame. Right-click on empty grid space, search for Event Tick, and place the node somewhere to the right of your Make Transform node.

To move the actor, we will be using the Set Actor Transform node. Drag a wire from the execution pin of Event Tick to empty grid space, and search for Set Actor Transform. Place the node, and then connect the Return Value output pin on your Make Transform node to the New Transform input pin on the Set Actor Transform node, as shown here:

Updating location

Changing direction

If you were to compile the Blueprint, save, and play the game now, what would you expect to see? The target cylinder would move according to our speed and direction as soon as the game began. However, since we don't have any instructions that cause the target to stop moving, it would proceed in the same direction for as long as the game runs, even moving through objects and out of the level we created! To address this, we need logic that will change the target's direction periodically. This will result in a target that moves back and forth between two points regularly, much like a shooting gallery target.

To do this, we have to set up two nodes that will set the direction variable we created to two different values. Drag the direction variable into empty grid space and choose the Set option. This will result in a node with X, Y, and Z axis fields. We can use them to change the value of the direction variable to be different from the initial default value that we gave it. We want two of these nodes, so drag the direction variable again into empty space, and then change the Y axis values of the two nodes to 10.0 and -10.0 respectively.

Now we need a way to switch between these two nodes so that the direction repeatedly shifts. The FlipFlop node was created for scenarios where we know we want to alternate between two sets of actions that execute exactly once before switching each time. This fits our use case here, so right-click on empty grid space and search for FlipFlop. Select and place the node. Then connect the A execution pin to one of the direction set node input pins, and the B execution pin to the other.

Finally, we need to ensure that there is some kind of delay between executing the direction shifts. Otherwise, the direction will change for every frame and the object will go nowhere. To do so, drag the input execution pin of the FlipFlop node into empty space and search for the Delay node. This node allows us to set a delay duration, in seconds, that will postpone the following execution commands by that length of time. Place this node before the FlipFlop node and give it a duration of 6 seconds. Placing this Delay node between our Set Actor Transform node and our FlipFlop node will ensure that the direction switch enabled by FlipFlop will occur only every 6 seconds. The final product should look like what is shown in the following screenshot. Once you are done, remember to compile and save the Blueprint.

Changing direction

Testing moving targets

Now that we have our Blueprint updated, we can test to ensure that the CylinderTarget object moves as expected. First, we will have to place the CylinderTarget object in a position that will allow it to move along the Y axis without bumping into other objects. The coordinates I used were 410 on the X axis, 680 on the Y axis, and 180 on the Z axis.

Note that these values will only work relative to the default layout of the First Person template map. If you have made adjustments to your own level, then you can adjust either the speed or the placement of the target in your level, and test until you find a good patrol spot. Click on Play. If the Blueprint is functioning correctly, you will see the cylinder move back and forth between two points at a steady rate.

One of the advantages of using Blueprints is that they create a template of functionality that can be used across multiple objects in a scene. Find CylinderTarget_Blueprint in the Blueprints folder and drag it directly onto 3D Viewport. You will see another cylinder created, which inherits all of the functionality of our original cylinder target. In this way, we can rapidly set up multiple moving targets using the single set of Blueprint logic we created.

Summary

You have built your first prototype using Unreal 4 Blueprints. Congratulations! The amount of progress you have already made is commendable.

In this chapter, you created a project and an initial level using a first-person shooter template. You then set up a target object that reacts to the player's gunfire by changing appearance. Finally, you set up a Blueprint that will allow you to rapidly create moving targets. The skills you have learned here will serve as a strong foundation for building more complex interactive behavior in later chapters, or even entire games of your own making.

You may wish to spend some additional time modifying your prototype to include a more appealing layout, or feature faster moving targets. As we continue building our game experience, remember that you always have the opportunity to linger on a section and experiment with your own functionality or customizations. One of the greatest benefits of Blueprint's visual scripting is the speed at which you can test new ideas, and each additional skill that you learn will unlock exponentially more possibilities for game experiences that you can explore and prototype.

In the next chapter, we will be looking more closely at the player controller that came with the First Person template. We will extend the existing Blueprint that governs player movement and shooting with a gun that is tweaked to our liking, and produces a more interesting visual impact and sound effects.

Left arrow icon Right arrow icon

Key benefits

  • Take your game designs from inspiration to a fully playable game that you can share with the world, without writing a single line of code.
  • Learn to use visual scripting to develop gameplay mechanics, UI, visual effects, artificial intelligence, and more.
  • Build a first person shooter from scratch with step-by-step tutorials.

Description

Blueprints Visual Scripting for Unreal Engine is a step-by-step approach to building a fully functional game, one system at a time. Starting with a basic First Person Shooter template, each chapter will extend the prototype to create an increasingly complex and robust game experience. You will progress from creating basic shooting mechanics to gradually more complex systems that will generate user interface elements and intelligent enemy behavior. Focusing on universally applicable skills, the expertise you will develop in utilizing Blueprints can translate to other types of genres. By the time you finish the book, you will have a fully functional First Person Shooter game and the skills necessary to expand on the game to develop an entertaining, memorable experience for your players. From making customizations to player movement to creating new AI and game mechanics from scratch, you will discover everything you need to know to get started with game development using Blueprints and Unreal Engine 4.

Who is this book for?

Whether you are an experienced game designer or artist looking to test your latest idea, or a complete novice looking to build their first video game, this is a great place to start learning how to build complex game mechanics quickly and easily without writing any text code. No programming experience required!

What you will learn

  • Prototype and iterate new game mechanics rapidly
  • Customize the player s abilities and controls
  • Build user interface elements, including health bars and objective counters
  • Set up interactions between player actions and game objects in the world
  • Create complex enemy AI that can sense the world around it and attack the player
  • Design menus that will allow your players to load, pause, and quit the game
  • Deploy your game to multiple platforms and share it with the world

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Jul 28, 2015
Length: 188 pages
Edition : 1st
Language : English
ISBN-13 : 9781785286018
Vendor :
Epic Games
Languages :
Concepts :
Tools :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

Publication date : Jul 28, 2015
Length: 188 pages
Edition : 1st
Language : English
ISBN-13 : 9781785286018
Vendor :
Epic Games
Languages :
Concepts :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just S$6 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just S$6 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total S$ 172.97
Unreal Engine Game Development Blueprints
S$74.99
Blueprints Visual Scripting for Unreal engine
S$44.99
Unreal Engine 4 AI Programming Essentials
S$52.99
Total S$ 172.97 Stars icon

Table of Contents

9 Chapters
1. Object Interaction with Blueprints Chevron down icon Chevron up icon
2. Enhancing Player Abilities Chevron down icon Chevron up icon
3. Creating Screen UI Elements Chevron down icon Chevron up icon
4. Creating Constraints and Gameplay Objectives Chevron down icon Chevron up icon
5. Making Moving Enemies with AI Chevron down icon Chevron up icon
6. Upgrading the AI Enemies Chevron down icon Chevron up icon
7. Tracking Game States and Applying Finishing Touches Chevron down icon Chevron up icon
8. Building and Publishing Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.1
(28 Ratings)
5 star 53.6%
4 star 21.4%
3 star 10.7%
2 star 7.1%
1 star 7.1%
Filter icon Filter
Top Reviews

Filter reviews by




Bernhard Apr 10, 2016
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Super Einführung in die Programmierung mit Unreal Blueprints. Wesentlich besser als z.B. "Master the Art of Unreal Engine 4 - Blueprints"
Amazon Verified review Amazon
Harrisoliver May 25, 2019
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I was a bit worried it might be out of date, as I'm using it with engine version 4.22.2 and it was written with 4.7, but this has only been an issue on a couple of superficial things so far. Example in chapter 1 when creating a material the book fails to state that you also need to select "used with static lighting" under material details.There's nothing that can't be sorted with a bit of googling and trial and error, and I actually am inclined to recommend the book even more as a result of this as it engages me mentally a bit more and makes for a more rewarding learning experience than simply following the steps listed.I'm very grateful for this book as after nine years out of the loop on Unreal it has been a great resource to get me back into the swing of things. Many thanks.
Amazon Verified review Amazon
TB Jul 31, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Ich habe mir dieses Buch als Einstieg ins Visual Scripting für Ego-Shooter zugelegt. Diesen Zweck hat es einwandfrei erfüllt, denn es deckt erfreulicherweise viele Bereiche dafür ab. Natürlich werden da keine hochkomplizierten Mechaniken behandelt, wie man sie aus einem äußerst bekannten Ego-Shooter kennt.Das Buch deckt aber alles ab, um einen lauffähigen kleinen Shooter selbst zusammenzubasteln und überhaupt einen Einstiegspunkt in die Engine zu finden. Die engine-eigene Doku ist für Anfänger beinahe unbrauchbar.
Amazon Verified review Amazon
Rob Thompson Aug 26, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This a great book. Unreal Blueprints is quite a topic and getting it into a book with clear examples is exactly what was needed for the Unreal Engine. There are not many books published on Unreal Engine 4 and hopefully this will be the start of many good quality books. The book covers the essentials of Blueprints and makes for an easy read. Follow all the topics and build the content as per the book and you will learn a lot.
Amazon Verified review Amazon
cybereality Sep 19, 2019
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Blueprints Visual Scripting for Unreal Engine is a great little book. Clocking in at just 190 pages, it is a quick read but packed with practical information. Brenden Sewell does a good job of introducing game development concepts in a series of chapters which build upon the same project, culminating in a nice (if somewhat simple) demo at the end.Inside this book, the author discusses the basics of using Blueprints, customizing the character controller, creating UI elements, working with branching and conditional statements, simple enemy AI, implementing game states, as well as building and publishing your game. Certainly not an exhaustive list, but a good range of popular topics you will need to make a game with Unreal Engine.I found the chapters on AI to be especially compelling. They were clearly explained and very functional. The way the chapters all build upon one another was also a plus, and made the learning practical.Overall an enjoyable book and a good introduction to using Blueprints visual scripting in UE4. The text uses the Unreal default art assets, so the demo you create is not particularly fresh in terms of the design, but if you want to learn visual coding, this is a great place to start.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.