Custom Primitive Data is a helpful feature within Unreal Engine that allows you to easily modify Scalar and Vector parameters within Materials without the need to setup Material Instances or Dynamic Material Instances during runtime.
This is primarily due to the data being stored on the Primitive Object itself, such as a Static or Skeletal Mesh Component, instead of the material. In addition, this method increases performance by reducing the number of draw calls used for duplicate geometry within your scene.
Setup for primitive component
- Select the desired non-constant Scalar and Vector parameters within a material of your choosing
- In the materials Details Panel, enable the "Use Custom Primitive Data" option and set the "Primitive Index" option to a unique value
-
Apply the material to a Primitive Object that can be assigned a material (e.g., Static or Skeletal Mesh Components)
-
Modify the "Custom Primitive Data" by the Primitive Component Details Panel or via the "Set Custom Primitive Data" functions in C++, Blueprint, or Python
Setup for instance component
- Add "Per Instance Custom Data" and "Per Instance Custom Data 3 Vector" nodes to your material
- In the materials Details Panel, adjust the "Const Default Value" option and set the "Data Index" option to a unique value
-
Apply the material to a Static Mesh object that will be instanced (e.g., Hierarchical Instance Static Mesh, Instanced Static Mesh)
-
Modify the "Custom data" option via the Instance Component Details Panel or via the "Set Custom Data Value" functions in C++, Blueprint, or Python
Important Set the "Num Custom Data Floats" to the number of "Data Index's" used in the applied materials
- The Primitive Index serves as a distinct identifier for a property across ALL materials on a Primitive Object. So, if you assign the same Primitive Index value to Scalar or Vector parameters in multiple materials, they will all share that value.
- A property with "Use Custom Primitive Data" enabled will remain at its default value until it is explicitly set by the Primitive Object.
- Allows for per-instance modification using the "Per Instance Custom Data" material nodes