#showing/hiding a property based off of a boolean?

1 messages · Page 1 of 1 (latest)

rapid mountain
#

hey guys, how can i do this? i did try using a custom property, but it didn't really work.
i am very new to shader graphs and shaders in general, so please bare with me XD

meager apex
rapid mountain
#

aw man i didn't wanna have to do manual scripting for such as simple thing 😭

#

are there any alternatives?

meager apex
#

None that I know of
Besides just to live with all properties visible

#

An editor GUI editor would be nice

rapid mountain
#

yeah :c

#

well thanks, ill check it out

meager apex
rapid mountain
#

that looks like it's for HDRP, im using URP

#

idk if it matters, i just thought i'd point that out

#

oh found it

meager apex
#

Graph Settings have "Custom Editor GUI" field which in the sample points to LitShader.cs that you can find by searching in "all" or "packages"

rapid mountain
#

ye i saw that too

#

i'll share my findings here when i figure it out

#

just for if someone happens to also have this issue

rapid mountain
#

AH i did it

#

so first you make a boolean KEYWORD

#

not just a normal boolean

#

and by default it makes it into a branch kind of thing

#

in the shader gui script, i used this code

using System;
using UnityEditor;
using UnityEngine;

public class VertexColorTextureBlendEditor : ShaderGUI
{
    float doesThisWork = 0f;

    override public void OnGUI(MaterialEditor materialEditor, MaterialProperty[] properties)
    {
        base.OnGUI(materialEditor, properties);

        Material targetMat = materialEditor.target as Material;

        bool useMetallicMap = Array.IndexOf(targetMat.shaderKeywords, "_USEHEAVYMETALMAP_ON") != -1;

        if (useMetallicMap)
            doesThisWork = EditorGUILayout.FloatField("Does This Work?", doesThisWork);
    }
}
#

and yes you gotta do this

#

thank you @meager apex