How to change Shadergraph file assets from code

Is there a way to modify shadergraph from code? I want to do some changes to multiple shadergraphs and it would be much simpler if I write an editor function to do it.

Shader Graph is an Editor-only tool and data format that let’s you generate an actual HLSL shader code.

If you are looking for a way to inject your own hlsl code into a Shader Graph you may want to use Custom Function Node

https://docs.unity3d.com/Packages/com.unity.shadergraph@17.0/manual/Custom-Function-Node.html

But if you want to modify a *.shadergraph file from a C# editor tool then this file is a simple YAML text file and and easy to modify after you figure out the syntax.

To modify multiple *.shadergraph files use a Sub Graph

https://docs.unity3d.com/Packages/com.unity.shadergraph@17.0/manual/Sub-graph.html

thanks andrew-lukasik, it’s more I want to change between options like lit and unlit

You can’t change declared shader type i.e. LitUnlit.

But you can easily fake it. That is shader can still receive lighting data but but output flat color. Keywords is a feature that allows to switch between different shader variants like this.

https://docs.unity3d.com/Packages/com.unity.shadergraph@17.0/manual/Keywords.html

I don’t mean at runtime, I mean an editor function to setup/change shadergraphs on mass

I already answered this here: