Dynamic Material - Stellar-Blade-Modding-Team/Stellar-Blade-Modding-Guide GitHub Wiki
[!IMPORTANT] This section was writen by our team member Code Breaker Umbra. It's a slightly advanced topic regarding dynamic materials. Dynamic materials allow you to tweak material parameters at runtime such as vector parameters, scalar parameters and texture parameters.
You should have minimal knowledge of Unreal Engine and Blueprints to have this working.
Appreciate Modder Code Breaker Umbra for providing source document and tips in this section.
Example of workflow with setting up dynamic materials :
https://github.com/user-attachments/assets/00af6453-a463-45fa-b616-684ede2b4e06
Setup
To improve the setup, we will be setting up a custom structure that can be easily added as a variable on your blueprints.
Blueprint structures
Create a folder anywhere on your project, for example /Content/Data
and create a blueprint structure and name it however you like.
Here I named mine FBP_DynamicMaterials
Add the fallowing variables to your structure:
-
TextureParams: of type
Texture Paramter Value
and set it to anArray
type -
ScalarParams: of type
Scalar Paramter Value
and set it to anArray
type -
VectorParams: of type
Vector Paramter Value
and set it to anArray
type -
BaseMaterial: of type
Material Interface
and set it to aSoft Object Reference
type
You should have something like this at the end:
Blueprint setup
The next step is to find a way to execute code on your skeletal mesh, for example using a custom post process anim bp.
-
With your blueprint open, create a new variable of tyep
Map
which mapsInteger
→FBP_DynamicMaterials
-
-
Make it a Map
-
After you compile your blueprint your variable should look like this
Setting up the dynamic materials
The next step is to map the textures that your mesh is using by their index.
Let's use eve's outfit 9 (default diving suit) as reference.
Here we have 3 materials. For simplicity reasons, let's assume that our mod uses the MI_CH_P_EVE_09_Suit
material, and want to replace the textures of that material. Note that this material is at index 0 (noted by the "element 0" on the left)
The next step is to configure our variable to load the textures dynamically.
Step 1
Add a new entry to the map and set the key to 0 (because this config is for material at index 0)
You should see the result in image above.
Step 2
Fill up the data structure as needed. You can check the different available parameters with FModel.
Here are the available texture parameters for the material MI_CH_P_EVE_09_Suit
Let's say we want to replace the BaseColor
texture and the ORM
texture, our variable would look something like this:
Using the same logic, you can now edit the other parameters available
[!NOTE] Your textures can be placed anywhere on your project, they don't need to replace the game's textures
The BaseMaterial
variable is set to MI_CH_P_EVE_09_Suit
because that's the base material we wish to use at index 0 on our mesh
You can now edit this variable at will and add your own indexes as needed.
[!TIP] You can use the same base materials with different textures! You can also overwrite other material parameters such as the vector params (color) and scalar params using the same logic.
[!TIP] If you want to add more indexes, consider adding them in reverse order, by default a new entry will try to add the key "0" and if that key already exists, an error will pop up and prevent you from adding new keys. So I suggest you add your indexes in reverse order (Descending order)
Blueprint Logic
Below, screenshots of the blueprint setup for dynamic materials.
For this example, we will use a custom post process anim blueprint as this blueprint gives us direct access to the target mesh we want to load dynamic materials on.
You can copy this graph from this website for easy copy/paste into your blueprint graph.
[!WARNING] If you copy the code from the website above, your engine may crash or give errors when you paste on your graph if the structure you created doesn't have the same name as mine, which is
FBP_DynamicMaterials
. If this is the case, simply replace the broken nodes with your own and recompile your BP
[!NOTE] The game seems to reset the materials on every frame on the pause menu, and the materials are reset on a delay when spawning, so I recommend using the Update function