Re-using materials: .mi
Material Instances and external materials
Summary
Published: ??? by manavortex Last documented update: May 01 2024 by manavortex
This guide will teach you how .mi files work
As of May 2024, you can also use ArchiveXL: dynamic materials, which is a more flexible implementation of the same basegame mechanic. However, you may want to understand this, because CDPR are using it a lot.
What is a material instance?
A .mi file encapsulates a material in a reusable template file, which you can use a .mi file as base material
in a material definition.
It is possible to use multiple .mi files in a row. For an example of this, check the player's skin materials.
For more information of this, you can look at Shaders -> The Daisy Chain
Why do I need this?
Put yourself in the shoes of a hypothetical modder.
You are creating a mod that offers multiple versions of the same item (e.g. toy props or hair)
You have created a base material
You duplicate and re-duplicate the material for each of your variants, changing the properties that defines the colour
You wish that there was less copy-pasting involved
![](https://wiki.redmodding.org/~gitbook/image?url=https%3A%2F%2F1427525421-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252F4gzcGtLrr90pVjAWVdTc%252Fuploads%252FP5qyK7p0OsZpcQ6cFHPc%252Fmi_files_materials_the_problem.png%3Falt%3Dmedia%26token%3D0410ae25-09ba-4de4-aa45-53ed8f980911&width=768&dpr=4&quality=100&sign=b51730e8&sv=1)
.mi files to the rescue
Take any of them from the game, move them to your custom directory, and group all the properties that you keep copy-pasting into the .mi.
Then, in your material, you can now use your .mi file as baseMaterial
, and only change the properties that are actually different!
For a collection of example .mi files, check manavortex's MEGA.
Instead of copy-pasting six properties, you now copy-paste only two.
![](https://wiki.redmodding.org/~gitbook/image?url=https%3A%2F%2F1427525421-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252F4gzcGtLrr90pVjAWVdTc%252Fuploads%252FNq5ZV8EdTycENPnkMlEq%252Fmi_files_the_solution.png%3Falt%3Dmedia%26token%3Dcc31b677-3d97-44bc-a19e-f7e56de3e31f&width=768&dpr=4&quality=100&sign=813fa41d&sv=1)
Making material templates
Let's take it another step further – we can make a bunch of different colours to re-use across your files. An example for this are hair files, or the plastic materials I've used in my toy prop pack.
![](https://wiki.redmodding.org/~gitbook/image?url=https%3A%2F%2Fstaticdelivery.nexusmods.com%2Fmods%2F3333%2Fimages%2F7391%2F7391-1676065515-1014778223.png&width=768&dpr=4&quality=100&sign=42b8beeb&sv=1)
For this, I first created a plastic_base.mi
with all the common properties, and then created one additional .mi file for each shade of plastic, setting plastic_base.mi as baseMaterial, leaving me with the following folder structure:
If I decide that my plastic is too shiny, I can edit _plastic_base.mi
instead of touching every template individually. Pretty neat, isn't it?
And if one of my items happens to have a custom normal map and/or texture, then I just add them in the values
array of my material and call it a day.
Maximally lazy: external materials
But we can take this approach even further! If you don't have any properties, your mesh doesn't even need materials! You can simply use the externalMaterials
list instead. You do this by unticking the isLocal property in the materialEntries definition:
![](https://wiki.redmodding.org/~gitbook/image?url=https%3A%2F%2F1427525421-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252F4gzcGtLrr90pVjAWVdTc%252Fuploads%252Fgit-blob-499010268c2e0c6405cf309b14c64de0e914b9ac%252Fre-using_materials.jpg%3Falt%3Dmedia&width=768&dpr=4&quality=100&sign=969d00a4&sv=1)
Warning
You can of course mix and match local and external materials! Just make sure that the materialEntries indices are pointing at the correct material.
However:
If you are using preloadLocalMaterials
, you need to use preloadExternalMaterials
instead of externalMaterials.
Last updated