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.

68747470733a2f2f692e696d6775722e636f6d2f3644714b3178792e706e67

68747470733a2f2f692e696d6775722e636f6d2f5a4544486e36332e706e67

Here I named mine FBP_DynamicMaterials

Add the fallowing variables to your structure:

  • TextureParams: of type Texture Paramter Value and set it to an Array type

  • ScalarParams: of type Scalar Paramter Value and set it to an Array type

  • VectorParams: of type Vector Paramter Value and set it to an Array type

  • BaseMaterial: of type Material Interface and set it to a Soft Object Reference type

You should have something like this at the end:

68747470733a2f2f692e696d6775722e636f6d2f594d50495074382e706e67

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 maps IntegerFBP_DynamicMaterials

  • 68747470733a2f2f692e696d6775722e636f6d2f4b6962566a51382e706e67

  • Make it a Map

  • 68747470733a2f2f692e696d6775722e636f6d2f34666d514643682e706e67

After you compile your blueprint your variable should look like this

68747470733a2f2f692e696d6775722e636f6d2f323677774d636f2e706e67

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.

68747470733a2f2f692e696d6775722e636f6d2f6a6776435563492e706e67

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) 68747470733a2f2f692e696d6775722e636f6d2f483036306c4b422e706e67

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.

68747470733a2f2f692e696d6775722e636f6d2f4f4e6c394e67612e706e67

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:

68747470733a2f2f692e696d6775722e636f6d2f657661706863682e706e67

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. 68747470733a2f2f692e696d6775722e636f6d2f764f5a374f764a2e706e67

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

Example result

68747470733a2f2f692e696d6775722e636f6d2f55466b435745512e706e67