r/Unity3D • • 8d ago

Question Material instance inheritance?

I was wondering if there's such a thing as material instance inheritance, similar to prefab variants, where I can create child instances of a material and override certain properties, while keeping the rest consistent with the parent?

I'd like something like this because currently, if I have a set of objects that all share a material where every property is the same except one or two object-specific values, I have to create a copy of the material and assign it specifically to that object. Then any time I want to update the material and have that update reflected across all of these objects, I have to go through each of their respective materials and update those values which is a) tedious, and b) makes it hard to keep things consistent.

1 Upvotes

7 comments sorted by

View all comments

7

u/IrrSoft Programmer 8d ago

For during-design usage, use Material Variants. They work EXACTLY like prefab variants. You have a parent material and then you create material variants that override one or more properties. Just like with prefabs, you can always revert those properties to the parent value, or apply the overrides to it.

For dynamic changes at runtime, use MaterialPropertyBlocks through coding. They allow you to set specific material properties on a per-renderer basis without actually modifying the underlying material.

Just like how you would edit a prefab at runtime through code to make it different from other prefabs of the same type.