Best workflow to replace a PBR material with a node material at runtime?

Hi All

So I need to do as the title says. My scene uses 3 shading types , unlit , lit and node material

Obviously with glb , we can only set up the materials as lit or unlit. So I have some external data that tells my application which materials actually need to be a node material.

workflow is , assets are loaded , scene materials looped and using the material name , look in the external data if this material actually needs to be a node material.

I have this all working and the node materials themselves working but its creating and swopping out materials in the scene at runtime that is causing me headaches.

Firstly the new node material needs the same name as the material it is replacing. This is for the entire applications material update system to stay working… it targets materials by name.

I have tested just creating it with the same name , and trying to assign it to the same index in the scene materials array.

This doesnt really work , because when you create the node material , it gets inserted into the array already. Now you have duplicates.

Also , any mesh using the material ( the old one ) gets disconnected ( active material becomes None )

Does anyone know what the best workflow is for this. Ideally…

  1. It would be great if creating a material doesnt auto inject itself ( because im trying to replace a material obviously )

  2. It would be great if you could just assign the material value to an existing index in scene materials and all mesh objects using the material dont loose their connection to it.

any ideas?

Just my two cents here, but if your system targets material by name, may be you could make your switch using the material id (so it wouldn’t conflict)?

Thanks bud , im working on a solution now using the existing system … I was in a rush this afternoon because I had to go to band rehersal and play and event :wink:

Now that im home and not rushing I can see a way to do it. will report back

1 Like