Is it ok to use a lot of static bool/switch parameters?

Hi,

I have a master material from the marketplace and it literally has over 100 static bool parameters so you can switch various options on/off.

If I make a single material instance of it, I assume it will just create one material as it ignores all of the static bool / switch chains (code) not used.

If I make a second instance with some different static bools selected I assume that also creates another single material (also just using the relevant code that the bool/switch selects).

So, shouldn’t I have 2 material instances and Unreal would just have to compute 2 materials?

If I had a master material with no static bool parameters and made 2 instances of it - maybe with just different textures), then Unreal would also only have to compute 2 materials.

I’m unsure of the warning on the documentation (below)? It’s suggesting you should limit the use of static bools/switches, but if it only computes what is used, why is this an issue?

Would appreciate if someone could explain!

Thanks!

If you have no static bool parameters and made 2 instances of it with different textures - it is only 1 material - the textures are passed as parameters, not altering the code at all.

Thanks. Ok, so if I had a material with just texture, vector and float parameters, each instance (with different parameter values) is still one material?

But, if I use static bool parameters then it will create unique materials for the various combinations of static bools (if used), hence why Unreal recommends to keep them to a minimum?

I read that if you have 100 materials or 100 material instances it doesn’t matter. But it sounds like what you’re saying if I had 100 materials then Unreal would compute 100 materials, but 100 material instances (if they use the same master material) would just be 1 material? Is that right?

Yes that’s correct. The static bools are handy to create multi-faceted materials - but each time you change those bools Unreal has to create a unique shader for each combination.

Having a lot of shaders in itself isn’t going to take up a lot of memory, they’re only small so in a way it’s not overly bad - it’s the textures themselves that use up the VRAM.

Super helpful, thanks!

I’m thinking I don’t like the master material with over 100 bool parameters though as that creates so many combos. Time to build my own master materials I think. :slight_smile:

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.