Choose your operating system:
Windows
macOS
Linux
Components are a special type of Object designed to be used as sub-objects within Actors. These are generally used in situations where it is necessary to have easily swappable parts in order to change the behavior or functionality of some particular aspect of the owning Actor. For instance, a car is controlled and moves very differently from an aircraft, which is controlled and moves differently from a boat, etc.; yet all of these are vehicles that share other commonalities. By using a Component to handle the controls and movement, the same vehicle can easily be made to behave like any one of these specific types.
Implementation Guide
In this guide, you will learn how to add Components to a Blueprint and how Components can be accessed and modified inside a Blueprint. To show this, we will create a simple burning bush Blueprint Actor that is comprised of three components: the Static Mesh Component (the Bush), an Audio Component (fire sound effect) and a Particle Effect (the visible fire effect).
Adding Components to a Blueprint
For this example, we are using the Blueprint Third Person Template with Starter Content.
The steps below will show you how to Add Components to a Blueprint Actor.
In the Content Browser, under the StarterContent/Props folder, Right-click on the SM_Bush asset, scroll up to Asset Actions, and select Create Blueprint Using This....
This will create a Blueprint based on this asset and will add it to the Blueprint as a Component.
Click Ok when the Create Blueprint window opens.
In the Content Browser, under the StarterContent/Blueprint folder, open the SM_Bush Blueprint.
In the Blueprint Editor window, click the Viewport tab in the upper left of the window.
You will notice that the Bush has already been added as a Component to our Burning Bush Actor.
On the Components tab, click the Add Component button in the Components window.
This window allows you to add Components to the Blueprint, in this case we can add a fire and audio effect.
Click Audio to add an Audio Component and notice that the Details window is populated below the Components window.
This is where you specify the details regarding the Component. Depending upon the Component added, varying options will be presented that you can define. In this case, we want to define the actual Sound Asset that the Audio Component will use.
In the Details panel, click the None box under Sound then select the Fire01_Cue asset.
We have now added a fire sound effect that emits from our Bush.
Click the Add Component button again and scroll through the list and add a Particle System Component.
In the Details panel for the Particle Effect, click the None box next to Template and select P_Fire.
We now are ready to finish the Blueprint, click the Compile button in the upper left of the window.
After you Compile, you should see the green check to indicate that it was successful.
Close the Blueprint, then in the Content Browser, under Game/Blueprints, drag the SM_Bush into the level.
Click the Play Button to play in the editor.
You should now see that we have a bush that is on fire and plays a fire audio effect. As you move away from the bush, the audio should fade out and it should fade in as you move close to the bush.
We have created a Blueprint Actor that is comprised of three Components, we could have placed the bush in the level, then placed the audio inside the bush, then placed the fire in the bush; however creating a Blueprint that has these Components is a far more manageable solution than having individual pieces.
Working with Components in Blueprints
Each of the Components inside a Blueprint can be accessed and modified from within the Blueprint itself or from an external Blueprint. For example, if we had a Car Blueprint and had an Engine Blueprint as a Component, we could modify the way the car performs by tweaking the values inside the Engine Blueprint.
Using the burning bush example from this page, if you look in the MyBlueprint window, you will notice that each of the Components are provided in the Components section:
Each of these Components can be placed inside the graph and access through Blueprint Script and modified (see the example below):
Here we are enabling input on the Burning Bush Blueprint Actor so that the player can modify it on a key press. We have added the F Key Event that when pressed, toggles between Deactivating and Activating the Particle System and Audio Components (turning them on or off when the key is pressed).
Additional Resources
There are several concepts that tie into Adding Components to Blueprints and the links below provide additional relevant information: