Notifications
Clear all

[Closed] Instance Materials via script?

I want to create instances of textures maps from one material slot to another. I’m using custom game shaders (I can query and set maps and values, no isse), and I’d like to set the diffuse/specular/normal maps of these to be instances of my standard material. Currently they are just copies – I loop through all my standard materials and copy the filenames into the relevent slots of my custom material.

After making sure it can be done manually in the material editor, I’ve come undone at the script stage. When I drag and drop the textures I’m given the option of creating a copy or creating an instance.

3 Replies

instancing a map is easy, you just point straight to the map you want to instance. For example:


-- instance a map
standardMaterialB.diffuseMap = standardMaterialA.diffuseMap

-- copy a map
 standardMaterialB.diffuseMap = copy standardMaterialA.diffuseMap
 

The ‘difficult’ part is getting the “standardMaterialX.diffuseMap” bits, but the macro recorder should have those for you

Ah! It’s so simple really! I’ve been doing it the hard way, storing filenames and paths…

Thanks so much, I’ll give that a whirl, and possible update some other scripts too.

That worked a treat. I’ll have to write some functions, and make it work with our game shaders, but it’s working:

– Instance Textures

– Test variables, use in loop later
matidfrom = 2
matidto = 4

subid = 2 – upper garment

– TO slot = FROM slot
meditMaterials[matidto].materialList[subid].diffuseMap = meditMaterials[matidfrom].materialList[subid].diffuseMap

Changing the upper garment diffuse texture in material 2 or 4 changes it in the other one too.