- Home /
Shader property per object
Hi . I write a simple shader and it's have some property; I want to create one material and each object has been different property (for example when you create a sprite material , each object has different texture)
at first I just use [PerRenderData] but it doesn't work (when I change an object's material property , it's effected on other objects with same material )
Answer by _dns_ · Aug 01, 2018 at 02:06 PM
Hi, MaterialPropertyBlock can solve this problem (https://docs.unity3d.com/ScriptReference/MaterialPropertyBlock.html) It can hold properties values and be passed to a Renderer.
it's good but I wan't change and preview properties in edit mode
There might be other way to do it but here is what I did for a similar problem: On the objects that need different shader properties, I use the ExecuteInEdit$$anonymous$$ode attribute a the component that manages those shader properties. Doing so, OnEnable (and Update) are called in the Editor too. Creating and assigning a $$anonymous$$aterialPropertyBloc during those callbacks in the Editor works well. You just have to be careful to separate your Editor and player/runtime code, using #if UNITY_EDITOR and Application.IsPlaying.