Working with Blueprint (BP) in Unreal Engine

Published on

How to work with Blueprint (BP) in the Unreal Engine?

Platforma

Create Blueprint Asset in C++

Following code is possible to use in UBlueprintFunctionLibrary inherited class.

The code below is an analogy of manual creation of assets in the Unreal Engine editor by clicking right mouse button in Content Drawer and selecting an asset to create.

Based on set Parent Class parameter, there's possible to create any type of Blueprint asset (such as Actor, Static mesh Actor, Character, Widget, ChildBlueprint of another Blueprint...) with the C++ code right in the editor.

/**
 * Editor Only - Will not work in packaged build.
 *
 * <mark>Create a blueprint asset</mark>
 *
 * @param BlueprintPath	Path of the blueprint: "/Game/Folder/MyBp"
 * @param bOutSuccess	If the action was a success or not
 * @param OutInfoMsg	More information about the action's result
 * 
 * @return The created blueprint
 */
UFUNCTION(BlueprintCallable, Category = "<a href="https://www.youtube.com/watch?v=eEy2v95pDWw">Alex Quevillon | Create Blueprint</a>")
static UBlueprint* CreateBlueprint(FString BlueprintPath, <strong>TSubclassOf&lt;UObject&gt; ParentClass</strong>, bool& bOutSuccess, FString& OutInfoMsg);

Compile Blueprint asset with C++

/**
 * Editor Only - Will not work in packaged build.
 *
 * <mark>Compile a blueprint asset</mark>
 *
 * @param BlueprintPath	Path of the blueprint: "/Game/Folder/MyBp"
 * @param OutInfoMsg	More information about the action's result
 * @param return If the action was a success or not
 */
UFUNCTION(BlueprintCallable, Category = "<a href="https://www.youtube.com/watch?v=WNSLXtrfSns" target="_blank">Alex Quevillon | Compile Blueprint</a>")
static void CompileBlueprint(FString BlueprintPath, FString& OutInfoMsg);

Spawn Actor to any Blueprint

AddNodeToBlueprint defined below will be used by functions adding various kind of actors into any blueprint based on its BlueprintPath.

This way of adding any Actor to any Blueprint comes in handy if we need to extend 1 or more Bluperint actors from one place - e.g. during automatization process. If we code a C++ class, from which a blueprint asset is inherited, adding actors to blueprint is easy to do through the common way.

Add a component node to a blueprint asset (Help function)

/**
 * Editor Only - Will not work in packaged build.
 *
 * Add a component node to a blueprint asset
 *
 * @param BlueprintPath Path of the blueprint: "/Game/Folder/MyBp"
 * @param ComponentTemplate The component to use as a template when creating the node
 * @param ParentNodeName  The name of the desired parent node
 * @param bOutSuccess If the action was a success or not
 * @param OutInfoMsg  More information about the action's result
 * 
 * @return The node that was created
 */
UFUNCTION(BlueprintCallable, Category = "<a href="https://www.youtube.com/watch?v=KpQYzYwJJQ0" target="_blank">Add Components To Blueprint</a>")
static class USCS_Node* AddNodeToBlueprint(FString BlueprintPath, class USceneComponent* ComponentTemplate, FString ParentNodeName, bool& bOutSuccess, FString& OutInfoMsg);
  • Add a scene component to a blueprint asset

    /**
     * Editor Only - Will not work in packaged build.
     *
     * Add a scene component to a blueprint asset
     *
     * @param BlueprintPath Path of the blueprint: "/Game/Folder/MyBp"
     * @param bOutSuccess If the action was a success or not
     * @param OutInfoMsg  More information about the action's result
     * 
     * @return The node that was created
     */
    UFUNCTION(BlueprintCallable, Category = "<a href="https://www.youtube.com/watch?v=KpQYzYwJJQ0" target="_blank">Add Components To Blueprint</a>")
    static class USCS_Node* AddSceneComponentToBlueprint(FString BlueprintPath, bool& bOutSuccess, FString& OutInfoMsg);
  • Add a point light component to a blueprint asset

    	/**
     * Editor Only - Will not work in packaged build.
     *
     * Add a point light component to a blueprint asset
     *
     * @param BlueprintPath Path of the blueprint: "/Game/Folder/MyBp"
     * @param bOutSuccess If the action was a success or not
     * @param OutInfoMsg  More information about the action's result
     * 
     * @return The node that was created
     */
    UFUNCTION(BlueprintCallable, Category = "<a href="https://www.youtube.com/watch?v=KpQYzYwJJQ0" target="_blank">Add Components To Blueprint</a>")
    static class USCS_Node* AddPointLightComponentToBlueprint(FString BlueprintPath, bool& bOutSuccess, FString& OutInfoMsg);
  • Add a camera component to a blueprint asset

    /**
     * Editor Only - Will not work in packaged build.
     *
     * Add a camera component to a blueprint asset
     *
     * @param BlueprintPath Path of the blueprint: "/Game/Folder/MyBp"
     * @param bOutSuccess If the action was a success or not
     * @param OutInfoMsg  More information about the action's result
     * 
     * @return The node that was created
     */
    UFUNCTION(BlueprintCallable, Category = "<a href="https://www.youtube.com/watch?v=KpQYzYwJJQ0" target="_blank">Add Components To Blueprint</a>")
    static class USCS_Node* AddCameraComponentToBlueprint(FString BlueprintPath, bool& bOutSuccess, FString& OutInfoMsg);
Vrealmatic consulting

Anything unclear?

Let us know!

Contact Us