Parent and Child Blueprints in Unreal Engine 4

In this guide I will be going through Parent and Child blueprints in Unreal Engine 4. They are a key part of making manageable code and preventing repeated blueprint nodes in similar classes.

Inheritance is an important feature in many object oriented programming languages. It allows programmers to create variations of an object and communicate with them as if they are all the same original type.

Blueprints also have the ability to have child classes and have parent classes that they inherit from.

If you want to learn more about the theory behind inheritance, click here for a tutorial from w3 schools showing inheritance in C++.

Parent Class

Creating the Parent Class

To start, create a new blueprint actor and name it ParentActor.

Creating the parent blueprint class

This actor can now be filled with events, input actions, variables, functions and more. All of these attributes will be shared to our child actors.

If you don’t know how to use input actions and input axes click here for a detailed run down on how to include these powerful events into your project.

Setting up the Parent Class

To demonstrate, I have created two keybinds, an event, a function and a float variable.

Pressing 1 will set this float value to 1 and pressing 2 will set the float value to 2.

Setting up the parent class with basic inputs and setting variables

Child Class

Creating a child class

Creating a child class from your chosen parent class is very easy.

To create a new class based on a previous simply right click your chosen class in the content browser and click create child blueprint.

Creating the child blueprint class

Accessing the parent

Variables

Inside the child actor there are no visible variables of the left side.

No functions, variables or macros shown in child class

Right clicking and searching for your parent variables will reveal them in the default section.

Parent variables showing in child class

Events and Functions

Right clicking inside your child blueprint class and typing the name of your functions and events will give you access to them.

Parent events showing in child class

Key events will override any code that is on the same parent event. This child class will now print 10 on key press 1 and 20 on key press 2.

Child key inputs run different code

To make sure the parent code runs as well as the child code on these key inputs, click on the input and look to the right of the details panel.

Un-checking the “Override Parent Binding” box will run both sections of code. If you want your child to have different behaviors on the same key presses you can leave this checked.

Parent bindings overridden on child class

Running Parent Code

When accessing parent functions and events you are stopping the parent code from running. This is called overriding.

To make sure the parent code runs during the event, right click the specific event and click Add Call to Parent Function.

Creating the parent function call
Connecting the parent event

Now when custom parent event is fired the child code will run and the parent code will run. The expected output is “Hello From Parent Class” on screen.

Parent event printing strings to the screen

Conclusion

That is the basics of parent and child classes in unreal engine 4!

Designing your code to utilize this powerful technique will improve the readability and efficiency of your game development processes.

Leave a Reply

Your email address will not be published. Required fields are marked *