56,39 €
Unreal Engine's Blueprint visual scripting system enables designers to script their games and programmers to create base elements that can be extended by designers. With this book, you'll explore all the features of the Blueprint Editor, along with expert tips, shortcuts, and best practices.
The book guides you through using variables, macros, and functions, and helps you learn about object-oriented programming (OOP). You'll discover the Gameplay Framework and advance to learning how Blueprint Communication allows one Blueprint to access information from another Blueprint. Later chapters focus on building a fully functional game step by step. You'll start with a basic first-person shooter (FPS) template, and each chapter will build on the prototype to create an increasingly complex and robust game experience. You'll then progress from creating basic shooting mechanics to more complex systems such as user interface elements and intelligent enemy behavior. The book demonstrates how to use arrays, maps, enums, and vector operations and introduces the elements needed for VR game development. In the final chapters, you’ll learn how to implement procedural generation and create a product configurator.
By the end of this book, you'll have learned how to build a fully functional game and have the skills required to develop an entertaining experience for your audience.
Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:
Seitenzahl: 485
Veröffentlichungsjahr: 2022
Unleash the true power of Blueprints to create impressive games and applications in UE5
Marcos Romero
Brenden Sewell
BIRMINGHAM—MUMBAI
Copyright © 2022 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the authors, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
Publishing Product Manager: Rohit Rajkumar
Senior Editor: Aamir Ahmed
Content Development Editor: Feza Shaikh
Technical Editor: Simran Udasi
Copy Editor: Safis Editing
Project Coordinator: Rashika Ba
Proofreader: Safis Editing
Indexer: Rekha Nair
Production Designer: Shyam Sundar Korumilli
Marketing Coordinator: Teny Thomas and Elizabeth Varghese
First published: July 2015
Second edition: August 2019
Third edition: April 2022
Production reference: 2170522
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham
B3 2PB, UK.
ISBN 978-1-80181-158-3
www.packt.com
I believe it must have been back in early 2015 that I had the privilege of being one of the very first people to work for Epic Games and Unreal Engine, focused on helping the academic community to understand the value and power of the amazing UE4 for educators, students, and aspiring game developers and (eventually) filmmakers. It was a remarkable time, getting to travel the world and spread the word about Unreal Engine 4.At the time, however, many/most universities were teaching Unity, or other game engines, and only a select few early adopters had embraced the concepts and workflows of designing and prototyping gameplay with Blueprints since Unreal Engine 4 and Blueprints were still in their infancy.
I was very fortunate, however, in the spring of 2015 to come across the work of Marcos Romero and, in particular, his Romero Blueprints Blog. All of a sudden, there was an online resource that helped contextualize a large set of core nodes of Blueprints in a way that developers could not only learn them but possibly even teach them. Although Epic and the internal UE4 teams were building various learning resources for Blueprints, what Marcos had created was beautifully clear and could prove very helpful in training new users. In my opinion, Marcos Romero's Blueprints Blog helped to ground the concepts of Blueprint for UE4 in an accessible and easy-to-grasp way.
Without hesitation, I reached out to Marcos to introduce myself and to encourage him in his efforts. I also sent emails to the Epic leadership promoting his work and encouraged them to issue Marcos Romero with one of the very first Education Dev Grants awarded at the time, which he received in August 2015. In early 2016, still very impressed with what Marcos was creating with his Romero Blueprints, I asked his permission to create a printed version of his Blueprints Compendium to distribute at one of the GDC education summits that I had the honor of hosting. Needless to say, these printed Blueprint Compendiums were extremely popular and in very high demand year after year at many events that Epic and the Unreal Engine Education and Training teams hosted, and are still a sought-after item.
As more universities around the world began to adopt Unreal Engine 4 and started trying to teach game development utilizing Blueprints, I once again turned to Marcos Romero to request a formal Blueprint Instructor Guide in 2018. I asked Marcos whether he would develop a teaching guide that could be used officially in classrooms to instruct the core principles of working with Blueprints, with the help of terminology sheets, exercises, lectures, and the like. Once again, Marcos delivered an amazing resource that is still in use and available to download at unrealengine.com.
I've enjoyed my collaboration with Marcos tremendously over the last 6 or 7 years. I invited Marcos to participate in an Education Livestream that I had been hosting on the Unreal Engine Twitch channel in the summer of 2020. Marcos' knowledge of Unreal and Blueprints, and his willingness to share have always been such a gift! It's been a treat to work with him at every turn.
When Marcos told me that he was writing a new book on Blueprints for Unreal Engine 5, I was thrilled and honored to help out by promoting his efforts without reservation. It has been my pleasure to work with Marcos and am thankful that he is willing to share his knowledge with the Unreal Engine community and with the world. I thoroughly hope everyone enjoys reading this book!!
Luis Cataldi
Lead Evangelist at Quixel/Epic Games
Marcos Romero is the author of the Romero Blueprints blog, which is one of the main references on the internet to learn about Blueprints. Epic Games invited Marcos to the Unreal Engine 4 closed beta program to experiment and collaborate with the evolution of the tools. He was also one of the first recipients of Unreal Dev Grants for Education. Marcos is a well-known figure in the Unreal community and, for Epic Games, he wrote the official Blueprints Compendium and Blueprints Instructors' Guide.
I would like to thank Luis Cataldi and Tom Shannon from Epic Games for sharing and recommending my Blueprint materials to developers around the world.
I'd also like to thank Elinaldo Azevedo, Filipe Mendes, and Ingrid Mendes, for their dedication to Beljogos, which is a local game development group that I founded in the city of Belém, northern Brazil.
Brenden Sewell is a creative director with a decade of experience leading teams in the development of compelling interactive experiences that entertain, teach, and inspire. Prior to joining E-Line, he explored the intersection of educational practice and industry game development, culminating in his work as the principal game designer at the Center for Games and Impact. There, he specialized in the development of immersive games for STEM education and teachers' professional development. Since joining the E-Line team, he has led developments from concept, prototyping, and production, to release on a variety of projects ranging from a brain-training first-person shooter to a construction sandbox exploring the future of digital fabrication.
Agne Skripkaite is an Unreal Engine software engineer. Coming from a strong background in physics (with a Bachelor's of Science in Physics from the University of Edinburgh), Agne likes to focus on the why of things and the overarching structure of code in games. In the past, they have worked on Unreal Engine VR applications – both room-scale and seated games, becoming an experienced user comfort and motion sickness mitigation specialist for these contexts. This is the fifth Packt Publishing book on Unreal Engine that Agne has reviewed as a technical editor.
Unreal Engine's Blueprint visual scripting system enables designers to script their games as well as programmers to create base elements that can be extended by designers. With this book, you'll explore all the features of the Blueprint Editor, along with expert tips, shortcuts, and best practices.
The book guides you through using variables, macros, and functions, and helps you learn about object-oriented programming (OOP). You'll discover the Gameplay Framework and advance to learning how Blueprint Communication allows one Blueprint to access information from another Blueprint. Later chapters will focus on building a fully functional game step by step. You'll start with a basic first-person shooter (FPS) template, and each chapter will build on the prototype to create an increasingly complex and robust game experience. You'll then progress from creating basic shooting mechanics to more complex systems, such as user interface elements and intelligent enemy behavior. The book demonstrates how to use arrays, maps, enums, and vector operations and introduces the elements needed for VR game development. In the final chapters, you'll learn how to implement procedural generation and create a product configurator.
By the end of this book, you'll have learned how to build a fully functional game and have the skills required to develop an entertaining experience for your audience.
This book is for anyone interested in developing games or applications with Unreal Engine 5. Whether you are brand new to game development or have just not had any exposure to Unreal Engine 5's Blueprint Visual Scripting system, this is a great place to start learning about how to build complex game mechanics quickly and easily without writing any text code. No programming experience is required!
Chapter 1, Exploringthe Blueprint Editor, covers the Blueprint Editor and all the panels that are integrated into it. We will explore the Components tab, the My Blueprint tab, the Details tab, and the Viewport and Event Graph tabs. Then, we will go through what components are and how to add them to a Blueprint.
Chapter 2, Programming with Blueprints, explains programming concepts that are used in Blueprints. We will learn about how to use variables, operators, events, actions, macros, and functions.
Chapter 3, Object-Oriented Programming and the Gameplay Framework, teaches OOP concepts and explores the Gameplay Framework.
Chapter 4, Understanding Blueprint Communication, explores different types of Blueprint Communication, which allows one Blueprint to access the information of another Blueprint.
Chapter 5, Object Interaction with Blueprints, covers how to bring new objects to a level to help build the world in which the game will be set. We will move on to manipulating materials on objects, first through the object editor, and then by triggering during runtime via Blueprints.
Chapter 6, Enhancing Player Abilities, teaches you how to use Blueprints to generate new objects during gameplay, and how to link actions in Blueprints to player control inputs. You'll also learn about how to create Blueprints that allow objects to react to collisions with our generated projectiles.
Chapter 7, Creating Screen UI Elements, demonstrates setting up a graphical user interface (GUI) that will track the player's health, stamina, ammo, and current objective. Here, you will learn how to set up a basic user interface using Unreal's GUI Editor and how to use Blueprints to link the interface to the gameplay values.
Chapter 8, Creating Constraints and Gameplay Objectives, covers how to constrain the player's abilities, define the gameplay objectives for a level, and track those objectives. We'll walk through setting up collectible ammo packs that will refill the ammo of the player's gun, as well as utilizing the level Blueprint to define a win condition for our game.
Chapter 9, Building Smart Enemies with Artificial Intelligence, is a crucial chapter that covers how to create an enemy zombie AI that will pursue the player around the level. We'll walk through setting up a navigation mesh on our level and see how to use Blueprints to get enemies to traverse between patrol points.
Chapter 10, Upgrading the AI Enemies, teaches us how to create a compelling experience by modifying the zombie AI to have states in order to give the zombies a little more intelligence. In this chapter, we'll set up the patrol, searching, and attack states for the zombies by using visual and auditory detection. Additionally, we'll explore how to make new enemies appear gradually as the game is playing.
Chapter 11, Game States and Applying the Finishing Touches, adds the finishing touches that are required to make our game a complete experience before we finalize our game for release. In this chapter, we'll create rounds that will make the game increasingly difficult, game saves so that the player can save their progress and return, and player death to make the game's challenge meaningful.
Chapter 12, Building and Publishing, covers how to optimize graphics settings to get our game performing and looking its best, and how to set up project information for distribution. Then, we'll learn about how to create shareable builds of the game for various platforms.
Chapter 13, Data Structures and Flow Control, explains what data structures are and how they can be used to organize data in Blueprints. We'll learn about the concept of containers and how to use arrays, sets, and maps to group multiple elements. This chapter shows other ways to organize data using enumerations, structures, and data tables. In this chapter, we'll also see how to control the flow of execution of a Blueprint by using various types of flow control nodes.
Chapter 14, Math and Trace Nodes, covers some math concepts that are required for 3D games. We will learn the difference between world and local coordinates and how to use them when working with components. This chapter shows us how to use vectors to represent the position, direction, velocity, and distance. The concept of traces is explained and various types of traces are presented. We'll also see how to use traces to test collisions in the game.
Chapter 15, Blueprints Tips, contains several tips to increase the quality of Blueprints. We will learn about how to use various editor shortcuts that speed up our work. This chapter demonstrates some Blueprint best practices that will help you decide where and what types of implementation should be undertaken. Finally, we'll learn about more useful Blueprint miscellaneous nodes.
Chapter 16, Introduction to VR Development, explains some VR concepts and explores the VR template. This chapter explores the functionalities of the VRPawn Blueprint of the VR template and explains how to create objects that can be grabbed by the player using motion controllers. We will learn about the Blueprint functions used to implement teleportation and how to use the interface for Blueprint communication. We will also see how the menu works in the VR template.
Chapter 17, Animation Blueprints, presents the main elements of the Unreal Engine animation system, including Skeleton, Skeletal Mesh, Animation Sequences, and Blend Spaces. It shows how to script an Animation Blueprint using the Event Graph and the Anim Graph. It explains how state machines are used in an animation and how to create new states for an animation.
Chapter 18, Creating Blueprint Libraries and Components, shows how to create Blueprint Macro and Function Libraries with common functionalities that can be used throughout the project. It explains in more detail the concept of components. We will also learn how to create Actor components with encapsulated behavior and Scene components with location-based behavior.
Chapter 19, Procedural Generation, shows several ways to generate level content automatically. You can use the construction script of a Blueprint to script procedural generation and use the Spline tool to define a path that will be used as a reference to position the instances. Also, you can create an Editor Utility Blueprint to manipulate assets and actors in edit mode.
Chapter 20, Creating a Product Configurator Using the Variant Manager, explains how to create a product configurator, which is a type of application used in industry to attract consumers to a specific product. You will learn how to use the Variant Manager panel and variant sets to define a product configurator. The Product Configurator template is an excellent resource for studying various Blueprint concepts in practice. We will analyze the BP_Configurator Blueprint, which dynamically creates the user interface using UMG widget Blueprints with the variant sets.
Appendix, Quiz answers, contains the answers to all the quiz questions, chapter-wise.
Although some basic knowledge of the Windows OS or macOS is required, experience in programming or Unreal Engine 5 is not necessary.
This book is focused on Unreal Engine 5, which means you only need a copy of Unreal Engine to get started. Unreal Engine 5 can be downloaded for free from https://www.unrealengine.com/ and comes with everything you need to follow along with this book.
The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/-Blueprints-Visual-Scripting-for-Unreal-Engine-5. If there's an update to the code, it will be updated on the existing GitHub repository.
We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!
We also provide a PDF file that has color images of the screenshots and diagrams used in this book. You can download it here: https://static.packt-cdn.com/downloads/9781801811583_ColorImages.pdf.
There are a number of text conventions used throughout this book.
Code in text: Indicates code words in the text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: "In the Level Editor, select the instance of BP_EnemyCharacter that we placed on the level."
Bold: Indicates a new term, an important word, or words that you see on screen. For instance, words in menus or dialog boxes appear in bold. Here is an example: "Change Parameter Name to Metallic, and then click and drag the output pin from our Metallic node to the Metallic input pin of the Material definition node."
Tips or Important Notes
Appear like this.
Feedback from our readers is always welcome.
General feedback: If you have questions about any aspect of this book, email us at [email protected] and mention the book title in the subject of your message.
Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit www.packtpub.com/support/errata and fill in the form.
Piracy: If you come across any illegal copies of our works in any form on the internet, we would be grateful if you would provide us with the location address or website name. Please contact us at [email protected] with a link to the material.
If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.
Once you've read Blueprints Visual Scripting for Unreal Engine 5, we'd love to hear your thoughts! Please click here to go straight to the Amazon review page for this book and share your feedback.
Your review is important to us and the tech community and will help us make sure we're delivering excellent quality content.
This part will explore the basic building blocks of Blueprints. You will gain a solid understanding of how Blueprints work and will be able to start creating your own games.
This part comprises the following chapters:
Chapter 1, Exploring the Blueprint EditorChapter 2, Programming with BlueprintsChapter 3, Object-Oriented Programming and the Gameplay FrameworkChapter 4, Understanding Blueprint CommunicationWelcome to the amazing world of game development with Unreal Engine 5. In this book, we will learn how to develop games in Unreal Engine using the Blueprints Visual Scripting language, which was created by Epic Games for Unreal Engine.
The first step that is needed before we can learn about Blueprints is to prepare our development environment. Unreal Engine is free to download. We will learn how to install Unreal Engine 5 and create a new project. After that, we will learn about some of the basic concepts of Blueprints and explore each panel of the Blueprint Editor.
In this chapter, we will cover the following topics:
Installing Unreal Engine Creating new projects and using templatesBlueprints Visual ScriptingThe Blueprint Class Editor interfaceAdding Components to a BlueprintTo use Unreal Engine, you must first install the Epic Games Launcher:
Access the website at https://www.unrealengine.com.Register and download the Epic Games Launcher.Install and start the launcher.Click the Unreal Engine tab on the left-hand side.Click on the Library tab that appears at the top of the screen.Click the + button next to ENGINE VERSIONS to add a version of Unreal Engine to the launcher. You can use the newest version available.Click the Install button. The launcher will start downloading the files needed for installation and may take a long time to complete.Click the Launch button to start an already installed version. It is possible to have multiple versions of Unreal Engine installed on the same machine – you simply set one of them as the current version. The Launch button at the top right of the launcher will start the current version.Figure 1.1 – Launching Unreal Engine
The Blueprint Visual Scripting system is already a well established and stable technology. This book uses version 5.0.0, but the examples created in this book should work without problems in later versions.
After starting up Unreal Engine Editor, the Unreal Project Browser will appear. The Recent Projects box on the top left is used to open existing projects and the other boxes on the left are categories of templates used to create a new project. The following screenshot shows the templates of the Games category.
Figure 1.2 – Templates under the Games category
Templates are basic containers with some key files and a level that provide a basic starting point for different types of projects. They are useful for rapid prototyping or to learn the basic mechanics of a specific type of project. The use of templates is optional. All templates can be simply recreated in the blank template. The following are descriptions of each template in the Games category:
First Person: For games with a first-person perspective. This template features a player character represented by a pair of arms equipped with a gun that fires a simple sphere projectile. The character can be moved around the level using a keyboard, controller, or virtual joystick on a touch device.Handheld AR: For augmented reality applications for Android and iOS devices. This template features runtime logic for toggling AR mode on and off, along with some example code for hit detection and light estimation handling.Third Person: Contains a playable character with a camera that follows it. The camera is positioned behind and slightly above the character. The character has walking, running, and jumping animations and can be moved around the level using a keyboard, controller, or virtual joystick on a touch device.Top Down: Contains a character controlled by a mouse with a camera at a great distance above it. The player's character is controlled using a mouse or touchscreen to click on the required destination and uses the navigation system to avoid obstacles when moving to destinations. This top-down view is often used in action role-playing games.Virtual Reality: Contains the essential features for virtual reality games. This template features teleport locomotion, grabbable objects, interactive objects, and a VR spectator camera. The template has a level where the player can move around and contains objects that can be grabbed and interacted with.Vehicle: Contains a regular vehicle and a complex vehicle with suspension. The level of this template contains a simple track and obstacles.At the bottom right of the Unreal Project Browser, there are the Project Defaults with project configuration options available for the selected template. In the examples of this book, we will use the values selected on the screenshot. These options can be modified later in the project, and they are as follows:
Blueprint/C++: There are templates made with Blueprint or the C++ programming language. In this book, we will only use Blueprint templates. A project in Unreal Engine 5 can be developed using Blueprint, C++, or a combination of both. You can add C++ code to Blueprint projects and Blueprint to C++ projects.Target Platform: Desktop or Mobile. Use Desktop if you are developing your project for use on computers or game consoles. Choose Mobile if your project will be viewed on a mobile device. In this book, we will use the Desktop option.Quality Preset: Scalable or Maximum. These options affect the project's performance. The Scalable option disables some complex features, and the Maximum option enables all the features available in the target platform. In this book, we will use the Scalable option.Starter Content: If this checkbox is marked, the project will include Starter Content. Starter Content is a content pack with simple meshes, materials, and particle effects. The examples in this book assume that Starter Content is being used.Raytracing: If this checkbox is marked, the project will use real-time raytracing, which is a performance-intensive feature. The examples in this book will not use raytracing.Select the Third Person template, choose a location folder, and fill in the Name field for the project. Select the Project Defaults mentioned in the previous list and then click the Create button. After the project loads, the Unreal Engine Level Editor will be displayed, as shown in the following screenshot:
Figure 1.3 – The Unreal Engine Level Editor
These are the key panels of the Level Editor:
Toolbar: Located at the top of the Level Editor. It contains buttons with commonly used operations. The toolbar buttons are separated into four groups. The first group from the left provides quick access to features such as saving your work and adding various objects and code to the project. The second group of buttons are used to change the editing mode of the Level Editor. The third group lets you play the current level and provides various platform-specific options. The final Settings button all the way on the right provides easy access to project settings.Viewport: Located at the center of the Level Editor. It shows the Level that is being created. You can use the Viewport panel to move around the Level and add objects on the Level. When holding down the right mouse button, move the mouse to rotate the camera and use the WASD keys to move around.Content Browser: This can be accessed by clicking on the Content Drawer button located at the bottom-left corner of the Level Editor. It is used to manage the assets of the project. An asset is a piece of content in an Unreal Engine project. For example, Materials, Static Meshes, and Blueprints are all assets. If you drag an asset from the Content Browser and drop it into the Level, the Editor creates a copy of the asset to place in the Level.Outliner: Located to the right of the Level Editor. It lists the objects that are in the Level.Details: Located to the right of the Level Editor, below Outliner. It shows the editable properties of an object that is selected in the Viewport.Now that we have an overview of the Unreal Engine Level Editor, let's focus on the Blueprints Visual Scripting.
The first question you should be asking is: what is a Blueprint?
The word Blueprint has more than one meaning in Unreal Engine. First, it is the name of a visual scripting language created by Epic Games for Unreal Engine. Second, it can refer to a new type of game object created using the Blueprint language.
There are two main types of Blueprints: Level Blueprint and Blueprint Class. Each Level of the game has its own Level Blueprint and it is not possible to create a separate Level Blueprint. On the other hand, Blueprint Class is used to create interactive objects for the game and can be reused in any Level.
To open the Level Blueprint Editor, click on the Blueprints button located in the leftmost group of buttons in the toolbar of the Unreal Editor. Then, select the Open Level Blueprint option from the dropdown, as shown in the following screenshot:
Figure 1.4 – Opening a Level Blueprint
The Editor will open the Level Blueprint of the current Level. The Level Blueprint Editor is simpler than the Blueprint Class Editor because it has only the My Blueprint panel, the Details panel, and the Event Graph Editor. The following screenshot shows the Level Blueprint Editor:
Figure 1.5 – The Level Blueprint Editor
For now, we will not do anything with the Level Blueprint. We opened it to get our first glance at the interface. Close the Level Blueprint Editor to return to the Level Editor window. Now, we will create a Blueprint Class to open the Blueprint Class Editor and see all the panels available.
There are three ways to create a Blueprint Class:
Click the same Blueprints button in the toolbar that we used to open the Level Blueprint. Then, click the New Empty Blueprint Class button in the dropdown.Click the Content Drawer button to open the Content Browser, then click the Add button and select Blueprint Class under the Create Basic Asset category.Right-click anywhere on an empty space in the Content Browser and select Blueprint Class from the menu that appears.Figure 1.6 – Creating a Blueprint Class
On the next window, you must choose the parent class of the new Blueprint. For now, think of the parent class as the Blueprint type. The window shows the most Common classes, but if you need to choose another parent class, then just expand the All Classes option. When you choose the parent class, this window will close, and a new Blueprint asset will appear in the Content Browser to be renamed. You can click the Cancel button because we are just familiarizing ourselves with the process.
Figure 1.7 – Blueprint Parent Class
Now that we've learned how to open the current Level Blueprint and how to create a Blueprint Class, we will explore the panels of the Blueprint Class Editor. You can open the Blueprint Class Editor by right-clicking on a Blueprint asset in the Content Browser and selecting Edit, or by double-clicking on a Blueprint asset.
The Blueprint Class Editor contains several panels. Each panel is used to edit one aspect of a Blueprint. The Blueprint Class Editor is usually simply called the Blueprint Editor. The main panels of the Blueprint Editor are listed as follows:
ToolbarComponentsMy BlueprintDetailsViewportEvent GraphThese panels can be found in the next screenshot. We will use the BP_ThirdPersonCharacter Blueprint of the Third Person template as an example. It is located in the ThirdPerson/Blueprints folder. Double-click the BP_ThirdPersonCharacter Blueprint to open the Blueprint Class Editor.
Figure 1.8 – Blueprint Editor panels
The Toolbar panel is located at the top of the Blueprint Class Editor and contains some essential buttons for editing Blueprints:
Figure 1.9 – Toolbar panel
The buttons are described as follows:
Compile: Converts the Blueprint script into a lower-level format that can be executed. That means a Blueprint must be compiled before running the game or the changes made will not be reflected. Click this button to compile the current Blueprint. A green check icon will appear if there is no error.Save: Saves all changes made to the current Blueprint.Browse: Shows the current Blueprint Class in the Content Browser.Find: Searches within a Blueprint. Hide Unrelated: When active, it hides the nodes unrelated to the selected nodes.Class Settings: Allows editing of the settings for the class in the Details panel. The Class Settings options contain properties such as Description, Category, and Parent Class.Class Defaults: Allows editing of the Class Defaults in the Details panel. Class Defaults are the initial values of the Blueprint variables.Simulation: Allows the execution of the Blueprint inside the Blueprint Editor.Play: Allows you to play the current Level.Debug Object: This dropdown allows the selection of an object to debug. If none is selected, it will debug any object created with the current Blueprint Class.The Components panel shows all the Components that are part of the current Blueprint.
Figure 1.10 – Components panel
Components are ready-to-use objects that can be added to Blueprints. To do this, click on the Add button of the Components panel. A Blueprint can be created with various features just by using Components.
The properties of a selected Component can be edited on the Details panel and the visual representation of some Components can be seen on the Viewport panel.
Static Meshes, lights, sounds, box collisions, particle systems, and cameras are examples of Components found in the Components panel.
My Blueprint is a panel where we can create Variables, Macros, Functions, and Graphs for the Blueprint:
Figure 1.11 – My Blueprint panel
New elements can be added by clicking on the Add button at the top of the panel, or the + button next to each category.
The properties of a selected element can be edited in the Details panel.
The Details panel allows you to edit the properties of a selected element of a Blueprint. The selected element can be a Component, Variable, Macro, or Function element. The properties shown in the Details panel are organized into categories.
The next screenshot shows the properties of a CapsuleComponent. There is a Search box at the top of the panel that can be used to filter the properties.
Figure 1.12 – Details panel
The Viewport panel shows the visual representation of a Blueprint and its Components. The Viewport panel has controls similar to the Level Editor, which you can use to manipulate the location, rotation, and scale of the Components.
The following screenshot shows the Viewport panel. There is a SkeletalMesh Component that represents the player, a Camera Component that defines the view of the player, and a Capsule Component used for collision detection.
Figure 1.13 – Viewport panel
It is in the Event Graph panel that we are going to program the behavior of a Blueprint. The Event Graph contains Events and Actions that are represented by nodes and connected by wires.
An Event is represented by a red node and is triggered by gameplay Events. A Blueprint can have several Actions that will be performed in response to an Event. The next screenshot shows two Events: InputAxis TurnRate and InputAxis LookUpRate:
Figure 1.14 – Event Graph panel
You can move around the Event Graph by right-clicking and dragging it to see the other Events.
The other nodes are Actions representing functions, operators, and variables. We will learn about these elements in Chapter 2,Programming with Blueprints.
After this overview of the Blueprint Editor panels, we are now able to create our first Blueprint. Close the Blueprint Class Editor and navigate back to the Level Editor.
Now, let's create our first Blueprint. It will be a very simple Blueprint that will only contain Components. For now, we will not use Events or Actions:
Click the Content Drawer button to open the Content Browser, then click the Add button and select Blueprint Class.On the next screen, choose Actor as the parent class.Rename the Blueprint we just created to BP_RotatingChair. Blueprints cannot have spaces in their name and there is a convention of starting Blueprint names with BP_.Double-click this Blueprint to open the Blueprint Editor.On the Components panel, click the Add button and select Static Mesh, as shown in the following screenshot. This Static Mesh will visually represent this Blueprint.Figure 1.15 – Adding a Static Mesh Component
On the Details panel, there is a property named Static Mesh, which has a drop-down input. Click on the dropdown and select the Static Mesh property named SM_Chair. This Static Mesh is part of the starter content. The following screenshot shows the selected SM_Chair:Figure 1.16 – Selecting a Static Mesh asset
Let's add another Component. Click the Add button of the Components panel and type rotating movement in the Search box.Click on the Rotating Movement Component to add it. By default, this Component will rotate the Blueprint around the z axis, so we don't need to change its properties.Click the Compile button and save the Blueprint.On the Level Editor, drag the BP_RotatingChair Blueprint from the Content Browser and drop it somewhere in the Level.Press the Play button of the Level Editor to see the rotating chair. You can use the WASD keys to move the character and the mouse to rotate the camera. You can exit the Level being played by pressing the Esc key. The next screenshot shows the example in execution:Figure 1.17 – The rotating chair
In this chapter, we learned how to install Unreal Engine and create new projects using the available templates. We learned that there are two main types of Blueprints: Level Blueprint and Blueprint Class.
Then, we explored the different types of panels that are part of the Blueprint Editor. Our familiarization with these panels will help when developing with Blueprints. Finally, we also created a simple Blueprint using only Components.
In the next chapter, we will learn how to program the behavior of Blueprints using Events and Actions.
a. True
b. False
The Level Blueprint Editor has more panels than the Blueprint Class editor.a. True
b. False
Which type of Blueprint is appropriate for creating objects that can be reused in any Level?a. Level Blueprint
b. Blueprint Class
Which panel in the Blueprint Editor is where Events and Actions can be added?a. Components panel
b. Event Graph panel
c. My Blueprint panel
d. Details panel
Which panel in the Blueprint Editor shows the variables and functions of the current Blueprint?a. Details panel
b. Components panel
c. My Blueprint panel
d. Event Graph panel
This chapter presents the basic programming concepts used in Blueprints. Programming is essentially a way of writing instructions that will be understood and executed by a computer. Most programming languages are text-based, but Blueprint presents a different form of visual programming by using a node-based interface.
Some programming languages are known as scripting languages when they exist in a special environment or when they have a well-defined purpose. For example, Blueprints is the visual scripting language of Unreal Engine.
In this chapter, we will cover the following topics:
Storing values in variablesDefining the behavior of a Blueprint with events and actionsCreating expressions with operatorsOrganizing the script with macros and functionsA variable is a programming concept. It consists of an identifier that points to a memory location where a value can be stored. For example, a character in a game may have variables to store the value of its health, its speed, and the quantity of ammunition.
A Blueprint can have many variables of various types. The variables of a Blueprint are listed on the My Blueprint panel. Clicking the + button in the VARIABLES category creates a variable:
Figure 2.1 – Creating a variable
The type of a variable defines the content that a variable can store. Blueprint is a strongly typed language. This means that you must define the variable type when creating the variable, and this type cannot be modified during program execution.
When you create a variable, its attributes are displayed in the Details panel. The first attribute of a variable is its name, and the second attribute is its type. The various types are as follows:
Figure 2.2 – Variable types
Each type is represented by a color. These are the types of variables:
Boolean: Can only hold values of true or false.Byte: This is an 8-bit number. It can store integer values between 0 and 255.Integer: This is a 32-bit number. It can store integer values between −2,147,483,648 and 2,147,483,647. Integer64: This is a 64-bit number. It can store integer values between −9,223,372,036,854,775,808 and 9,223,372,036,854,775,807.Float: This is a 32-bit floating-point number. It can store number values with fractional parts and has a precision of seven decimal digits.Double: This is a 64-bit floating-point number. It can store number values with fractional parts and has a precision of 16 decimal digits.Name: Piece of text used as an object identifier.String: Can store a group of alphanumeric characters.Text: This type is used for text that will be localized, meaning it allows for easier implementation of translation into different languages.Vector: Contains the X, Y, and Z float values, which represent a 3D vector.Rotator: Contains the X (Roll), Y (Pitch), and Z (Yaw) float values, which represent a rotation in 3D space.Transform: Can store location, rotation, and scale.There are also other types of variables related to Structure, Interface, Object Types, and Enum. We will learn about these types in the upcoming chapters.
The following screenshot shows the Details panel with the attributes that can be modified in VARIABLE:
Figure 2.3 – Attributes of a variable
These attributes can be individually described as follows:
Variable Name: This is the identifier of the variable.Variable Type: This specifies the type of values that can be stored in this variable.Instance Editable: When this box is checked, each copy of this Blueprint placed in the level can store a different value in this variable. Otherwise, the same initial value is shared by all copies, called instances. Blueprint Read Only: If checked, the variable cannot be changed by Blueprint nodes.Tooltip: This contains information shown when the cursor hovers over the variable.Expose on Spawn: If checked, the variable can be set when spawning the Blueprint.Private: If checked, child Blueprints cannot modify it.Expose to Cinematics: If checked, this variable will be exposed to Sequencer.Category: This can be used to organize all variables in the Blueprint.Slider Range: This sets the minimum and maximum values that will be used by a User Interface (UI) slider to modify this variable.Value Range: This sets the minimum and maximum values allowed for this variable.Replication and Replication Condition: They are used in networked games.DEFAULT VALUE: This contains the initial value of the variable. The Blueprint must be compiled before you can set the default value.Variables are used to represent the current state of a Blueprint, but the behavior is defined by events and actions, which will be discussed in the following section.
Most of the time, we will use Blueprints to create new Actors. In Unreal Engine, Actors are game objects that can be added to a level.
Unreal Engine informs the state of a game for an Actor using events. We define how an Actor responds to an event by using actions. Both events and actions are represented by nodes in the Event Graph panel.
To add events to a Blueprint, use the Event Graph panel. Right-click the Event Graph panel to open Context Menu, which has a list of available events and actions. If you need more space in the Event Graph panel, you can right-click and drag to move it to an empty area of Event Graph. Context Menu has a Search bar that can be used to filter the list of nodes. There is also the Context Sensitive checkbox that filters the possible actions based on the node selected. The following screenshot shows Context Menu and some of the events available:
Figure 2.4 – Events in Context Menu
You can add several events in the Event Graph panel, but you can add each event only once. In addition to the events provided by Unreal Engine, you can create your own events by clicking on Add Custom Event…. The next screenshot shows a Custom Event node and its Details panel where you can rename the custom event and add input parameters. We will learn about parameters later in this chapter, in the Creating macros topic:
Figure 2.5 – Creating a custom event
These are some of the events that are available:
Collision Events: These are executed when two Actors collide or overlap.Input events: These are triggered by input devices, such as the keyboard, mouse, touch screen, and gamepads.Event BeginPlay: This is executed either when the game is started for Actors already present on the Level Editor, or immediately after the Actor is spawned if that happens during runtime.Event End Play: This is executed when the Actor is about to be removed during runtime.Event Tick: This is called every frame of the game. For example, if a game runs at 60 frames per second, this event will be called 60 times in a second.We will now learn how to create actions that connect to events.
When an event is triggered, we use actions to define how a Blueprint will react to this event. You can use actions to get or set values in the Blueprint variables or call functions that modify the state of a Blueprint.
The following screenshot shows the Event BeginPlay event of a Blueprint. In this example, the Blueprint has a string variable named Bot Name:
The SET action assigns the Archon value to the Bot Name variable. The next action, Print String, displays the value that is received on the In String pin on the screen. These values that are passed to the functions are known as parameters. The In String pin is connected to a GET node of the Bot Name variable that returns the value of the Bot Name variable and passes it to the Print String function:Figure 2.6 – Event BeginPlay with some actions
To add the GET and SET Actions of a variable to Event Graph, simply drag the variable from the My Blueprint panel and drop it in Event Graph to show the GET and SET options.Other functions such as Print String are added from Context Menu that appears when you right-click on the Event Graph panel. The GET and SET actions can also be searched in Context Menu.
The white lines that connect the actions are also known as the execution path.
The white pins of nodes are called execution pins. The other colored pins are the data pins. The execution of the nodes of a Blueprint starts with a red event node, and then follows the white wire from left to right until it reaches the last node.
There are some nodes that control the flow of execution of the Blueprint. These nodes determine the execution path based on conditions. For example, the Branch node has two output execution pins named True and False. The execution pin that will be triggered depends on the Boolean value of the Condition input parameter. The following screenshot shows an example of the Branch node:
Figure 2.7 – Branch node with two execution paths
In this example, when Event BeginPlay fires, the Branch node evaluates the value of the Has Shield Boolean variable. If the value is True, then the True pin will be executed and will set the value to 100.0 in the Shield Value variable. If it is False, the value 0.0 will be set in the Shield Value variable.
We saw how to modify the value of a variable using an action. The next step is to learn how to create expressions with variables.
Operators are used to create expressions using variables and values. These operators are found in Context Menu within the Utilities | Operators category.
The main types of operators are arithmetic, relational, and logical.
The arithmetic operators (+, -, x, and /) can be used to create mathematical expressions in Blueprints. The following screenshot shows the equivalent nodes in Blueprints. These operators receive two input values on the left and give the operation result on the right. The arithmetic operators can have more than two input parameters; just click on the Add pin button on the node to add another input parameter. The input values can be obtained from a data wire or entered directly in the node:
Figure 2.8 – Arithmetic operation nodes
Note
The * symbol is the multiplication operator in programming languages. Blueprints also recognize * as the multiplication operator but use the letter X as the label of the multiplication node. You need to use the * symbol or write the word multiply when searching for multiplication nodes in the Context Menu.
The following screenshot shows a simple arithmetic expression. The numbers on the screenshot show the order of completion of the nodes. The execution starts with Event BeginPlay. The SET node assigns a new value to the Magic Points variable, but this value must be obtained using the data wire that is connected to the output of a multiplication node, which will need to get the value of the Willpower variable using another data wire to multiply by 20.0:
Figure 2.9 – Multiply operation
Relational operators perform a comparison between two values and return a Boolean value (True or False) as a result of the comparison. The following screenshot shows the relational operators in Blueprints:
Figure 2.10 – Relational operation nodes
The following screenshot shows an example with a relational operator, assuming these actions are performed when a game object receives damage. A Branch node is used to test whether the Health variable value is less than or equal to 0.0. If it returns True, then this game object will be destroyed. If it returns False, nothing will happen since there are no actions connected to the False branch of execution.
Figure 2.11 – Testing a condition with a relational operator
Logical operators perform an operation between Boolean values and return a Boolean value (True or False) as a result of the operation. The following screenshot shows the logical operators in Blueprints:
Figure 2.12 – Logical operation nodes
These are the descriptions of these operators:
OR: Returns a value of True if any of the input values are True.AND: Returns a value of True if and only if all input values are True.NOT: Receives only one input value, and the result will be the opposite value.NOR: This is a combination of NOT and OR operators. It returns a value of True if both inputs are False, otherwise, the return value is False.NAND: This is a combination of NOT and AND operators. It returns a value of False if both inputs are True, otherwise, the return value is True.XOR: This operator is called exclusive OR. It returns a value of True