What is Inheritance in Unreal Engine?
In this lesson, we will learn about Inheritance in Unreal Engine, specifically how to work with Parent and Child blueprints.
Understanding how parents and children work will provide you with the opportunity to better organize your code and avoid repetitive blueprint nodes.
The amazing feature that blueprint children have is that they can access all the variables, properties, functions and code of the parent. Child Actors are really useful to create similar blueprints but with small changes.
So let’s learn how to use them!
1. Create the Parent Class
The first step is to create a Blueprint Actor in Unreal Engine.
To do this, simply right-click in the Content Browser or press the ‘+Add‘ button, and then select ‘Blueprint Class’ -> ‘Actor’.
To keep this example simple, I will just add a Static Mesh Sphere, a Custom Event, and Float and String Variables connected to Delay and Print String nodes.
In the next steps we will see how the blueprint child actor can access and modify all of these variables and events.
2. Creating a Child Class in Unreal Engine
Now, the parent blueprint is ready. It could be an enemy, an item, collectible, or whatever you need in your game.
In the content drawer, right-click on the parent blueprint and select ‘Create Child Blueprint Class‘.
Next, open the Blueprint Child Actor.
If you’ve followed all the steps correctly, in the upper right corner, you’ll notice that the Parent class is the blueprint you created earlier.
3. Modify the Child Blueprint Class
Once inside the child, you can make changes to the static mesh or material without affecting the parent’s appearance.
Additionally, in the Event Graph, you’ll find that you can easily access all Variables, Events and Functions by simply typing their names.
If you wish to execute the parent’s code, don’t forget to add the brown parent nodes, like ‘Parent: BeginPlay‘. To do it, just right click on the Event and select ‘Add Call to Parent Function‘.
To finish, selecting the child blueprint root (the first element in the component list), allows you to modify the variables inherited from the parent in the Details tab.
In this example, you can observe that I changed the Delay Duration to 2 seconds, and the Print String now outputs ‘Child’ instead of ‘Parent.’
I hope it helps! Keep creating!
Unreal Engine Learning Path
Blueprints Course
Learn more