Language:
Page Info
Skill Level:
Engine Version:

3. Blueprint Setup

Choose your OS:

Now that the required Materials and Render Targets have been created and setup, it is now time to create a new Blueprint and configure it to work as the fluid surface Actor.

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, naming it WaterSurface_BP.

    FS_Water_BP_Creation.png

  3. Double-click on the WaterSurface_BP to open it up and then add the following variable types.

    FS_Var_Creation.png

  4. Now, set the variables to the following default values:

    Variable Name

    Variable Type

    Default Value

    WaterMeshAsset

    Static Mesh

    SM_Plane1000_512 (Included in the Content Example Maps)

    WaterMaterial

    Material Interface

    WaterMaterial

    HeightState

    Integer

    0

    TimeAccumulator

    Float

    0.0

    WaterMID

    MaterialInstanceDynamic

    N/A

    UpdateRate

    Float

    60.0

    TouchingCharacter

    Actor

    N/A

    LastTouchingActorPosition

    Vector

    0, 0, 0

    InteractionDistance

    Float

    1.0

    MouseDown

    Bool

    Un-Checked

Blueprint Function Creation & Setup

Now that the Blueprint has been created with its required variables, it is now time to create some functions. In the following section, we will go over what the three functions are and how you go about setting them up.

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

  • The GetHeightRT function will get and store the height of the render target so that it can be used later. Before you start to create this function, make sure you setup the function's Inputs and Outputs with the following information.

    • Inputs:

      • Name: Index

      • Type:Integer

    • Outputs:

      • Name: Heigh RT

      • Type:Texture Render Target 2D

      Copy Node Graph

      FS_Get_Height_Function.png

      Do not forget to add each of the three render targets to the Height RT inputs on the Return Node.

  • The GetLastHeight function will store the last known height for the fluid surface for later use. Before you start to create this function, make sure you setup the function's Inputs and Outputs with the following information.

    • Inputs:

      • Name: CurrentHeightIndex

      • Type:Integer

      • Name: NumFramesOld

      • Type:Integer

    • Outputs:

      • Name: Heigh RT

      • Type:Texture Render Target 2D

      Copy Node Graph

      FS_Store_Last_Height.png

  • Trace From Camera is the same trace that was used in the Height Field Painter Blueprint. For this function, there are no input or output variables that need to be setup.

    Copy Node Graph

    HFP_BP_Setup_05.png

Blueprint Construction Graph Setup

The Construction Graph is used to create and set both of the Static Meshes and Materials that fluid simulation needs to function correctly. In the following section, we will go over what the three functions are, and how you go about setting them up.

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

  • In the Construction Graph, we are going to create a Static Mesh that is needed for the water surface and then create and apply a Dynamic Material Instance to that Static Mesh, which will simulate the water's surface.

    Copy Node Graph

    FS_Con_Script.png

Blueprint Event Graph Setup

The Event graph is where everything that is needed for this effect to work correctly is added and connected. In the following section, we will go over what each section of the Event Graph does and how it affects the final Blueprint that is placed in the world.

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

  • Clear all render targets of data is the part of the Blueprint that clears all of the render targets of any previous data that they might contain in order to ensure that no artifacts appear the first time the Blueprint is run.

    Copy Node Graph

    FS_Clear_All_RT.png

    Do not forget to add each of the three render targets to the *Height RT** inputs on the Return Node.

  • Check to see if Left Mouse Button is held down is the part of the Blueprint that checks to see if the user has the Left Mouse Button held down or not. If the user has the Left Mouse button held down, the MouseDown is set to true; otherwise, it is set to false.

    Copy Node Graph

    FS_Check_If_Left_Mouse.png

  • The Take Damage Force section finds the location on the Static Mesh that was hit and applies the ForceSplat Material to that section so that it can offset the surface that is simulating an impact event.

    Copy Node Graph

    FS_Take_Damage_Force.png

  • The Begin & End Overlap section checks to see if the player is currently touching the fluid surface Actor that has been placed in the world or not.

    Copy Node Graph

    FS_Begin_End_Overlap.png

  • Shoot when mouse is down is the part of the Blueprint that checks each Tick to see if the Left Mouse button is held down. When the Left Mouse button is held down, the Trace From Camera function is called, which traces from the center of the camera into the world.

    Copy Node Graph

    FS_Shoot_When_Mouse_Is_Down.png

  • Touching Character Force is the part of the Blueprint that is responsible for applying and updating the force that is applied to the fluid surface Actor when a player is touching it.

    Copy Node Graph

    FS_Touching_Char_FOrce.png

  • Fixed timestep, so fluid speed is framerate independent is the part of the Blueprint that makes sure that the propagation of the waves through the fluid surface has a frame rate that is not tied to the frame rate of the project. Essentially, the waves in the fluid surface will not slow down or speed up based on what is currently happening in the level.

    Copy Node Graph

    FS_Fixed_Time_Step.png

  • Cycle Active heightfield is the part of the Blueprint that cycles through the various render targets for the fluid surface so that the fluid surface has a more dynamic look when shot or touched.

    Copy Node Graph

    FS_Cycle_Active_Heightfield.png

  • Apply fluid surface simulation kernel, which propagates waves is the part of the Blueprint that handles the propagation of the waves through the fluid surface Actor making it look like the waves die out over time.

    Copy Node Graph

    FS_ApplySim.png

  • Compute Surface Normal is a section of the Blueprint that applies a normal to the surface of the fluid which helps make the ripples more pronounced and easier to see.

    Copy Node Graph

    FS_Compute_Surface_Normal.png

Now that the Blueprints have been setup in the next section we will take a look at how to set all of this up for use in UE4.