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

You're reading from   Game Development Projects with Unreal Engine Learn to build your first games and bring your ideas to life using UE4 and C++

Arrow left icon
Product type Paperback
Published in Nov 2020
Publisher Packt
ISBN-13 9781800209220
Length 822 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Authors (5):
Arrow left icon
 Reis Reis
Author Profile Icon Reis
Reis
Hammad Fozi Hammad Fozi
Author Profile Icon Hammad Fozi
Hammad Fozi
Gonçalo Marques Gonçalo Marques
Author Profile Icon Gonçalo Marques
Gonçalo Marques
David Pereira David Pereira
Author Profile Icon David Pereira
David Pereira
Devin Sherry Devin Sherry
Author Profile Icon Devin Sherry
Devin Sherry
+1 more Show less
Arrow right icon
View More author details
Toc

Table of Contents (19) Chapters Close

Preface
1. Unreal Engine Introduction 2. Working with Unreal Engine FREE CHAPTER 3. Character Class Components and Blueprint Setup 4. Player Input 5. Line Traces 6. Collision Objects 7. UE4 Utilities 8. User Interfaces 9. Audio-Visual Elements 10. Creating a SuperSideScroller Game 11. Blend Spaces 1D, Key Bindings, and State Machines 12. Animation Blending and Montages 13. Enemy Artificial Intelligence 14. Spawning the Player Projectile 15. Collectibles, Power-Ups, and Pickups 16. Multiplayer Basics 17. Remote Procedure Calls 18. Gameplay Framework Classes in Multiplayer

Event Graph

The Event Graph window is where you'll be writing all of your Blueprint visual scripting code, creating your variables and functions, and accessing other variables and functions declared in this class's parent class.

If you select the Event Graph tab, which you should be able to see to the right of the Viewport tab, you will be shown the Event Graph window instead of the Viewport window. On clicking the Event Graph tab, you will have the following window:

Figure 1.21: The Event Graph window, showing three disabled events

Figure 1.21: The Event Graph window, showing three disabled events

You can navigate the Event Graph by holding the right mouse button and dragging inside the graph, you can zoom in and out by scrolling the mouse wheel, and you can select nodes from the graph by either clicking with the left mouse button or by pressing and holding to select an area of nodes.

You can also right-click inside the Event Graph window to access the Blueprint's Actions menu, which allows you to access the actions you can do in the Event Graph, including getting and setting variables, calling functions or events, and many others.

The way scripting works in Blueprint is by connecting nodes using pins. There are several types of nodes, such as variables, functions, and events. You can connect these nodes through pins, of which there are two types:

  1. Execution pins: These will dictate the order in which the nodes will be executed. If you want node 1 to be executed and then node 2 to be executed, you link the output execution pin of node 1 to the input execution pin of node 2, as shown in the following screenshot:
    Figure 1.22: The output execution pin of the Event OnReset node being connected 
to the input execution pin of the setter node for MyVar

    Figure 1.22: The output execution pin of the Event OnReset node being connected to the input execution pin of the setter node for MyVar

  2. Variable pins: These work as parameters (also known as input pins), at the left of the node, and return values (also known as output pins), at the right side of the node, representing a value of a certain type (integer, float, Boolean, and others):
    Figure 1.23: The Get Scalar Parameter Value function call node, which has two input variable pins and one output variable pin

Figure 1.23: The Get Scalar Parameter Value function call node, which has two input variable pins and one output variable pin

Let's understand this better through the next exercise.

Exercise 1.04: Creating Blueprint Variables

In this exercise, we will see how to create Blueprint variables by creating a new variable of the Boolean type.

In Blueprint, variables work similarly to the ones you would use in C++. You can create them, get their value, and set them.

The following steps will help you complete this exercise:

  1. To create a new Blueprint variable, head to the My Blueprint window and click the + Variable button:
    Figure 1.24: The + Variable button being highlighted in the My Blueprint window, which allows you to create a new Blueprint variable

    Figure 1.24: The + Variable button being highlighted in the My Blueprint window, which allows you to create a new Blueprint variable

  2. After that, you'll automatically be allowed to name your new variable. Name this new variable MyVar:
    Figure 1.25: Naming the new variable MyVar

    Figure 1.25: Naming the new variable MyVar

  3. Compile your Blueprint by clicking the Compile button on the left side of the Toolbar window. If you now take a look at the Details window, you should see the following:
    Figure 1.26: The MyVar variable settings in the Details window

    Figure 1.26: The MyVar variable settings in the Details window

  4. Here, you'll be able to edit all the settings related to this variable, the most important ones being Variable Name, Variable Type, and its Default Value at the end of the settings. Boolean variables can have their value changed by clicking the gray box to their right:
    Figure 1.27: The variable types available from the Variable Type drop-down menu

    Figure 1.27: The variable types available from the Variable Type drop-down menu

  5. You can also drag a getter or setter for a variable inside the My Blueprint tab into the Event Graph window:
    Figure 1.28: Dragging the MyVar into the Event Graph window and choosing 
whether to add a getter or setter

    Figure 1.28: Dragging the MyVar into the Event Graph window and choosing whether to add a getter or setter

    Getters are nodes that contain the current value of a variable while setters are nodes that allow you to change the value of a variable.

  6. To allow a variable to be editable in each of the instances of this Blueprint class, you can click the eye icon to the right of that variable inside the My Blueprint window:
    Figure 1.29: Clicking the eye icon to expose a variable and allow it to be instance-editable

    Figure 1.29: Clicking the eye icon to expose a variable and allow it to be instance-editable

  7. You can then drag an instance of this class to your level, select that instance, and see the option to change that variable's value in the Details window of the editor:
    Figure 1.30: The exposed MyVar variable that can be edited through the 
Details panel of that object

Figure 1.30: The exposed MyVar variable that can be edited through the Details panel of that object

And with that, we conclude this exercise and now know how to create our own Blueprint variables. Let's now take a look at how to create Blueprint Functions in the next exercise.

Exercise 1.05: Creating Blueprint Functions

In this exercise, we will create our first Blueprint Function. In Blueprint, functions and events are relatively similar, the only difference being that an event will only have an output pin, usually because it gets called from outside of the Blueprint class:

Figure 1.31: An event (left), a pure function call that doesn't need execution pins (middle), and a normal function call (right)

Figure 1.31: An event (left), a pure function call that doesn't need execution pins (middle), and a normal function call (right)

The following steps will help you complete this exercise:

  1. Click the + Function button inside the My Blueprint window:
    Figure 1.32: The + Function button being hovered over, which will create a new function

    Figure 1.32: The + Function button being hovered over, which will create a new function

  2. Name the new function MyFunc.
  3. Compile your Blueprint by clicking the Compile button in the Toolbar window:
    Figure 1.33: The Compile button

    Figure 1.33: The Compile button

  4. If you now take a look at the Details window, you should see the following:
    Figure 1.34: The Details panel after selecting the MyFunc function and adding 
an input and output pin

    Figure 1.34: The Details panel after selecting the MyFunc function and adding an input and output pin

    Here, you'll be able to edit all the settings related to this function, the most important ones being Inputs and Outputs at the end of the settings. These will allow you to specify the variables that this function must receive and will return.

    Lastly, you can edit what this function does by clicking it from the My Blueprint window. This will open a new tab in the center window that will allow you to specify what this function will do. In this case, this function will simply return false every time it is called:

    Figure 1.35: The contents of the MyFunc function, receiving a Boolean parameter, 
and returning a Boolean type

    Figure 1.35: The contents of the MyFunc function, receiving a Boolean parameter, and returning a Boolean type

  5. To save the modifications we made to this Blueprint class, click the Save button next to the Compile button on the toolbar. Alternatively, you can have it so that the Blueprint automatically saves every time you compile it successfully by selecting that option.

After following these steps, you now know how to create your own Blueprint Functions. Let's now take a look at a Blueprint node we'll be making use of later in this chapter.

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at £13.99/month. Cancel anytime
Visually different images