UE4 – Blueprints – Set Parent Class

Software:
Unreal Engine 4.24

When It comes to OOP inheritance, the best practice is to take a moment to think about code structure and decide which classes should be be extensions of a common super-class. But in a wild hackathon or game-jam, we may be blueprinting too hastily for that, and we may find out different blueprint classes actually have to be child classes of a common parent class after they already exist and have existing blueprints in them.
In this case will have to Set their parent class as a different class than the class we chose when we initially created them, and also create calls to the parent class event functions if needed.

Setting a BP’s parent class:

Click Class Settings, and under Class Options, in the Parent Class drop-down select the wanted parent class (superclass).
Annotation 2020-03-22 131138

 

Calling the Parent Class’s event functions:

Note:
When creating a BP class that is defined as child class in its creation this is done automatically

  1. Right-Click the current class’s Event icon, and select Add call to parent function:Annotation 2020-03-22 153156
  2. Connect the execution flow graph, and other inputs if necessary:
    Annotation 2020-03-22 161019

 

 

UE4 Blueprints – Spawn Actor Transform Note..

Software:
Unreal Engine 4.24

Short version:
When Spawning new actors via the SpanActor Blueprint node, initial transform must be supplied to the SpanActor node, and not defined in the spawned Actor Class’s Blueprint.

Annotation 2020-03-22 131138

Explanation:
Just found out the hard way, that when you spawn an Actor using the SpawnActor blueprint node, the transform data connected to the SpawnActor node is actually applied after the actors Construction Script and BeginPlay Event.
This means any transform you will try to apply in the spawned Actor’s Blueprint will be overridden and therefore not work.

UE4 Material Blueprint Shortcuts

Software:
Unreal\n Engine 4.24

Some useful Unreal Editor Material Blueprint shortcuts:

  1. Hold 1 and LMB Click to create a 1D Constant node:
    Annotation 2019-12-26 005530
  2. Hold 2 and LMB Click to create a 2D Constant node:
    Annotation 2019-12-26 005549
  3. Hold 3 and LMB Click to create a 3D Constant node:
    Annotation 2019-12-26 005605
  4. Hold S and LMB Click to create a Scalar Parameter node:
    Annotation 2019-12-26 005618
  5. Hold V and LMB Click to create a Vector Parameter node:
    Annotation 2019-12-26 005631
  6. Hold L and LMB Click to create a Lerp (Linear Interpolate) node:Annotation 2019-12-26 005653
  7. Hold M and LMB Click to create a Multiply node:
    Annotation 2019-12-26 005722
  8. Hold A and LMB Click to create a Add node:
    Annotation 2019-12-26 005736
  9. Hold T and LMB Click to create a Texture Sample node:Annotation 2019-12-26 010504
  10. Hold U and LMB Click to create a Texture Coordinate node:
    Annotation 2019-12-26 010449
  11. Just press C to create a comment:
    Annotation 2019-12-26 005808

More UE4 Material Editing posts

UE4 – Material Functions explanation and Example

Software:
Unreal Engine 4.24

Material Functions encapsulate shading flow graphs (material blueprints) into reusable shading nodes that have their own inputs and outputs.
This allows development of custom shading nodes, and saving the time it takes to recreate the same flow graphs multiple times or even copy and paste material flow graphs.
Common shading processes and operations that have to be performed in many different materials, and even multiple times in a single material can be defined as a Material Function for quick and easy re-usability.
Material functions can also be used to encapsulate a full material blueprint with a Material Attributes output. this provides a convenient workflow for blending different materials together.

In this post I’ll detail the steps needed to create and use a Material Function.
The Material Function example we’ll create, called “ColorAngleBlend” performs a commonly needed shading operation of blending 2 colors or textures according to the surface viewing angle (facing ratio).

The ColorAngleBlend Material Function will have the following inputs:

  1. color a:
    The color or texture appearing when viewing the surface at perpendicular angle.
  2. color b:
    The color or texture appearing when viewing the surface at grazing view angle.
  3. curve exponent:
    The steepness of the blend curve between the colors, 1 being a linear blend and higher values displaying color a at more angles “pushing” color b to be seen only at grazing angle.
  4. base color blend:
    The percent of color b seen at perpendicular view angle.
  5. normal:
    bump normals input.

The final “ColorAngleBlend” Material Function Blueprint:
* The internals of the “ColorAngleBlend” Material Function
Annotation 2019-12-24 151655.jpg

An example of the “ColorAngleBlend” Material Function node used to create a reach view-angle dependent color blend for a steampunk metal material:
Annotation 2019-12-24 152625

An example of the “ColorAngleBlend” Material Function node used to create a reach color for a car-paint material:
Annotation 2019-12-24 152036

An example of the “ColorAngleBlend” Material Function node used to create a washed-out effect for a cloth material:Annotation 2019-12-24 151927
Steps for creating the “ColorAngleBlend” Material Function:

  1. In the content browser, create a Material Function Object and name it “ColorAngleBlend”:
    Annotation 2019-12-24 161420
    Annotation 2019-12-24 162132
  2. Double click the ColorAngleBlend Material Function to open it for editing:
    Annotation 2019-12-24 162209
  3. Click the background of the work space to deselect the Output Result Node,
    So that the Details panel on the left will display the Material Functions‘s properties.
    Type a description into the Description field, check the Expose to Library option so that the new Material Function will be available to all materials in the Palate and node search, and define in which node categories it should appear:
    Annotation 2019-12-24 162805
  4. Select the Output Result node and in the Details panel on the left set its output name to “color”:
    Annotation 2019-12-24 163948
  5. Add a Linear Interpolate (Lerp) node, a Fresnel node and a Transform Vector (Tangent space to World space) node to the Blueprint and connect the nodes like this:
    * The Lerp node will blend the 2 color inputs with the Fresnel providing view angle data as the alpha for the Lerp.
    The Transform Vector  node is needed to convert normal (bump) input to world space for the Fresnel node.
    Annotation 2019-12-24 164646.jpg
  6. Adding function inputs:
    Create 2 Function Input nodes, in their Details panel, name them “color a” and “color b”, leave their Input Type as default Vector3D, check the option Use Preview Value as Default, number their Sort Priority parameters 0 and 1 to make them appear as the first inputs of the ColorAngleBlend node as it will appear when used in a material, and connect them to the Lerp node’s A and B inputs:
    Annotation 2019-12-24 165934
  7. Adding function inputs:
    Create 2 new Function Input nodes, name them “curve exponent” and “base color blend”, this time set their Input Type to Scalar, check the option Use Preview Value as Default, set their Sort Priority parameters to 2 and 3 and connect their outputs to the Fresnel node’s ExpoentIn and BaseReflectFractionIn inputs:
    Annotation 2019-12-24 171212.jpg
  8. Adding function inputs:
    Create the final Function Input node, name it “normal“, set its Input Type to Vector3D, check its Preview Value as Default option, set its Sort Priority to 4, and connect its output to the Fresnel node’s Normal input:
    Annotation 2019-12-24 171640
  9. Adding default inputs:
    Finally, add constant nodes to serve as default input values for the Material Function.
    A pure white Constant3Vector (color) constant as the default value for “color a” input,
    A pure black Constant3Vector (color) constant as the default value for “color a” input,
    A Constant with value 1.0 as the default value for “curve exponent” input,
    A Constant with value 0.0 as the default value for”base color blend” input,
    A pure blue Constant3Vector (color) constant as the default value for “normal” input.
    > Tip for quick creation of constant value nodes
    Annotation 2019-12-24 172438
  10. Save the new Material Function.

To use the new ColorAngleBlend Material Function create a new material, in the node search start typing color… to locate the ColorAngleBlend node and create it, and connect it to the desired material input.

Annotation 2019-12-24 173747

Annotation 2019-12-24 173809.jpg

> Material Functions can also be used by dragging them from the Content Browser into the Material Blueprint.

Related posts:
UE4 – Procedural Bump Normals
UE4 – Material Instances
UE4 – Fresnel node
UE4 – Triplanar mapping

UE4 – Create and Play a Level Sequence

Software:
Unreal Engine 4.24

To create animations and trigger them to play on game start:

First create a Level Sequence containing the animation:

  1. Create a new Level Sequence actor:
    Annotation 2019-12-23 164745
  2. Name the new Level Sequence and drag it to into the level:
    Annotation 2019-12-23 165833.jpg
  3. Select the actor you want to animate in the level and double click the Level Sequence in the Content Browser to open it in the Sequencer window:
    Annotation 2019-12-23 170453.jpg
  4. In the Sequencer window, press the +Track button to add a sequence track, choose the upper most option Actor To Sequence, the option to Add the selected actor will automatically appear first on the menu that will open on the right:
    Annotation 2019-12-23 170622
  5. Add the selected actor as a sequence track, expand the track’s Transform channels to reveal the Transform property you would like to animate, and click the + button for that channel to create the first key-frame:
    Annotation 2019-12-23 171623
  6. Activate the Create when channels/properties change option button:
    Annotation 2019-12-23 171932
  7. Move the time slider to a desired time for the motion and move/change the actors transform to create a new key-frame:
    Annotation 2019-12-23 172115.jpg

The Level Sequence now contains animation for the Actor, but when we play the game, the animation doesn’t play.
For the animation to play in game, we must trigger it fro a Blueprint, in this case the Level Blueprint:

  1. From the Editor Blueprints menu, choose Open Level Blueprint:
    Annotation 2019-12-23 173450
  2. In the Level Blueprint, drag the Event BeginPlay execution graph and create CreateLevelSequencePlayer node that will follow it:
    Annotation 2019-12-23 173759
  3. Drag the CreateLevelSequencePlayer node’s Return Value output and create a Play node that will be executed after it and receive it’s output:
    Annotation 2019-12-23 173854
  4. The Level Blueprint now has instructions to play a Level Sequence,
    but it’s not yet specified which Level Sequence to play:
    Annotation 2019-12-23 173929
  5. In the Variables list on the left, press the +Variable button to create a new variable and name it:
    Annotation 2019-12-23 174757
  6. With the new variable selected, in it’s details on the right, press the Variable Type button, and locate Level Sequence – Object Reference type:
    Annotation 2019-12-23 174932.jpg
  7. The Level Blueprint now contains a variable named seq of type: Level Sequence – Object Reference:
    Annotation 2019-12-23 175200.jpg
  8. Drag the new variable to the Blueprint and choose Get when placing it:
    Annotation 2019-12-23 175536
  9. Connect the variable’s output to the Level Sequence input of the CreateLevelSequencePlayer node:
    Annotation 2019-12-23 175609
  10. With the variable selected, in the details panel on the right, select the Level Sequence object it will be referencing:
    Annotation 2019-12-23 175627
  11. Press Compile and save the Level Blueprint:
    Annotation 2019-12-23 175646

The Level Blueprint now has instructions to play the desired Level Sequence when the level begins playing so a the animation we created plays when we hit play game in the editor:
Annotation 2019-12-23 180500

animseq.gif

 

Related:
UE4 Camera Animation

UE4 Blueprint Delay node

Software:
Unreal Engine 4.18

Untitled-1

The Delay node serves as a timer that will execute the connected blueprint after a predefined time in seconds.

An example of usage could be triggering a game event at a set time after the player entered a location.
You can use random values or other expressions connected to the Duration input to create a richer and less predictable interaction.

UE4 Actor Blueprint – Referencing another Actor instance

Software:
Unreal Engine 4.18

A direct reference to another actor instance can’t be created from within the blueprint because it can only be provided at run-time after the instances have been created, both the current actor and the other actor we want to refer to.

In the Actor Blueprint:

  1. Add a new variable of type Actor > Object Reference
  2. Make the variable public and editable in the editor (the eye button..)
  3. Hit Compile and Save.

In the Map Editor:

  1. Place both actors in the map and save it.
  2. Select the actor in which you created the reference variable.
  3. In the Details panel, set the Actor property you created to the wanted other Actor instance.

Untitled-7.jpg

Untitled-7.jpg