Search Unity

Toggle doesn't work when using a CustomEditor

Discussion in 'Shaders' started by GeriB, May 20, 2019.

  1. GeriB

    GeriB

    Joined:
    Apr 26, 2017
    Posts:
    11
    I'm writting a shader that uses a custom MaterialEditor and therefore includes a CustomEditor sentence at the end of the shader.

    When I use the CustomEditor all my Toggles won't work. But when I use the default Editor the Toggles work again.

    Is this the desired behaviour? Am I missing something?

    I used the following method for adding the Toggles: https://gist.github.com/keijiro/22cba09c369e27734011
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    7,128
    Define "won't work". Do you mean they don't show as toggles, or they don't cause the material to use the keyword? And how are you showing those properties using your custom editor? If you're doing something other than "materialEditor.ShaderProperty()" then it means it's up to you to set the keywords.
     
  3. GeriB

    GeriB

    Joined:
    Apr 26, 2017
    Posts:
    11
    I mean that although the Toggle checkbox appears on my CustomEditor when I click on the checkbox and change it's state it has no effect on the shader.

    When trying to set the shader_feature with the Toggle in my CustomEditor the code never gets into the #ifdef part.

    The CustomEditor at the end displays the Toggle like this: ShaderProperty(properties[propertyIndex], properties[propertyIndex].displayName);


    To sum it up what happens is that with the CustomEditor line commented the Toggle appears on the default material editor and works as intended within the shader (gets into the #ifdef when it should).
    And when using the CustomEditor the Toggle also appears where it should but changing it's state doesn't do anything, the #ifdef will always fail regardless of the Toggle state.