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 – First Person Projectile Overlap Event

Software:
Unreal Engine 4.24

Had some frustrating time not understanding why doesn’t the FirstPersonProjectile Actor doesn’t “play ball” and generate Overlap Events when hitting my bad guys..
It turns out I had to change its collision (sphere) component’s collision settings to overlap dynamic objects (see image):
Annotation 2020-03-14 231242

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 – Basic Material Blending

Software:
Unreal Engine 4.24

The example explained in this article is creating a blend between a mud material, and a mud-leaves material using a mask (Alpha) texture.
>>
The scanned PBR materials in demonstrated in this post are from Texture Haven (texturehaven.com)

How does it work?
There is actually no blending of Unreal materials, but rather a regular Unreal material in which each of the parameters is defined as a linear blend between 2 different source values for that parameter.
We could create such a material blueprint that uses a Lerp (Linear Interpolate) node’s to provide each of the material parameters with a blend of 2 input textures/colors or parameters, connecting the alpha texture to all the Lerp nodes’s Alpha input, and effectively achieve blending of 2 different materials, but it would be a complex blueprint in which it’s very inconvenient to design each of the individual materials participating in the blend:
Annotation 2019-12-25 232734

This complexity can be greatly simplified by collecting each of the participating materials parameters into a Material Attributes data structure.
The Material Attributes data structure contains all the data needed to compile a material, and allows input, output, and processing of this data as a single blueprint data stream (connection).
For example, when the material parameters are grouped as a Material Attributes data structure, they can be blended by connecting them into a single BlendMaterialAttributes node, instead of “Lerping” (blending) between 2 inputs to create each individual material parameter, which produces an unworkable complex material blueprint like the previous example.

> To collect material parameters into a Material Attributes data structure, connect them into a MakeMaterialAttributes node:
annotation-2019-12-26-015532.jpg

> To create a blend between 2 Material Attributes data streams, use the BlendMaterialAttributes node:
* The Alpha parameter determines the weights of the blend (a black and white texture can be connected to it as the blend mask)
Annotation 2019-12-26 015717

> In order for the material output to receive a grouped Material attributes input instead of individual inputs for each parameter, select the material output, and in the Details panel, check the Use Material Attributes option:
matatts

Using the Material Attributes data structure, the blended material’s Blueprint in now much simpler and cleaner, while producing the exact same result as before:
Annotation 2019-12-26 021435

But designing 2 different materials within one material Blueprint is still far from being ideal..
What if we want to use just one of these materials on some surfaces?
What if the individual materials are not as simple as the materials shown here, it would be mush more efficient to be able to have one Blueprint for each of the materials allowing to focus on its development and preview it.
We can achieve this desired workflow by developing each of the materials as a Material Function.
Each of the participating materials is created as a Material Function with a Material Attributes output.

> One of the huge advantages of UE4’s material editing is that it allows us to preview a full material while developing it as a Material Function.
* This may sound trivial, but it isn’t. the Material Function isn’t compiled by itself as a material, it just produces data needed to define a material. in many other media production systems, this would have meant that you can develop data within the function but only preview it in the main material where the function is used.

> Learn how to create Material Functions

The Material Function defining the mud material:
Annotation 2019-12-26 024834.jpg

The Material Function defining the mud-leaves material:
Annotation 2019-12-26 024906.jpg

The Blend material using the Material Function nodes:
Annotation 2019-12-26 025111

Note:
When blending a non-metallic material with a metal material, the alpha values (mask colors) should be only 0 or 1 (black or white), otherwise blend areas that have a mid-range metallic value will make no sense visually.
> A RemapValueRange node can be used to force a color threshold on the mask texture or value.

Related:
Material Functions
Material Instances
Texture Painting

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 – RemapValueRange Node

Software:
Unreal Engine 4.24

Having to remap a value range is very common in designing shaders, whether it’s to perform a traditional “levels” operation on a texture, or use just a specific range of values in a float input.
The RemapValueRange node let’s us do just that. this node has 5 inputs:

  1. Input: The input value
  2. Input Low: Input mapping range minimum
  3. Input High: Input mapping range maximum
  4. Target Low: Output range minimum
  5. Target Height: Output range maximum

Mono Noise examples:

  1. The original noise pattern:0
  2. Mapping input 0 -> 1 to output 0 -> 1 obviously has no effect:1
  3. Mapping input 0 -> 1 to output 0.3 -> 0.7 reduces the pattern contrast:2
  4. Mapping input 0.3 -> 0.7 to output 0 -> 1 increases the pattern contrast:3
  5. Mapping input 0 -> 1 to output 1 -> 0 inverts the pattern:4

In this example RemapValueRange nodes are applied to a texture’s individual color channels to increase contrast (Levels):
> Note that this operation can be performed using a simpler graph by using float3d adding and multiplication operations on the texture color (this will be a subject for a different post)
> Note that a different remapping operation can be performed on each color channel of a texture to adjust its color balance.

Before the value remapping:5

After the value remapping tha value in each channel 0.1 -> 0.9 to 0.0 to 1.0:6

The same operation performed by multiplication by 1.2 and subtracting 0.1:7.jpg

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 – Python – Placing level actors bottom at Z 0.0

Software:
Unreal Engine 4.22

This simple Unreal Editor Python example sets the Z axis location of all actors with names beginning with ‘Sphere_’ in a way that their bottom (minimum Z bound) is at height 0.0.

Download the script

> learn how to run Python scripts in the UE4 Editor

import unreal
from unreal import Vector

lst_actors = unreal.EditorLevelLibrary.get_all_level_actors()
print('place actors at 0 z')
for act in lst_actors:
    act_label = act.get_actor_label()
    if 'Sphere_' in act_label:
        print('placing: {}'.format(act_label))
        act_location = act.get_actor_location()
        act_bounds = act.get_actor_bounds(False)
        act_min_z = act_bounds[0].z - act_bounds[1].z
        location_offset = Vector(act_location.x, act_location.y, act_location.z - act_min_z)
        act.set_actor_location(location_offset, False, False)

* note that when copying and pasting a script from this example, the indentation may not be pasted correctly.

Note:
The get_actor_bounds unreal.Actor class method returns a tuple object containing 2 unreal.Vector objects, the first being world space location of the actor geometric center, and the second is the corner of the bounding box relative to the center.

‘Sphere_*’ actors before running the script:

Annotation 2019-12-08 225356.jpg

‘Sphere_*’ actors after running the script:

Annotation 2019-12-08 225503.jpg

 

Related:
Get started with Python for Unreal Editor
UE4 – Python – Importing assets

UE4 – Package a Project for Windows

Software:
Unreal Engine 4.25

Basic steps for packaging a simple UE4 project for Windows:

Package settings:
Open the Project Settings window:
Untitled-1.jpg

  1. In: Project > Description
    Set the project’s details and thumbnail:
    > The Project thumbnail will apear in the UE4 Editor browser.
    > Thumbnail image must be a 192 x 192 resolution PNG
    Untitled-4
  2. In: Project > Maps & Modes
    Set default level (Map) for the project:
    Untitled-5
  3. In: Project > Packaging
    Choose build configuration
    > For final distribution choose ‘Shipping‘:
    Untitled-6
  4. In: Project > Supported Platforms:
    Make sure Windows is selected:
    Untitled-7.jpg

Setting user input focus:
* So the user doesn’t have to mouse click the screen before being able to control the game.
Select the FirstPersonCharacter Actor and enter editing mode.
In the Event Graph Blueprint, locate the Event BeginPlay node, add a Set Input Game Only node, after it, and connect a Get Player Controller node set to index 0, to it’s Player Controller input:
Annotation 2020-07-14 175909
Note that if there are UI user interactions, in the game, you may need to switch to different input modes during the game to allow interaction with UI.

Adding a Quit command:
Select the FirstPersonCharacter Actor and enter editing mode.
In the Event Graph Blueprint, add an Escape key press Event node,
And connect it to a Quit Game command node.

Untitled-9.jpg

 

Creating the game package:
Choose:
File > Package Project > Windows > Windows (64-bit)
And select an output folder.

Untitled-8.jpg

A folder named “WindowsNoEditor” will be created,
And inside it will be the game executable along with code and assets folders.
This package can be renamed and copied to other locations.

 

Possible causes for packaging failure:
There are many reasons packaging a UE project can fail,
I certainly don’t know all of them, but I’ll list some cases I actually encountered:

  1. If the project folder is located within a deep folder structure, packaging errors may occur because of long file paths.
    * Sorry I didn’t save the actual error message..
  2. Installing a plugin twice by mistake will cause the following error:
    Error: System.ArgumentException: An item with the same key has already been added.
    * I mistakenly installed the Houdini engine plugin both in the Plugins\Runtime folder and in the Plugins folder (this specific plugin should be only in Plugins\Runtime).

 

Related posts:

  1. UE4 – 3ds max & V-Ray Datasmith workflow
  2. Cleanup the FPS project template for ArchvisÂ