These are definitions to describe the motion of objects. Both are unique. In mathematics, scalars are defined as quantities that are described as a single numerical value, whereas vectors are defined as quantities that are described as a numerical value and direction. The examples of scalar quantities include length, area, volume, speed, mass, temperature, and power, whereas the examples of vector quantities include direction, velocity, force, acceleration, and displacement.
In Unreal Engine 4, the use of scalar and vector values is very common, especially in blueprints and materials. In the context of the material editor, scalar values are simply numerical values, whereas vectors are actually the colors of RGBA or red, green, blue, and alpha. In the Material editor, we can use both scalar and vector parameters to influence the color and intensity of the material itself.
In the preceding screenshot, we are using a vector parameter node in our material to dictate the color of the material itself. By default, the vector parameter in the material editor contains the values for red, green, blue, and alpha; the alpha value controls the opacity of the color. In the material example, the scalar parameter controls the strength of the emissive value of the material. By increasing or decreasing this value, the material's brightness will get brighter or dimmer. To recreate this, we can right-click on our Content Browser, select Material and name this MAT_Example
, and double-click on the material to open the Material editor. Perform the following steps:
1.0
, 0.5
, 2.0
, and 1.0
respectively. We can name this parameter as Material Color
.5
and name this parameter as Material Color Intensity
.In the Blueprints of Unreal Engine 4, the scalar and vector parameters serve similar purposes (as seen in the material editor). The vector variable in blueprint scripting holds the values for X, Y, and Z values and is used to dictate the location and direction, whereas the rotator variables holds the Roll, Pitch, and Yaw rotation values. When it comes to scalar variables in blueprints, there are many options to use (such as integers or floats) because scalar values are only numerical values with no direction associated to them.
As shown in the preceding image, we can split the structure pin for the rotator and vector variables by right-clicking on the vector values and selecting Split Struct Pin. So, we can edit each direction individually using float scalars to affect each. At the same time, instead of using individual scalar values by right-clicking on one of the split float values and selecting the Recombine Struct Pin option, we can also recombine the structure pin for these variables so that we can edit these values with vectors or rotators respectively.
Another interesting use of materials and blueprints is that you can dynamically change the value of the scalar and vector parameters in the event graph or the construction script of the blueprint.
As shown in the preceding image, we can create a dynamic material instance from a static mesh in our blueprint that uses the material example we made earlier, which uses the vector and scalar parameters. Here, we can set the Material Color vector parameter, split the color structure into four unique float values of RGBA (red, green, blue, and alpha) and then use the random float in the range node to create random colors for the material.
To recreate this, we first need to create a new blueprint by right-clicking on our content browser and selecting the Blueprint class and then Actor to create an actor-based blueprint. Next, double-click on this new blueprint to open the Blueprint editor. Perform the following steps:
ROOT
.StarterContent
folder in Shapes, select the Shape_Plane Static mesh so that it is highlighted in the content browser.Material Color
.Make Linear Color
. For the RGB values, we can use Random Float in range nodes that have a minimum value of 0.5, a maximum value of 1.0, and a constant alpha value of 1 to randomize the color.18.222.83.185