Chapter 2. Blueprints and Barrels – Your First Game

Welcome to Blueprints and Barrels! During this chapter, you will be introduced to the visual scripting system called Blueprint. This system will be your first entry point toward creating customized functionality and content, using UE4. This chapter will show you the basics of how to create and work with Blueprints to achieve the same level of freedom that any other text based scripting language can provide. You will also expand on the engine navigational skills you learned in the previous chapter as we delve into the more complicated facets of the Editor panel and how you can communicate between the different components of the engine. You will learn all this by creating your very first UE game project, Barrel Hopper.

This chapter will cover the following points:

  • Creating Blueprints
  • Navigating the Blueprint GUI
  • How to find Blueprint functions
  • Basic coding functionality with Blueprint (logical nodes, objects, and events)
  • Game mode Blueprints
  • Using UE4's world outliner
  • Basic level creation and blocking
  • Blueprint collision
  • Adding physics dynamics to objects in a world
  • Creating a Blueprint character
  • Controlling a character through Blueprint
  • Debugging Blueprints

Creating your first Blueprint

Now, it is time to create your first Blueprint. Instead of jumping straight into a new project, I can't think of a better place to create your first Blueprint than our Hello World project. It is time to give our Hello Sphere an upgrade! The first thing we need to do is create a Blueprint from our actor. To do this, we need to select the HelloSphere actor by clicking on the Actor in the viewport or selecting the HelloSphere name in the World Outlier. This will populate our Details Panel with the appropriate options. Just next to the Add Component button, there is a Blueprint/Add Script button, click on this now:

Creating your first Blueprint

You will be prompted to save the Blueprint we are about to create in some folder within our Content Browser. For now, save the blueprint in the Content folder directly. Name this Bluerpint HelloUnrealBP and press the green Create Blueprint button.

The Blueprint window

You will have been presented with an entirely new window, the Blueprint window. This will be your work area whenever you are editing or creating Blueprints. The Blueprint window boasts a new layout of panels and visual sections:

  1. Components: Located in the top left-hand side of the window, this panel functions in exactly the same way as the top of the Details panel in the editor window. You can use this panel to add and remove components.
  2. My Blueprint: Located directly under the Components panel, this panel is responsible for all of the different technical members of the Blueprint. This is where you can find your Event Graphs, Events, Functions, Macros, Variables, and Event Dispatchers. Each of these elements will be described in detail throughout the chapter.
  3. Details: This panel functions exactly the same way as is it did in the editor window. This panel exposes all of the publicly exposed properties of your currently selected component within the Blueprint.
  4. Toolbar: The toolbar is located in center of the screen at the top and features a set of large clickable buttons. These buttons will be explained in the next paragraph.
  5. Viewport: This viewport section is responsible for showing the current physical arrangement of the blueprint in 3D space. This section will also be used to navigate the graphs or functions that are created with the Blueprint system. These other panels can be seen as tabs along the top of the viewport window. By default, Viewport, Construction Script, and Event Graph are shown.

Working with Blueprints

When creating Blueprints, you are frequently going to want to test your recent changes and additional functions as intended. You will also want to make sure that you have minimal errors, warnings, or bugs. The way you will do this is by interfacing with the previously mentioned Toolbar. The buttons featured on the Toolbar allow you to perform varying actions that assist with having your Blueprint execute in a test environment. Each button performs the follows:

  1. Compile: This compiles the current Blueprint and will output any errors or warnings. You can specify various parameters for Blueprint compilation that will adjust if the file is saved and how Blueprint compile errors are handled. These parameters can be found by navigating to Editor Preferences | Content Editors | Blueprint.
  2. Save: This saves the Blueprint.
  3. Find in CB: This opens the content browser and navigate to a selected asset. This lets you locate any assets included in your Blueprint within your content browser. This can be useful if you wish to edit these assets midway through working with a Blueprint.
  4. Class Settings: This opens a Details panel that is responsible for all of the Blueprint Properties such as the Blueprints Parent class, thumbnail appearance, and any interfaces the Blueprint is concerned with. These options will be covered when we look at advanced blueprint functionality.
  5. Class Defaults: This opens a Details panel that is responsible for the default values of all of the publically exposed variables that can be found in the Blueprint and its components. This lets you specify what state you would like these variable to be in when an instance of this Blueprint is created in a game.
  6. Simulation: This runs the Blueprint as a simulation. The simulation takes place within the Blueprint viewport. This lets you witness how the Blueprint will function within the game without having to create an instance in the level and running the game.
  7. Play: This runs the current project, and functions in the same way as the play button within the editor window. The main difference is the drop-down window located next to the Play button. This lets you select the in-Editor Blueprint instance you wish to scrutinize for debugging. Note that this kind of playing in the editor is known as a PIE (Play In Editor) session

All of these options provide you the ability to debug and run your Blueprints while working on them in your project.

Tip

Once you are familiar with the engine and you no longer need the tabs describing the title of each panel. You can right-click on the tab and select the Hide Tab option, so you can maximize available screen space.

Blueprint elements

Each Blueprint will include and be composed of certain elements, these elements can be found under the My Blueprint panel. Each of these elements will be used by you to create the custom functionality that you require from your Blueprint.

Graphs

Blueprint Graphs are the canvas with which you work to create blueprint functionality. It is within these graphs that you will place and connect your Blueprint nodes. Event Graphs house the Events that will be fired during a Blueprint's application lifetime. These events can be things like the Tick event that will be called every frame or the ActorBeginOverlap event that will be called when the Blueprint object is overlapping another. Blueprint functions and Macros will also be constructed using the graph system; however, these graphs will be independent.

Functions

Blueprint functions are a means of wrapping frequently used functionality or functionality that you wish to expose to other objects These functions act in a very similar way to standard C++ functions. You may also specify an encapsulation level when working with Blueprint functions (public, protected, and private). Blueprint functions allow you to specify both input and return parameters.

Macros

Similar to functions but are only internally facing, meaning that they can only be called from within the Blueprint itself. Macros are predominantly used for grouping sets of simple instructions that will be called very frequently. The major difference between Blueprint functions and Blueprint macros is that macros are inlined when the Blueprint is compiled. As UE4 is a C++ based engine, all blueprints are eventually compiled down into generated C++ that can be then again compiled into executable binary. When I state that the Macros are inlined, I am speaking of traditional C++ inlining to the macro function itself it its generated C++ form.

Variables

Blueprint variables allow you to create data types that can store information. These variables are very similar to Class Member Variables in C++. You can specify an encapsulation level and default values for Blueprint variables. It is also important to note that, for every component included in a blueprint, there will be a corresponding variable that will act as a reference to the component. This allows you to access components form within your blueprint graphs.

Event dispatchers

Event dispatchers allow you to bind events to one another. For example, if you wanted some functionality to be performed in Class A when an event in Class B is fired, you can do that using Event dispatchers; or similarly you can set up these delegate relationships within single objects as well. We will cover these in detail at the end of the chapter. This is very similar to Delegates in C++ and C#.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.141.165.180