Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question An issue about custom editor in shadergraph.

Discussion in 'Shader Graph' started by PuzzledBoy, Oct 24, 2019.

  1. PuzzledBoy

    PuzzledBoy

    Joined:
    Sep 9, 2014
    Posts:
    23
    I'm making a rendering work flow base on ShaderGraph.

    Due to unsupported custom editor in shader graph,the material inspector become unfriendly while writing complex shader with lot of exposed properties.And,I can't see anyone talk about it.

    Shader Graph was designed for zero coding.I think create a custom editor C# script and indicate the script's location in source code ("CustomEditor "XXX.cs") is breaking the rule.

    Well,so I am building a simple feature that you can add a "Drawer" Property with it's display name will be insert into the source code:
    upload_2019-10-24_13-54-59.png

    It's almost done except an issue:
    When you click 'Save Asset' and only the drawer attribute was added or removed,then the material inspector will not refresh,unless restart the unity project(refresh and reimport was useless).

    There are simple steps to reproduce it with unmodify package:
    1.Create a shdaer graph,assign it to a new material.
    2.Add a property "Boolean" and save,of course you will see a bool appear on the material inspector .
    3.Open the source code "BooleanShaderProperty.cs",nagivate to function "GetPropertyBlockString()",and remove the string "[ToggleUI]".
    4.Back to Unity,save the shader graph,the inspector keep toggle but not a float field,if you add a new boolean property it will show as float which is correct.
    upload_2019-10-24_14-39-37.png
    5.restart unity then both show correctly.
    upload_2019-10-24_14-41-28.png

    The way unity handle inspector update is a black box,I don't know how to solve it.
     
    ph_ likes this.
  2. PuzzledBoy

    PuzzledBoy

    Joined:
    Sep 9, 2014
    Posts:
    23
    After some digging the 2018.4.9f1 CS source, I find a code line has highly possibility was the reason :

    upload_2019-10-31_16-28-7.png

    Return variable 'attribs' may don't get update when a shader graph property'attribute changed,but this function 'GetShaderPropertyAttributes' finally call the C++ side code,which I can't get more informations.

    I guess the function has different implement for shader and shader graph,and the reason was inside.
     
  3. whoisj

    whoisj

    Joined:
    Jan 4, 2018
    Posts:
    26
    The fact that this worked in anyway is terrifying. Better to do it right and submit a patch directly to Unity to get the effects that you want.

    https://github.com/Unity-Technologies
     
    ph_ likes this.
  4. ph_

    ph_

    Joined:
    Sep 5, 2013
    Posts:
    232
    Custom editors (the same one you use with traditional shaders) is also one of the feature of ShaderGraph Essentials. You fill in information directly in the master node as: MyNamespace.MyCustomEditorScript; and it adds the correct code to the generated shader.

     
    whoisj likes this.