Language:
Page Info
Skill Level:
Engine Version:

3. Blueprint Setup

Choose your OS:

With the render targets and needed Materials setup and ready to use, it is now time to bring everything together using a Blueprint. In the following section, we will go over how to setup all of the various parts of the Height Field Painter Blueprint.

Blueprint Creation & Variable Setup

  1. Right-click in the Content Browser and from the menu in the Create Basic Asset section, click on the Blueprint Class option.

    HFP_BP_Setup_00.png

  2. From the Pick Parent Class window, select Actor and name it HeightFieldPainter.

    HFP_BP_Setup_01.png

  3. Double-click on the HeightFieldPainter Blueprint to open it up and then click on the Event Graph tab. When the Event Graph is open, add the following variables.

    HFP_BP_Setup_02.png

    Variable Name

    Variable Type

    Default Value

    HeightfieldRT

    Texture Render Target 2D

    N/A

    PainterMaterialInstance

    Material Instance Dynamic

    N/A

    MouseDown

    Bool

    N/A

    ForceSplatMID

    Material Instance Dynamic

    N/A

    InteractionDistance

    Float

    1000.0

    BrushSize

    Float

    0.04

    BrushStrength

    Float

    1.0

Components Setup

Inside of the Components tab, press the Add Component button and add a Static Mesh Component to the Blueprint. Once the Static Mesh Component has been added, select the Static Mesh Component and setup the following options.

HFP_BP_Setup_06.png

Section

Property

Required Asset

Value

Transform

Mobility

N/A

Movable

Static Mesh

Static Mesh

SM_Plane1000_512

N/A

Materials

Material

HeightfieldPainterMaterial

N/A

Collision

Generate Overlap Events

N/A

Checked

Collision

Collision Presets

N/A

OverlapOnlyPawn

Construction Script Setup

The Construction script is used to create and assign a 2D render target in addition to creating and assigning the required Dynamic Material Instances. If you arean't already there, click on the Construction Script tab and then copy the following code into your Blueprints Construction Script.

Copy Node Graph

HFP_BP_Setup_03.png

Trace from Camera Function Setup

There are two ways you can implement this function. The first method requires a bit of math and works primarily on planes or other flat surfaces. The second method uses the Find Collisoin UV node which requires more memory to use, but will work across any Static Mesh Component, regardless of shape (UV seams will still cause artifcats). You can choose your implementation method below.

Choose Implementation Method

Method 1

Method 2

The Trace from Camera function will be used to determine the location on the Static Mesh that should have its height increased. It determines this location by casting a ray from the center of the player's camera into the world. When that ray intersects with a Static Mesh, the location that it intersects will be the location that is raised. To set up the Trace from Camera function, you will need to do the following.

  1. Click the small (white) plus sign on the Functions tab to create a new function and name it TraceFromCamera.

    HFP_BP_Setup_04.png

  2. Open the TraceFromCamera function and copy the following Blueprint code into your Blueprint by hovering your mouse over the image below and then clicking on the Copy Expression Graph option, selecting the code, copying it, and then pasting it into the TraceFromCamera function.

    Copy Node Graph

    HFP_BP_Setup_05.png

    Do not forget to Compile and Save your Blueprint so that it can be used.

Event Graph Setup

Now that all of the need parts have been created and setup, it is now time to connect all of the various parts together in the Event Graph. You can copy the completed Blueprint code into your Blueprint by hovering your mouse over the image below and then clicking on the Copy Node Graph option, copying-and-pasting the provided Blueprint code into your Height Field Painter Blueprint.

Copy Node Graph

HFP_BP_Setup_07.png

When you copy-paste the Blueprint code, the Event Begin Play node will not be added to the graph. Make sure that you add the Event Begin Play node and connect it to the Enable Input input.

HFP_BP_Setup_08.png

Now that the required Blueprints have been setup, in the next section we will go over how to use the height map painter inside UE4.

You have to enable Support UV from Hit Result feature in the editor to use this method. See getting uv coordinates from trace for information on how to do this.

  1. Click the small (white) plus sign on the Functions tab to create a new function and name it TraceFromCamera.

    HFP_BP_Setup_04.png

  2. Open the TraceFromCamera function and copy the following Blueprint code into your Blueprint by hovering your mouse over the image below and then clicking on the Copy Expression Graph option, selecting the code, copying it, and then pasting it into the TraceFromCamera function.

    Copy Node Graph

    HFP_BP_Setup_01.png

    Do not forget to Compile and Save your Blueprint so that it can be used.

Event Graph Setup

Now that all of the need parts have been created and setup, it is now time to connect all of the various parts together in the Event Graph. You can copy the completed Blueprint code into your Blueprint by hovering your mouse over the image below and then clicking on the Copy Node Graph option, copying-and-pasting the provided Blueprint code into your Height Field Painter Blueprint.

Copy Node Graph

HFP_BP_Setup_02.png

When you copy-paste the Blueprint code, the Event Begin Play node will not be added to the graph. Make sure that you add the Event Begin Play node and connect it to the Enable Input input.

HFP_BP_Setup_08.png

Now that the required Blueprints have been setup, in the next section we will go over how to use the height map painter inside UE4.