Unreal Engine 4: The Event Graph

seana19931
4 min readMar 20, 2017

--

At the time of writing, I am a Software Developer student. I have been coding for about 3 and a half years. By my own standards, I’m a beginner, only now defining for myself as a programmer and still eager to learn new languages and find new techniques for coding. Sometimes my inexperience with programming means that when confronted with projects that require learning a new language, I’m hesitant to really dive in head first like I otherwise would. So when I first started using Unreal Engine 4 and realized that I was going to be introduced to C++ for the first time, I was nervous! However, as my project progressed, my easement into C++ and Unreal’s functionality was helped tremendously thanks to the Event Graph utility.

The Event Graph is a visual representation of C++ code which is triggered by, you guessed it, events! Whenever an event occurs in the game world, whether it be to an enemy character, player character, or even event associated with the game mode, the developer can call C++ functions and utilities which allow them to customize and build their game however they see fit.

To show you some of the functionality of the Event Graph, I will take you through the spawn enemy event in a twin stick shooter game that I created. This game infinitely spawns enemy characters, while a player character shoots at the enemy characters in a small piece of level geometry.

We start at the “SpawnEnemy” event, a custom event that calls on the “Get All Actors Of Class function”. You can see underneath the “Actor Class” text that there is a drop down list that is currently set to “Enemy Character”, an object previously made that represents the character model that this spawner will create. This function returns an array, as it should seeing as it is a get function that will retrieve all of the enemy characters in the game world. The array is represented by the blue box at the bottom right of the function. By clicking and dragging from the blue box, a search query pops up, inquiring what you would like to do with the return of the function. For my particular needs, I must be able to determine how many enemy characters are in the game world at any given time, and set a limit on how many there can be. As a result, I created a node to determine the length of the array that results from getting all the enemy characters.

Then I created a node that evaluates whether or not the length of the array is less than the “Max Enemies” variable that I’ve set to 15. This is used as the Boolean condition for the “Branch” node, which is the Event Graph’s version of an “if” statement. The event graph allows you to create an “if-else if” construct by chaining together false results with new conditions, however for this example there is only an “if” construct. This branch then, if the less than 15 condition evaluates to true, then a call to the “Spawn AI From Class” function is called, which will spawn an enemy character.

We’re almost done with this use case, but not quite. There still needs to be a location from which the enemy character needs to spawn from. That’s where the final section of our “SpawnEnemy” event comes into play. Tied to the location input on the “Spawn AI From Class” function are calls to 3 functions: “Random Point in Bounding Box”, “Get World Location”, and “Get Scaled Box Extent”. All of these functions tie into the spawn volume variable, which represents an invisible mesh above the level geometry that allows for an enemy to spawn anywhere inside of it.

The spawn volume is the see through square with the golf ball in the middle

This means that the functions tied to the spawn volume implement the functionality of the volume. They read the dimensions of the spawn volume, read where in the level the volume is, and pick a random point inside of it to create an enemy character.

Because of Unreal Engine’s ease of use and code documentation, I was able to easily look for and research what I wanted in order to create this project. All of this was created by either right clicking on the Event Graph and searching for what I wanted, clicking and dragging values from inside the nodes onto the event graph, or clicking and dragging objects from the components panel of the UI. The source code for any of the non-custom events or functions is made available by Unreal. Because I was able to look at the source code for some of the other crucial functions implemented in my project via the Event Graph, I was able to ease myself into learning C++, and take away the early intimidation of learning a new language.

--

--