Search Unity

MaterialEditor.OnShaderChanged() not working correctly!

Discussion in 'Shaders' started by Isfaq, Jul 23, 2018.

  1. Isfaq

    Isfaq

    Joined:
    Feb 2, 2017
    Posts:
    161
    My custom shader uses a custom inspector which derives from MaterialEditor. when I create a new material and change the shader from standard to my shader, the custom material inspector doesn't draw, the default inspector draws instead. However, If I then deselect and reselect the material, it works.
    I assumed I have to repaint the editor on overriding the OnShaderChanged() and I did (added a debug log too). I noticed OnShaderChanged gets called after deselecting and reselecting the material, not after switching the shader. OnEnable, Awake, OnInspectorGUI, these are also gets called after reselecting the material.
    Is there any fix or workaround to it? Or am I missing something?